[PATCH 4 of 4] Add tags always on the same branch

Edouard Gomez ed.gomez at free.fr
Tue Feb 6 15:14:09 CST 2007

# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1170775893 -3600
# Node ID 915cb87f425f711437a1d14a331ea1b5fb14fa76
# Parent  5d510b4b3e8cc06a13b505dcde4f93e56a7c4914
Add tags always on the same branch

convert-repo uses to commit tags on the tip. This has 1 pro and 2 cons:
 - it's cool to have tip (tag node) reflect the last real commit node
   hg up -C gives exactly the same working dir
 - the tags commit nodes are floating all around history w/o real logic
   except the user started convert-repo at that precise time
 - If we consider tags are not part of history but they live aside, it's
   just better to really mean this by tagging always on the same branch

The proposed solution is to have a fake '0' source changeset that always
points to the last 'update tag' commit. This '0' source changeset is mapped
to a real hg node in the map file, and can be used in a future run to
keep track of this unamed head. The first 'tag' commit is parented
to the first revision.

'0' source node id is safe for both cvs and git backendfs because in both
cases, it doesn't collide with possible real source nodes id. GIT uses
an hexified sha1 and cvs patchsets starts being numbered from 1.

diff -r 5d510b4b3e8c -r 915cb87f425f contrib/convert-repo
--- a/contrib/convert-repo	Tue Feb 06 00:36:19 2007 +0100
+++ b/contrib/convert-repo	Tue Feb 06 16:31:33 2007 +0100
@@ -430,7 +430,7 @@ class convert_mercurial:
         return p2
-    def puttags(self, tags):
+    def puttags(self, parent, tags):
             old = self.repo.wfile(".hgtags").read()
             oldlines = old.splitlines(1)
@@ -453,8 +453,9 @@ class convert_mercurial:
             if not oldlines: self.repo.add([".hgtags"])
             date = "%s 0" % int(time.mktime(time.gmtime()))
+            parent = parent or self.repo.changelog.node(0)
             self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
-                                date, self.repo.changelog.tip(), hg.nullid)
+                                date, parent, hg.nullid)
             return hg.hex(self.repo.changelog.tip())
 converters = [convert_cvs, convert_git, convert_mercurial]
@@ -643,11 +644,14 @@ class convert:
                 ctags[k] = self.map[v]
         if c and ctags:
-            nrev = self.dest.puttags(ctags)
+            parent = None
+            if '0' in self.map:
+                parent = hg.bin(self.map.get('0'))
+            nrev = self.dest.puttags(parent, ctags)
             # write another hash correspondence to override the previous
             # one so we don't end up with extra tag heads
             if nrev:
-                self.mapentry(c, nrev)
+                self.mapentry('0', nrev)

More information about the Mercurial-devel mailing list