Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 6ee3fef

Browse files
author
Robin Luckey
committed
[CHANGE] No need for separate a separate commit walk() method. Merge it into the existing commit_tokens().
1 parent c8e4b93 commit 6ee3fef

File tree

5 files changed

+71
-153
lines changed

5 files changed

+71
-153
lines changed

lib/scm/adapters/git/commits.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def commit_count(since=nil)
77
end
88

99
# Returns the SHA1 hash for every commit in the repository following the commit with SHA1 'since'.
10-
def commit_tokens(since=nil)
11-
run(rev_list_command(since)).split("\n")
10+
def commit_tokens(since=nil, up_to=branch_name)
11+
run(rev_list_command(since, up_to)).split("\n")
1212
end
1313

1414
# Yields each commit following the commit with SHA1 'since'.
@@ -47,16 +47,9 @@ def log(since=nil)
4747
end
4848
end
4949

50-
51-
def rev_list_command(since=nil)
52-
rev_list_options = "--root --reverse --topo-order"
53-
54-
if since
55-
"cd '#{self.url}' && git rev-list #{rev_list_options} #{since}..HEAD #{self.branch_name}"
56-
else
57-
"cd '#{self.url}' && git rev-list #{rev_list_options} #{self.branch_name}"
58-
end
50+
def rev_list_command(since=nil, up_to=branch_name)
51+
range = since ? "#{since}..#{up_to}" : up_to
52+
"cd '#{url}' && git rev-list --topo-order --reverse #{range}"
5953
end
60-
6154
end
6255
end

lib/scm/adapters/git/head.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,5 @@ def parent_tokens(commit)
1717
def parents(commit)
1818
parent_tokens(commit).collect { |token| verbose_commit(token) }
1919
end
20-
21-
# This method returns the list of commits you must fetch if you are
22-
# current as of old_head, and wish to be current up to new_head.
23-
def walk(old_head=nil, new_head=head_token)
24-
if old_head
25-
run("cd #{url} && git rev-list --reverse #{old_head.to_s}..#{new_head.to_s}").split("\n")
26-
else
27-
run("cd #{url} && git rev-list --reverse #{new_head.to_s}").split("\n")
28-
end
29-
end
3020
end
3121
end

test/unit/commit_walk_test.rb

Lines changed: 0 additions & 65 deletions
This file was deleted.

test/unit/git_rev_list_test.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require File.dirname(__FILE__) + '/../test_helper'
2+
3+
module Scm::Adapters
4+
# Repository graph.git has the following structure:
5+
#
6+
# G -> H -> I -> J -> development
7+
# / \ \
8+
# A -> B -> C -> D -> master
9+
#
10+
class GitRevListTest < Scm::Test
11+
12+
def test_rev_list
13+
with_git_repository('git_walk') do |git|
14+
# Full history to a commit
15+
assert_equal [:A], rev_list_helper(git, nil, :A)
16+
assert_equal [:A, :B], rev_list_helper(git, nil, :B)
17+
assert_equal [:A, :B, :G, :H, :C], rev_list_helper(git, nil, :C)
18+
assert_equal [:A, :B, :G, :H, :C, :I, :D], rev_list_helper(git, nil, :D)
19+
assert_equal [:A, :G], rev_list_helper(git, nil, :G)
20+
assert_equal [:A, :G, :H], rev_list_helper(git, nil, :H)
21+
assert_equal [:A, :G, :H, :I], rev_list_helper(git, nil, :I)
22+
assert_equal [:A, :G, :H, :I, :J], rev_list_helper(git, nil, :J)
23+
24+
# Limited history from one commit to another
25+
assert_equal [], rev_list_helper(git, :A, :A)
26+
assert_equal [:B], rev_list_helper(git, :A, :B)
27+
assert_equal [:B, :G, :H, :C], rev_list_helper(git, :A, :C)
28+
assert_equal [:B, :G, :H, :C, :I, :D], rev_list_helper(git, :A, :D)
29+
assert_equal [:G, :H, :C, :I, :D], rev_list_helper(git, :B, :D)
30+
assert_equal [:I, :D], rev_list_helper(git, :C, :D)
31+
assert_equal [:H, :I, :J], rev_list_helper(git, :G, :J)
32+
end
33+
end
34+
35+
protected
36+
37+
def rev_list_helper(git, from, to)
38+
to_labels(git.commit_tokens(from_label(from), from_label(to)))
39+
end
40+
41+
def commit_labels
42+
{ '886b62459ef1ffd01a908979d4d56776e0c5ecb2' => :A,
43+
'db77c232f01f7a649dd3a2216199a29cf98389b7' => :B,
44+
'f264fb40c340a415b305ac1f0b8f12502aa2788f' => :C,
45+
'57fedf267adc31b1403f700cc568fe4ca7975a6b' => :D,
46+
'97b80cb9743948cf302b6e21571ff40721a04c8d' => :G,
47+
'b8291f0e89567de3f691afc9b87a5f1908a6f3ea' => :H,
48+
'd067161caae2eeedbd74976aeff5c4d8f1ccc946' => :I,
49+
'b49aeaec003cf8afb18152cd9e292816776eecd6' => :J
50+
}
51+
end
52+
53+
def to_label(sha1)
54+
commit_labels[sha1.to_s]
55+
end
56+
57+
def to_labels(sha1s)
58+
sha1s.collect { |sha1| to_label(sha1) }
59+
end
60+
61+
def from_label(l)
62+
commit_labels.each_pair { |k,v| return k if v.to_s == l.to_s }
63+
nil
64+
end
65+
end
66+
end

test/unit/git_walk_test.rb

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)