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

Commit 4a5f0ee

Browse files
author
Robin Luckey
committed
[CHANGE] Ensure that the hg logs are ordered in the desired way:
1. oldest first (parents before children) 2. first parent before branch parents 3. use the --follow behavior so that only actual ancestors are returned
1 parent 6ee3fef commit 4a5f0ee

19 files changed

+84
-8
lines changed

lib/scm/adapters/hg/commits.rb

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

99
# Return the list of commit tokens following +since+.
10-
def commit_tokens(since=0)
11-
tokens = run("cd '#{self.url}' && hg log -r #{since || 0}:tip --template='{node}\\n'").split("\n")
10+
def commit_tokens(since=0, up_to='tip')
11+
# We reverse the final result in Ruby, rather than passing the --reverse flag to hg.
12+
# That's because the -f (follow) flag doesn't behave the same in both directions.
13+
# Basically, we're trying very hard to make this act just like Git. The hg_rev_list_test checks this.
14+
tokens = run("cd '#{self.url}' && hg log -f -r #{up_to || 'tip'}:#{since || 0} --template='{node}\\n'").split("\n").reverse
1215

1316
# Hg returns everything after *and including* since.
14-
# We do not want to include it.
15-
if tokens.any? && tokens.first == since
17+
# We want to exclude it.
18+
if tokens.any? && tokens.first == since
1619
tokens[1..-1]
1720
else
1821
tokens
@@ -24,8 +27,8 @@ def commit_tokens(since=0)
2427
# If you need all commits including diffs, you should use the each_commit() iterator, which only holds one commit
2528
# in memory at a time.
2629
def commits(since=0)
27-
log = run("cd '#{self.url}' && hg log -v -r #{since || 0}:tip --style #{Scm::Parsers::HgStyledParser.style_path}")
28-
a = Scm::Parsers::HgStyledParser.parse(log)
30+
log = run("cd '#{self.url}' && hg log -f -v -r tip:#{since || 0} --style #{Scm::Parsers::HgStyledParser.style_path}")
31+
a = Scm::Parsers::HgStyledParser.parse(log).reverse
2932

3033
if a.any? && a.first.token == since
3134
a[1..-1]
@@ -54,7 +57,7 @@ def each_commit(since=0)
5457

5558
# Not used by Ohloh proper, but handy for debugging and testing
5659
def log(since=0)
57-
run "cd '#{url}' && hg log -v -r #{since}:tip"
60+
run "cd '#{url}' && hg log -f -v -r tip:#{since}"
5861
end
5962

6063
# Returns a file handle to the log.

test/repositories/graph.tgz

-9.86 KB
Binary file not shown.
57 Bytes
Binary file not shown.

test/repositories/hg_walk/.hg/branch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
8daa1aefa228d3ee5f9a0f685d696826e88266fb 6
2+
8daa1aefa228d3ee5f9a0f685d696826e88266fb default
63 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C
154 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
revlogv1
2+
store
3+
fncache
Binary file not shown.
791 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data/README.i
53 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default
63 Bytes
Binary file not shown.

test/repositories/hg_walk/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
D

test/unit/git_rev_list_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require File.dirname(__FILE__) + '/../test_helper'
22

33
module Scm::Adapters
4-
# Repository graph.git has the following structure:
4+
# Repository git_walk has the following structure:
55
#
66
# G -> H -> I -> J -> development
77
# / \ \

test/unit/hg_rev_list_test.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require File.dirname(__FILE__) + '/../test_helper'
2+
3+
module Scm::Adapters
4+
# Repository hg_walk has the following structure:
5+
#
6+
# G -> H -> I
7+
# / \ \
8+
# A -> B -> C -> D -> tip
9+
#
10+
class HgRevListTest < Scm::Test
11+
12+
def test_rev_list
13+
with_hg_repository('hg_walk') do |hg|
14+
# Full history to a commit
15+
assert_equal [:A], rev_list_helper(hg, nil, :A)
16+
assert_equal [:A, :B], rev_list_helper(hg, nil, :B)
17+
assert_equal [:A, :B, :G, :H, :C], rev_list_helper(hg, nil, :C)
18+
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)
22+
23+
# Limited history from one commit to another
24+
assert_equal [], rev_list_helper(hg, :A, :A)
25+
assert_equal [:B], rev_list_helper(hg, :A, :B)
26+
assert_equal [:B, :G, :H, :C], rev_list_helper(hg, :A, :C)
27+
assert_equal [:B, :G, :H, :C, :I, :D], rev_list_helper(hg, :A, :D)
28+
assert_equal [:G, :H, :C, :I, :D], rev_list_helper(hg, :B, :D)
29+
assert_equal [:I, :D], rev_list_helper(hg, :C, :D)
30+
end
31+
end
32+
33+
protected
34+
35+
def rev_list_helper(hg, from, to)
36+
to_labels(hg.commit_tokens(from_label(from), from_label(to)))
37+
end
38+
39+
def commit_labels
40+
{ '4bfbf836feeebb236492199fbb0d1474e26f69d9' => :A,
41+
'23edb79d0d06c8c315d8b9e7456098823335377d' => :B,
42+
'7e33b9fde56a6e3576753868d08fa143e4e8a9cf' => :C,
43+
'8daa1aefa228d3ee5f9a0f685d696826e88266fb' => :D,
44+
'e43cf1bb4b80d8ae70a695ec070ce017fdc529f3' => :G,
45+
'dca215d8a3e4dd3e472379932f1dd9c909230331' => :H,
46+
'3a1495175e40b1c983441d6a8e8e627d2bd672b6' => :I
47+
}
48+
end
49+
50+
def to_label(sha1)
51+
commit_labels[sha1.to_s]
52+
end
53+
54+
def to_labels(sha1s)
55+
sha1s.collect { |sha1| to_label(sha1) }
56+
end
57+
58+
def from_label(l)
59+
commit_labels.each_pair { |k,v| return k if v.to_s == l.to_s }
60+
nil
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)