mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge pull request #2654 from github/vmg/git-linguist-fixes
Small fixes for git-linguist
This commit is contained in:
@@ -71,17 +71,20 @@ class GitLinguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_cache(object)
|
def write_cache(object)
|
||||||
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
|
return unless File.directory? @repo_path
|
||||||
|
|
||||||
|
begin
|
||||||
|
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
|
||||||
File.open(tmp_path, "wb") do |f|
|
File.open(tmp_path, "wb") do |f|
|
||||||
marshal = Marshal.dump(object)
|
marshal = Marshal.dump(object)
|
||||||
f.write(Zlib::Deflate.deflate(marshal))
|
f.write(Zlib::Deflate.deflate(marshal))
|
||||||
end
|
end
|
||||||
|
|
||||||
File.rename(tmp_path, cache_file)
|
File.rename(tmp_path, cache_file)
|
||||||
tmp_path = nil
|
rescue => e
|
||||||
ensure
|
(File.unlink(tmp_path) rescue nil)
|
||||||
(File.unlink(tmp_path) rescue nil) if tmp_path
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_cache
|
def load_cache
|
||||||
@@ -96,24 +99,18 @@ end
|
|||||||
def git_linguist(args)
|
def git_linguist(args)
|
||||||
incremental = true
|
incremental = true
|
||||||
commit = nil
|
commit = nil
|
||||||
git_dir = nil
|
|
||||||
|
|
||||||
parser = OptionParser.new do |opts|
|
parser = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: git-linguist [OPTIONS] stats|breakdown|dump-cache|clear|disable"
|
opts.banner = "Usage: git-linguist [OPTIONS] stats|breakdown|dump-cache|clear|disable"
|
||||||
|
|
||||||
opts.on("-f", "--force", "Force a full rescan") { incremental = false }
|
opts.on("-f", "--force", "Force a full rescan") { incremental = false }
|
||||||
opts.on("--git-dir=DIR", "Path to the git repository") { |v| git_dir = v }
|
|
||||||
opts.on("--commit=COMMIT", "Commit to index") { |v| commit = v}
|
opts.on("--commit=COMMIT", "Commit to index") { |v| commit = v}
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.parse!(args)
|
parser.parse!(args)
|
||||||
|
|
||||||
git_dir ||= begin
|
git_dir = `git rev-parse --git-dir`.strip
|
||||||
pwd = Dir.pwd
|
raise "git-linguist must be ran in a Git repository" unless $?.success?
|
||||||
dotgit = File.join(pwd, ".git")
|
|
||||||
File.directory?(dotgit) ? dotgit : pwd
|
|
||||||
end
|
|
||||||
|
|
||||||
wrapper = GitLinguist.new(git_dir, commit, incremental)
|
wrapper = GitLinguist.new(git_dir, commit, incremental)
|
||||||
|
|
||||||
case args.pop
|
case args.pop
|
||||||
|
|||||||
@@ -126,12 +126,13 @@ module Linguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
MAX_TREE_SIZE = 100_000
|
||||||
|
|
||||||
def compute_stats(old_commit_oid, cache = nil)
|
def compute_stats(old_commit_oid, cache = nil)
|
||||||
|
return {} if current_tree.count_recursive(MAX_TREE_SIZE) >= MAX_TREE_SIZE
|
||||||
|
|
||||||
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
|
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
|
||||||
|
|
||||||
read_index
|
read_index
|
||||||
|
|
||||||
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
|
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
|
||||||
|
|
||||||
# Clear file map and fetch full diff if any .gitattributes files are changed
|
# Clear file map and fetch full diff if any .gitattributes files are changed
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Linguist
|
module Linguist
|
||||||
VERSION = "4.6.2"
|
VERSION = "4.6.3"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user