[CHANGE] Ensure that the hg logs are ordered in the desired way:
authorRobin Luckey <robin@ohloh.net>
Wed, 4 Feb 2009 23:29:14 +0000 (15:29 -0800)
committerRobin Luckey <robin@ohloh.net>
Wed, 4 Feb 2009 23:29:14 +0000 (15:29 -0800)
           1. oldest first (parents before children)
           2. first parent before branch parents
           3. use the --follow behavior so that only actual ancestors are returned

19 files changed:
lib/scm/adapters/hg/commits.rb
test/repositories/graph.tgz [deleted file]
test/repositories/hg_walk/.hg/00changelog.i [new file with mode: 0644]
test/repositories/hg_walk/.hg/branch [new file with mode: 0644]
test/repositories/hg_walk/.hg/branch.cache [new file with mode: 0644]
test/repositories/hg_walk/.hg/dirstate [new file with mode: 0644]
test/repositories/hg_walk/.hg/merge/69e27356ef629022720d868ab0c0e3394775b6c1 [new file with mode: 0644]
test/repositories/hg_walk/.hg/merge/state [new file with mode: 0644]
test/repositories/hg_walk/.hg/requires [new file with mode: 0644]
test/repositories/hg_walk/.hg/store/00changelog.i [new file with mode: 0644]
test/repositories/hg_walk/.hg/store/00manifest.i [new file with mode: 0644]
test/repositories/hg_walk/.hg/store/data/_r_e_a_d_m_e.i [new file with mode: 0644]
test/repositories/hg_walk/.hg/store/fncache [new file with mode: 0644]
test/repositories/hg_walk/.hg/store/undo [new file with mode: 0644]
test/repositories/hg_walk/.hg/undo.branch [new file with mode: 0644]
test/repositories/hg_walk/.hg/undo.dirstate [new file with mode: 0644]
test/repositories/hg_walk/README [new file with mode: 0644]
test/unit/git_rev_list_test.rb
test/unit/hg_rev_list_test.rb [new file with mode: 0644]

index 551032c9e8b0d539bb7076514ca83fc1b5b9083d..e3284b2adce23837b5ebb1461a58725843ecca73 100644 (file)
@@ -7,12 +7,15 @@ module Scm::Adapters
                end
 
                # Return the list of commit tokens following +since+.
-               def commit_tokens(since=0)
-                       tokens = run("cd '#{self.url}' && hg log -r #{since || 0}:tip --template='{node}\\n'").split("\n")
+               def commit_tokens(since=0, up_to='tip')
+                       # We reverse the final result in Ruby, rather than passing the --reverse flag to hg.
+                       # That's because the -f (follow) flag doesn't behave the same in both directions.
+                       # Basically, we're trying very hard to make this act just like Git. The hg_rev_list_test checks this.
+                       tokens = run("cd '#{self.url}' && hg log -f -r #{up_to || 'tip'}:#{since || 0} --template='{node}\\n'").split("\n").reverse
 
                        # Hg returns everything after *and including* since.
-                       # We do not want to include it.
-                       if tokens.any? && tokens.first == since 
+                       # We want to exclude it.
+                       if tokens.any? && tokens.first == since
                                tokens[1..-1]
                        else
                                tokens
@@ -24,8 +27,8 @@ module Scm::Adapters
                # If you need all commits including diffs, you should use the each_commit() iterator, which only holds one commit
                # in memory at a time.
                def commits(since=0)
-                       log = run("cd '#{self.url}' && hg log -v -r #{since || 0}:tip --style #{Scm::Parsers::HgStyledParser.style_path}")
-                       a = Scm::Parsers::HgStyledParser.parse(log)
+                       log = run("cd '#{self.url}' && hg log -f -v -r tip:#{since || 0} --style #{Scm::Parsers::HgStyledParser.style_path}")
+                       a = Scm::Parsers::HgStyledParser.parse(log).reverse
 
                        if a.any? && a.first.token == since
                                a[1..-1]
@@ -54,7 +57,7 @@ module Scm::Adapters
 
                # Not used by Ohloh proper, but handy for debugging and testing
                def log(since=0)
