[PATCH 1 of 5] convert: fix bug with converting the same commit twice

Durham Goode durham at fb.com
Mon Jun 29 20:44:01 CDT 2015


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1435610345 25200
#      Mon Jun 29 13:39:05 2015 -0700
# Node ID af9d42a3e9c6d03411e7713cf174ada52c81472c
# Parent  5d0847cd158741975598a29eedad1327af41fd1f
convert: fix bug with converting the same commit twice

Convert had a bug where it relied on repo.tip() to be the newly committed
commit. This was not the case if the commit already existed in the repository
(since repo.commitctx() did nothing, the tip() referenced some random other
commit and the revmap got corrupted).

This fixes it by using the node returned by repo.commitctx().

diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -284,7 +284,7 @@ class mercurial_sink(converter_sink):
                 tr.release()
 
             text = "(octopus merge fixup)\n"
-            p2 = hex(self.repo.changelog.tip())
+            p2 = node
 
         if self.filemapmode and nparents == 1:
             man = self.repo.manifest
@@ -344,8 +344,8 @@ class mercurial_sink(converter_sink):
         ctx = context.memctx(self.repo, (tagparent, None), "update tags",
                              [".hgtags"], getfilectx, "convert-repo", date,
                              extra)
-        self.repo.commitctx(ctx)
-        return hex(self.repo.changelog.tip()), hex(tagparent)
+        node = self.repo.commitctx(ctx)
+        return hex(node), hex(tagparent)
 
     def setfilemapmode(self, active):
         self.filemapmode = active
diff --git a/tests/test-convert-hg-source.t b/tests/test-convert-hg-source.t
--- a/tests/test-convert-hg-source.t
+++ b/tests/test-convert-hg-source.t
@@ -83,7 +83,43 @@ Different hash because no x bit
      premerge1                 3:973ef48a98a4
      premerge2                 8:3537b15eaaca
 #endif
-  $ cd ..
+
+Test that redoing a convert results in an identical graph
+  $ cd ../
+  $ rm new/.hg/shamap
+  $ hg convert --datesort orig new 2>&1 | grep -v 'subversion python bindings could not be loaded'
+  scanning source...
+  sorting...
+  converting...
+  8 add foo bar
+  7 change foo
+  6 make bar and baz copies of foo
+  5 merge local copy
+  4 merge remote copy
+  3 Added tag that for changeset 88586c4e9f02
+  2 Removed tag that
+  1 Added tag this for changeset c56a7f387039
+  0 mark baz executable
+  updating bookmarks
+  $ hg -R new log -G -T '{rev} {desc}'
+  o  8 mark baz executable
+  |
+  o  7 Added tag this for changeset c56a7f387039
+  |
+  o  6 Removed tag that
+  |
+  o  5 Added tag that for changeset 88586c4e9f02
+  |
+  o    4 merge remote copy
+  |\
+  +---o  3 merge local copy
+  | |/
+  | o  2 make bar and baz copies of foo
+  | |
+  o |  1 change foo
+  |/
+  o  0 add foo bar
+  
 
 check shamap LF and CRLF handling
 


More information about the Mercurial-devel mailing list