Skip to content

Commit 68c6170

Browse files
committed
Fix for hg v4 api changes
Since hg(v4) -f returns entire log. The original intent of using this flag was to limit log to current branch. This is now achieved by introducing `branch_name_or_default`. Since hg(v4) --follow-parent does not play well with `-r N:n`.
1 parent 4e08291 commit 68c6170

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

lib/ohloh_scm/adapters/hg/commits.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def commit_tokens(opts={})
1414
# Basically, we're trying very hard to make this act just like Git. The hg_rev_list_test checks this.
1515
tokens = run("cd '#{self.url}' && #{ hg_log_with_opts } --template='{node}\\n'").split("\n").reverse
1616

17+
# Since hg v4, --follow-first does not play well with -r N:n. Using them together always returns all commits.
18+
# To find trunk commits since a given revision, we get all trunk commits and drop older commits before given revision.
19+
tokens = tokens.drop(tokens.index(after)) if tokens.any? && after && after != 0
20+
1721
# Hg returns everything after *and including* after.
1822
# We want to exclude it.
1923
if tokens.any? && tokens.first == after
@@ -96,13 +100,13 @@ def hg_command_builder(opts)
96100
up_to = opts[:up_to] || :tip
97101

98102
options = if opts[:trunk_only]
99-
"--follow-first -r #{ up_to }:#{ after }"
103+
'--follow-first'
100104
else
101-
query = "and (branch(#{ branch_name }) or ancestors(#{ branch_name }))" if branch_name && branch_name != 'default'
105+
query = "and (branch(#{ branch_name_or_default }) or ancestors(#{ branch_name_or_default }))"
102106
"-r '#{ up_to }:#{ after } #{ query }'"
103107
end
104108

105-
["hg log -f -v #{ options }", after]
109+
["hg log -v #{ options }", after]
106110
end
107111
end
108112
end

lib/ohloh_scm/adapters/hg/head.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class HgAdapter < AbstractAdapter
33
def head_token
44
# This only returns first 12 characters.
55
# How can we make it return the entire hash?
6-
branch_opts = "--rev #{branch_name || :default}"
6+
branch_opts = "--rev #{branch_name_or_default}"
77
token = run("hg id --debug -i -q #{url} #{branch_opts}").strip
88

99
# Recent versions of Hg now somtimes append a '+' char to the token.

lib/ohloh_scm/adapters/hg/misc.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ def tags
3030
[tag_name, rev, Time.parse(time_string)]
3131
end
3232
end
33+
34+
protected
35+
36+
def branch_name_or_default
37+
branch_name || :default
38+
end
3339
end
3440
end

test/unit/hg_commits_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def test_commit_tokens
2929
'75532c1e1f1de55c2271f6fd29d98efbe35397c4',
3030
'655f04cf6ad708ab58c7b941672dce09dd369a18'], hg.commit_tokens
3131

32+
assert_equal ['b14fa4692f949940bd1e28da6fb4617de2615484',
33+
'468336c6671cbc58237a259d1b7326866afc2817',
34+
'75532c1e1f1de55c2271f6fd29d98efbe35397c4',
35+
'655f04cf6ad708ab58c7b941672dce09dd369a18'],
36+
hg.commit_tokens(after: '01101d8ef3cea7da9ac6e9a226d645f4418f05c9')
37+
3238
assert_equal ['655f04cf6ad708ab58c7b941672dce09dd369a18'],
3339
hg.commit_tokens(:after => '75532c1e1f1de55c2271f6fd29d98efbe35397c4')
3440

test/unit/hg_rev_list_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def test_rev_list
1616
assert_equal [:A, :B], rev_list_helper(hg, nil, :B)
1717
assert_equal [:A, :B, :G, :H, :C], rev_list_helper(hg, nil, :C)
1818
assert_equal [:A, :B, :G, :H, :C, :I, :D], rev_list_helper(hg, nil, :D)
19-
assert_equal [:A, :G], rev_list_helper(hg, nil, :G)
20-
assert_equal [:A, :G, :H], rev_list_helper(hg, nil, :H)
21-
assert_equal [:A, :G, :H, :I], rev_list_helper(hg, nil, :I)
19+
assert_equal [:A, :B, :G], rev_list_helper(hg, nil, :G)
20+
assert_equal [:A, :B, :G, :H], rev_list_helper(hg, nil, :H)
21+
assert_equal [:A, :B, :G, :H, :C, :I], rev_list_helper(hg, nil, :I)
2222

2323
# Limited history from one commit to another
2424
assert_equal [], rev_list_helper(hg, :A, :A)

0 commit comments

Comments
 (0)