"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bin/github-linguist" between
linguist-7.23.0.tar.gz and linguist-7.24.0.tar.gz

About: Linguist is a library mainly to detect the programming language used in a file (on GitHub.com it is used to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs).

github-linguist  (linguist-7.23.0):github-linguist  (linguist-7.24.0)
skipping to change at line 16 skipping to change at line 16
require 'rugged' require 'rugged'
require 'json' require 'json'
require 'optparse' require 'optparse'
require 'pathname' require 'pathname'
HELP_TEXT = <<~HELP HELP_TEXT = <<~HELP
Linguist v#{Linguist::VERSION} Linguist v#{Linguist::VERSION}
Detect language type and determine language breakdown for a given Git repository . Detect language type and determine language breakdown for a given Git repository .
Usage: linguist <path> Usage: linguist <path>
linguist <path> [--breakdown] [--json] linguist <path> [--rev REV] [--breakdown] [--json]
linguist [--breakdown] [--json] linguist [--rev REV] [--breakdown] [--json]
HELP HELP
def github_linguist(args) def github_linguist(args)
breakdown = false breakdown = false
json_output = false json_output = false
rev = 'HEAD'
path = Dir.pwd path = Dir.pwd
parser = OptionParser.new do |opts| parser = OptionParser.new do |opts|
opts.banner = HELP_TEXT opts.banner = HELP_TEXT
opts.version = Linguist::VERSION opts.version = Linguist::VERSION
opts.on("-b", "--breakdown", "Analyze entire repository and display detailed usage statistics") { breakdown = true } opts.on("-b", "--breakdown", "Analyze entire repository and display detailed usage statistics") { breakdown = true }
opts.on("-j", "--json", "Output results as JSON") { json_output = true } opts.on("-j", "--json", "Output results as JSON") { json_output = true }
opts.on("-r", "--rev REV", String,
"Analyze specific git revision",
"defaults to HEAD, see gitrevisions(1) for alternatives") { |r| rev
= r }
opts.on("-h", "--help", "Display a short usage summary, then exit") do opts.on("-h", "--help", "Display a short usage summary, then exit") do
puts opts puts opts
exit exit
end end
end end
parser.parse!(args) parser.parse!(args)
if !args.empty? if !args.empty?
if File.directory?(args[0]) || File.file?(args[0]) if File.directory?(args[0]) || File.file?(args[0])
path = args[0] path = args[0]
else else
abort HELP_TEXT abort HELP_TEXT
end end
end end
if File.directory?(path) if File.directory?(path)
rugged = Rugged::Repository.new(path) rugged = Rugged::Repository.new(path)
repo = Linguist::Repository.new(rugged, rugged.head.target_id) begin
target_oid = rugged.rev_parse_oid(rev)
rescue
puts "invalid revision '#{rev}' for repo '#{path}'"
exit 1
end
repo = Linguist::Repository.new(rugged, target_oid)
full_results = {} full_results = {}
repo.languages.each do |language, size| repo.languages.each do |language, size|
percentage = ((size / repo.size.to_f) * 100) percentage = ((size / repo.size.to_f) * 100)
percentage = sprintf '%.2f' % percentage percentage = sprintf '%.2f' % percentage
full_results.merge!({"#{language}": { size: size, percentage: percentage } }) full_results.merge!({"#{language}": { size: size, percentage: percentage } })
end end
if !json_output if !json_output
full_results.sort_by { |_, v| v[:size] }.reverse.each do |language, detail s| full_results.sort_by { |_, v| v[:size] }.reverse.each do |language, detail s|
 End of changes. 4 change blocks. 
3 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)