Added Repo#commit_deltas_from as a (fairly expensive and lazy) way of getting

the commits that differ between two different repositories
This commit is contained in:
Johan Sørensen 2009-02-13 12:03:38 +01:00
Родитель ed76397875
Коммит 2adfc81694
5 изменённых файлов: 60 добавлений и 0 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -1 +1,2 @@
pkg
.DS_Store

Просмотреть файл

@ -209,6 +209,20 @@ module Grit
Commit.find_all(self, id, options).first
end
# Returns a list of commits that is in +other_repo+ but not in self
#
# Returns Grit::Commit[]
def commit_deltas_from(other_repo, ref = "master", other_ref = "master")
# TODO: we should be able to figure out the branch point, rather than
# rev-list'ing the whole thing
repo_refs = self.git.rev_list({}, ref).strip.split("\n")
other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n")
(other_repo_refs - repo_refs).map do |ref|
Commit.find_all(other_repo, ref, {:max_count => 1}).first
end
end
# The Tree object for the given treeish reference
# +treeish+ is the reference (default 'master')
# +paths+ is an optional Array of directory paths to restrict the tree (deafult [])

8
test/fixtures/rev_list_delta_a поставляемый Normal file
Просмотреть файл

@ -0,0 +1,8 @@
e34590b7a2d186b3bb9a1170d02d52b36c791c78
8977833d74f8681aa0d9a5e84b0dd3d81519774d
6f5561530cb3a94e4c86454e84732197325be172
ee419e04a961543444be6db66aef52e6e37936d6
d845de9d438e1a249a0c2fcb778e8ea3b7e06cef
0bba4a6c10060405a94d52533af2f9bdacd4f29c
77711c0722964ead965e0ba2ee9ed4a03cb3d292
501d23cac6dd911511f15d091ee031a15b90ebde

11
test/fixtures/rev_list_delta_b поставляемый Normal file
Просмотреть файл

@ -0,0 +1,11 @@
4c8124ffcf4039d292442eeccabdeca5af5c5017
634396b2f541a9f2d58b00be1a07f0c358b999b3
ab25fd8483882c3bda8a458ad2965d2248654335
e34590b7a2d186b3bb9a1170d02d52b36c791c78
8977833d74f8681aa0d9a5e84b0dd3d81519774d
6f5561530cb3a94e4c86454e84732197325be172
ee419e04a961543444be6db66aef52e6e37936d6
d845de9d438e1a249a0c2fcb778e8ea3b7e06cef
0bba4a6c10060405a94d52533af2f9bdacd4f29c
77711c0722964ead965e0ba2ee9ed4a03cb3d292
501d23cac6dd911511f15d091ee031a15b90ebde

Просмотреть файл

@ -318,4 +318,30 @@ class TestRepo < Test::Unit::TestCase
Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
@r.log('master', 'file.rb', :max_count => 1)
end
# commit_deltas_from
def test_commit_deltas_from_nothing_new
other_repo = Repo.new(GRIT_REPO)
@r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
delta_commits = @r.commit_deltas_from(other_repo)
assert_equal 0, delta_commits.size
end
def test_commit_deltas_from_when_other_has_new
other_repo = Repo.new(GRIT_REPO)
@r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
%w[
4c8124ffcf4039d292442eeccabdeca5af5c5017
634396b2f541a9f2d58b00be1a07f0c358b999b3
ab25fd8483882c3bda8a458ad2965d2248654335
].each do |ref|
Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
end
delta_commits = @r.commit_deltas_from(other_repo)
assert_equal 3, delta_commits.size
end
end