-                       run "cd '#{url}' && hg log -v -r #{since}:tip"
+                       run "cd '#{url}' && hg log -f -v -r tip:#{since}"
                end
 
                # Returns a file handle to the log.
diff --git a/test/repositories/graph.tgz b/test/repositories/graph.tgz
deleted file mode 100644 (file)
index e3cf77d..0000000
Binary files a/test/repositories/graph.tgz and /dev/null differ
diff --git a/test/repositories/hg_walk/.hg/00changelog.i b/test/repositories/hg_walk/.hg/00changelog.i
new file mode 100644 (file)
index 0000000..d3a8311
Binary files /dev/null and b/test/repositories/hg_walk/.hg/00changelog.i differ
diff --git a/test/repositories/hg_walk/.hg/branch b/test/repositories/hg_walk/.hg/branch
new file mode 100644 (file)
index 0000000..4ad96d5
--- /dev/null
@@ -0,0 +1 @@
+default
diff --git a/test/repositories/hg_walk/.hg/branch.cache b/test/repositories/hg_walk/.hg/branch.cache
new file mode 100644 (file)
index 0000000..2ad1947
--- /dev/null
@@ -0,0 +1,2 @@
+8daa1aefa228d3ee5f9a0f685d696826e88266fb 6
+8daa1aefa228d3ee5f9a0f685d696826e88266fb default
diff --git a/test/repositories/hg_walk/.hg/dirstate b/test/repositories/hg_walk/.hg/dirstate
new file mode 100644 (file)
index 0000000..d1e8f54
Binary files /dev/null and b/test/repositories/hg_walk/.hg/dirstate differ
diff --git a/test/repositories/hg_walk/.hg/merge/69e27356ef629022720d868ab0c0e3394775b6c1 b/test/repositories/hg_walk/.hg/merge/69e27356ef629022720d868ab0c0e3394775b6c1
new file mode 100644 (file)
index 0000000..3cc58df
--- /dev/null
@@ -0,0 +1 @@
+C
diff --git a/test/repositories/hg_walk/.hg/merge/state b/test/repositories/hg_walk/.hg/merge/state
new file mode 100644 (file)
index 0000000..07ff788
Binary files /dev/null and b/test/repositories/hg_walk/.hg/merge/state differ
diff --git a/test/repositories/hg_walk/.hg/requires b/test/repositories/hg_walk/.hg/requires
new file mode 100644 (file)
index 0000000..5175383
--- /dev/null
@@ -0,0 +1,3 @@
+revlogv1
+store
+fncache
diff --git a/test/repositories/hg_walk/.hg/store/00changelog.i b/test/repositories/hg_walk/.hg/store/00changelog.i
new file mode 100644 (file)
index 0000000..18c3192
Binary files /dev/null and b/test/repositories/hg_walk/.hg/store/00changelog.i differ
diff --git a/test/repositories/hg_walk/.hg/store/00manifest.i b/test/repositories/hg_walk/.hg/store/00manifest.i
new file mode 100644 (file)
index 0000000..3874605
Binary files /dev/null and b/test/repositories/hg_walk/.hg/store/00manifest.i differ
diff --git a/test/repositories/hg_walk/.hg/store/data/_r_e_a_d_m_e.i b/test/repositories/hg_walk/.hg/store/data/_r_e_a_d_m_e.i
new file mode 100644 (file)
index 0000000..0f0c4c3
Binary files /dev/null and b/test/repositories/hg_walk/.hg/store/data/_r_e_a_d_m_e.i differ
diff --git a/test/repositories/hg_walk/.hg/store/fncache b/test/repositories/hg_walk/.hg/store/fncache
new file mode 100644 (file)
index 0000000..fb1271b
--- /dev/null
@@ -0,0 +1 @@
+data/README.i
diff --git a/test/repositories/hg_walk/.hg/store/undo b/test/repositories/hg_walk/.hg/store/undo
new file mode 100644 (file)
index 0000000..dee7b93
Binary files /dev/null and b/test/repositories/hg_walk/.hg/store/undo differ
diff --git a/test/repositories/hg_walk/.hg/undo.branch b/test/repositories/hg_walk/.hg/undo.branch
new file mode 100644 (file)
index 0000000..331d858
--- /dev/null
@@ -0,0 +1 @@
+default
\ No newline at end of file
diff --git a/test/repositories/hg_walk/.hg/undo.dirstate b/test/repositories/hg_walk/.hg/undo.dirstate
new file mode 100644 (file)
index 0000000..867d35c
Binary files /dev/null and b/test/repositories/hg_walk/.hg/undo.dirstate differ
diff --git a/test/repositories/hg_walk/README b/test/repositories/hg_walk/README
new file mode 100644 (file)
index 0000000..1784810
--- /dev/null
@@ -0,0 +1 @@
+D
index 19fababfe2e5b94f205c51d0ad9345cd3a10b05d..4b48aa3f824e5aec32aa05ff0a5fba207bc3cdfb 100644 (file)
@@ -1,7 +1,7 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 module Scm::Adapters
-       # Repository graph.git has the following structure:
+       # Repository git_walk has the following structure:
        #
        #      G -> H -> I -> J -> development
        #     /      \    \
