зеркало из 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!!)
|
# if it will be faster, or if the git binary is not available (!!TODO!!)
|
||||||
module GitRuby
|
module GitRuby
|
||||||
|
|
||||||
attr_accessor :ruby_git_repo
|
attr_accessor :ruby_git_repo, :git_file_index
|
||||||
|
|
||||||
def cat_file(options, ref)
|
def cat_file(options, ref)
|
||||||
if options[:t]
|
if options[:t]
|
||||||
|
@ -34,8 +34,15 @@ module Grit
|
||||||
def rev_list(options, ref = 'master')
|
def rev_list(options, ref = 'master')
|
||||||
options.delete(:skip) if options[:skip].to_i == 0
|
options.delete(:skip) if options[:skip].to_i == 0
|
||||||
allowed_options = [:max_count, :since, :until, :pretty] # this is all I can do right now
|
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)
|
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
|
else
|
||||||
return ruby_git.rev_list(rev_parse({}, ref), options)
|
return ruby_git.rev_list(rev_parse({}, ref), options)
|
||||||
end
|
end
|
||||||
|
@ -76,16 +83,18 @@ module Grit
|
||||||
end
|
end
|
||||||
|
|
||||||
def blame_tree(commit, path = nil)
|
def blame_tree(commit, path = nil)
|
||||||
begin # try index file, sooooo much faster
|
begin
|
||||||
index = FileIndex.new(@git_dir)
|
commits = file_index.last_commits(rev_parse({}, commit), looking_for(commit, path))
|
||||||
commits = index.last_commits(commit, looking_for(commit, path))
|
clean_paths(commits)
|
||||||
clean_paths(commits, path)
|
rescue FileIndex::IndexFileNotFound
|
||||||
rescue
|
{}
|
||||||
temp = Repository.new(@git_dir, :map_packfile => true)
|
|
||||||
temp.blame_tree(rev_parse({}, commit), path)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_index
|
||||||
|
@git_file_index ||= FileIndex.new(@git_dir)
|
||||||
|
end
|
||||||
|
|
||||||
def ruby_git
|
def ruby_git
|
||||||
@ruby_git_repo ||= Repository.new(@git_dir)
|
@ruby_git_repo ||= Repository.new(@git_dir)
|
||||||
end
|
end
|
||||||
|
@ -102,19 +111,17 @@ module Grit
|
||||||
else
|
else
|
||||||
file = e.name
|
file = e.name
|
||||||
end
|
end
|
||||||
|
file += '/' if e.type == :directory
|
||||||
looking_for << file
|
looking_for << file
|
||||||
end
|
end
|
||||||
looking_for
|
looking_for
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_paths(commit_array, path)
|
def clean_paths(commit_array)
|
||||||
return commit_array if !path || (path == '' || path == '.' || path == './')
|
|
||||||
|
|
||||||
new_commits = {}
|
new_commits = {}
|
||||||
path_match = Regexp.new(path + '/')
|
|
||||||
commit_array.each do |file, sha|
|
commit_array.each do |file, sha|
|
||||||
amended = file.sub(path_match, '')
|
file = file.chop if file[file.size - 1 , 1] == '/'
|
||||||
new_commits[amended] = sha
|
new_commits[file] = sha
|
||||||
end
|
end
|
||||||
new_commits
|
new_commits
|
||||||
end
|
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(' ')}"
|
call = "#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}"
|
||||||
puts call if Grit.debug
|
puts call if Grit.debug
|
||||||
|
|
||||||
|
puts
|
||||||
|
puts '**'
|
||||||
|
puts call
|
||||||
|
puts '**'
|
||||||
|
puts
|
||||||
|
|
||||||
response = timeout ? sh(call) : wild_sh(call)
|
response = timeout ? sh(call) : wild_sh(call)
|
||||||
puts response if Grit.debug
|
puts response if Grit.debug
|
||||||
response
|
response
|
||||||
|
|
|
@ -94,7 +94,13 @@ module Grit
|
||||||
|
|
||||||
|
|
||||||
def blame_tree(commit, path = nil)
|
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
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
|
|
|
@ -17,14 +17,16 @@ class TestBlameTree < Test::Unit::TestCase
|
||||||
def test_blame_tree_path
|
def test_blame_tree_path
|
||||||
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||||
tree = @git.blame_tree(commit, 'lib')
|
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'
|
assert_equal last_commit_sha, '5a0943123f6872e75a9b1dd0b6519dd42a186fda'
|
||||||
|
last_commit_sha = tree['lib/grit']
|
||||||
|
assert_equal last_commit_sha, '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_blame_tree_multi_path
|
def test_blame_tree_multi_path
|
||||||
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
||||||
tree = @git.blame_tree(commit, 'lib/grit')
|
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'
|
assert_equal last_commit_sha, '22825175e37f22c9418d756ca69b574d75602994'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,14 @@ class TestFileIndex < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_last_commits_pattern
|
def test_last_commits_pattern
|
||||||
arr = @index.last_commits(@commit, /lib\/grit\/[^\/]*$/)
|
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 @commit, arr['lib/grit/commit.rb']
|
||||||
assert_equal nil, arr['lib/grit/actor.rb']
|
assert_equal nil, arr['lib/grit/actor.rb']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_last_commits_array
|
||||||
|
arr = @index.last_commits(@commit, ['lib/grit.rb', 'lib/grit/'])
|
||||||
|
assert_equal @commit, arr['lib/grit/']
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Загрузка…
Ссылка в новой задаче