зеркало из https://github.com/github/grit.git
patched bare rev-list to use FileIndex (for paging commit count)
FileIndex now understands tree changes makes GitHub use almost no git calls, and can up max list over 30
This commit is contained in:
Родитель
2cb492fffe
Коммит
a92a84f8ca
|
@ -8,7 +8,7 @@ module Grit
|
|||
# if it will be faster, or if the git binary is not available (!!TODO!!)
|
||||
module GitRuby
|
||||
|
||||
attr_accessor :ruby_git_repo
|
||||
attr_accessor :ruby_git_repo, :git_file_index
|
||||
|
||||
def cat_file(options, ref)
|
||||
if options[:t]
|
||||
|
@ -34,8 +34,15 @@ module Grit
|
|||
def rev_list(options, ref = 'master')
|
||||
options.delete(:skip) if options[:skip].to_i == 0
|
||||
allowed_options = [:max_count, :since, :until, :pretty] # this is all I can do right now
|
||||
if (options.size == 0) || ((options.keys - allowed_options).size > 0)
|
||||
if ((options.keys - allowed_options).size > 0)
|
||||
return method_missing('rev-list', options, ref)
|
||||
elsif (options.size == 0)
|
||||
# pure rev-list
|
||||
begin
|
||||
return file_index.commits_from(rev_parse({}, ref)).join("\n")
|
||||
rescue
|
||||
return method_missing('rev-list', options, ref)
|
||||
end
|
||||
else
|
||||
return ruby_git.rev_list(rev_parse({}, ref), options)
|
||||
end
|
||||
|
@ -76,16 +83,18 @@ module Grit
|
|||
end
|
||||
|
||||
def blame_tree(commit, path = nil)
|
||||
begin # try index file, sooooo much faster
|
||||
index = FileIndex.new(@git_dir)
|
||||
commits = index.last_commits(commit, looking_for(commit, path))
|
||||
clean_paths(commits, path)
|
||||
rescue
|
||||
temp = Repository.new(@git_dir, :map_packfile => true)
|
||||
temp.blame_tree(rev_parse({}, commit), path)
|
||||
begin
|
||||
commits = file_index.last_commits(rev_parse({}, commit), looking_for(commit, path))
|
||||
clean_paths(commits)
|
||||
rescue FileIndex::IndexFileNotFound
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def file_index
|
||||
@git_file_index ||= FileIndex.new(@git_dir)
|
||||
end
|
||||
|
||||
def ruby_git
|
||||
@ruby_git_repo ||= Repository.new(@git_dir)
|
||||
end
|
||||
|
@ -102,19 +111,17 @@ module Grit
|
|||
else
|
||||
file = e.name
|
||||
end
|
||||
file += '/' if e.type == :directory
|
||||
looking_for << file
|
||||
end
|
||||
looking_for
|
||||
end
|
||||
|
||||
def clean_paths(commit_array, path)
|
||||
return commit_array if !path || (path == '' || path == '.' || path == './')
|
||||
|
||||
def clean_paths(commit_array)
|
||||
new_commits = {}
|
||||
path_match = Regexp.new(path + '/')
|
||||
commit_array.each do |file, sha|
|
||||
amended = file.sub(path_match, '')
|
||||
new_commits[amended] = sha
|
||||
file = file.chop if file[file.size - 1 , 1] == '/'
|
||||
new_commits[file] = sha
|
||||
end
|
||||
new_commits
|
||||
end
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -55,6 +55,12 @@ module Grit
|
|||
call = "#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}"
|
||||
puts call if Grit.debug
|
||||
|
||||
puts
|
||||
puts '**'
|
||||
puts call
|
||||
puts '**'
|
||||
puts
|
||||
|
||||
response = timeout ? sh(call) : wild_sh(call)
|
||||
puts response if Grit.debug
|
||||
response
|
||||
|
|
|
@ -94,7 +94,13 @@ module Grit
|
|||
|
||||
|
||||
def blame_tree(commit, path = nil)
|
||||
self.git.blame_tree(commit, path)
|
||||
commit_array = self.git.blame_tree(commit, path)
|
||||
|
||||
final_array = {}
|
||||
commit_array.each do |file, sha|
|
||||
final_array[file] = commit(sha)
|
||||
end
|
||||
final_array
|
||||
end
|
||||
|
||||
def status
|
||||
|
|
|
@ -17,14 +17,16 @@ class TestBlameTree < Test::Unit::TestCase
|
|||
def test_blame_tree_path
|
||||
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||
tree = @git.blame_tree(commit, 'lib')
|
||||
last_commit_sha = tree['grit.rb']
|
||||
last_commit_sha = tree['lib/grit.rb']
|
||||
assert_equal last_commit_sha, '5a0943123f6872e75a9b1dd0b6519dd42a186fda'
|
||||
last_commit_sha = tree['lib/grit']
|
||||
assert_equal last_commit_sha, '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||
end
|
||||
|
||||
def test_blame_tree_multi_path
|
||||
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||
tree = @git.blame_tree(commit, 'lib/grit')
|
||||
last_commit_sha = tree['diff.rb']
|
||||
last_commit_sha = tree['lib/grit/diff.rb']
|
||||
assert_equal last_commit_sha, '22825175e37f22c9418d756ca69b574d75602994'
|
||||
end
|
||||
|
||||
|
|
|
@ -37,9 +37,14 @@ class TestFileIndex < Test::Unit::TestCase
|
|||
|
||||
def test_last_commits_pattern
|
||||
arr = @index.last_commits(@commit, /lib\/grit\/[^\/]*$/)
|
||||
assert_equal 9, arr.size
|
||||
assert_equal 10, arr.size
|
||||
assert_equal @commit, arr['lib/grit/commit.rb']
|
||||
assert_equal nil, arr['lib/grit/actor.rb']
|
||||
end
|
||||
|
||||
def test_last_commits_array
|
||||
arr = @index.last_commits(@commit, ['lib/grit.rb', 'lib/grit/'])
|
||||
assert_equal @commit, arr['lib/grit/']
|
||||
end
|
||||
|
||||
end
|
Загрузка…
Ссылка в новой задаче