diff --git a/test/unit/hg_rev_list_test.rb b/test/unit/hg_rev_list_test.rb
new file mode 100644 (file)
index 0000000..b5036cb
--- /dev/null
@@ -0,0 +1,63 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+module Scm::Adapters
+       # Repository hg_walk has the following structure:
+       #
+       #      G -> H -> I
+       #     /      \    \
+       #    A -> B -> C -> D -> tip
+       #
+       class HgRevListTest < Scm::Test
+
+               def test_rev_list
+                       with_hg_repository('hg_walk') do |hg|
+                               # Full history to a commit
+                               assert_equal [:A],                         rev_list_helper(hg, nil, :A)
+                               assert_equal [:A, :B],                     rev_list_helper(hg, nil, :B)
+                               assert_equal [:A, :B, :G, :H, :C],         rev_list_helper(hg, nil, :C)
+                               assert_equal [:A, :B, :G, :H, :C, :I, :D], rev_list_helper(hg, nil, :D)
+                               assert_equal [:A, :G],                     rev_list_helper(hg, nil, :G)
+                               assert_equal [:A, :G, :H],                 rev_list_helper(hg, nil, :H)
+                               assert_equal [:A, :G, :H, :I],             rev_list_helper(hg, nil, :I)
+
+                               # Limited history from one commit to another
+                               assert_equal [],                           rev_list_helper(hg, :A, :A)
+                               assert_equal [:B],                         rev_list_helper(hg, :A, :B)
+                               assert_equal [:B, :G, :H, :C],             rev_list_helper(hg, :A, :C)
+                               assert_equal [:B, :G, :H, :C, :I, :D],     rev_list_helper(hg, :A, :D)
+                               assert_equal [:G, :H, :C, :I, :D],         rev_list_helper(hg, :B, :D)
+                               assert_equal [:I, :D],                     rev_list_helper(hg, :C, :D)
+                       end
+               end
+
+               protected
+
+               def rev_list_helper(hg, from, to)
+                       to_labels(hg.commit_tokens(from_label(from), from_label(to)))
+               end
+
+               def commit_labels
+                       { '4bfbf836feeebb236492199fbb0d1474e26f69d9' => :A,
+                               '23edb79d0d06c8c315d8b9e7456098823335377d' => :B,
+                               '7e33b9fde56a6e3576753868d08fa143e4e8a9cf' => :C,
+                               '8daa1aefa228d3ee5f9a0f685d696826e88266fb' => :D,
+                               'e43cf1bb4b80d8ae70a695ec070ce017fdc529f3' => :G,
+                               'dca215d8a3e4dd3e472379932f1dd9c909230331' => :H,
+                               '3a1495175e40b1c983441d6a8e8e627d2bd672b6' => :I
+                       }
+               end
+
+               def to_label(sha1)
+                       commit_labels[sha1.to_s]
+               end
+
+               def to_labels(sha1s)
+                       sha1s.collect { |sha1| to_label(sha1) }
+               end
+
+               def from_label(l)
+                       commit_labels.each_pair { |k,v| return k if v.to_s == l.to_s }
+                       nil
+               end
+       end
+end