[PATCH] convert: make tags children of the nodes they tag

Brendan Cully brendan at kublai.com
Wed Jul 11 03:03:40 CDT 2007


# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1184141011 25200
# Node ID 730206f6ee6570dd99a883bf3184ad89b415fc09
# Parent  1f3742217a7689928becc04066c303a5329585bc
convert: make tags children of the nodes they tag

They also have the same date and branch as the nodes they tag. One
advantage of this scheme is that a clone -r branch will get the tags
that belong on that branch and avoid those that don't (otherwise, many
operations complain about invalid tags).

One regression is that deleted tags are not discovered when convert is
run incrementally. This could be fixed in a second changeset if
desired.

diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -225,6 +225,14 @@ class convert(object):
             num = len(t)
             c = None
 
+            tags = self.source.gettags()
+            newtags = {}
+            for tag, rev in tags.iteritems():
+                if rev not in t:
+                    continue
+                newtags.setdefault(rev, []).append(tag)
+            # TODO: discover and remove deleted tags
+
             self.ui.status("converting...\n")
             for c in t:
                 num -= 1
@@ -236,20 +244,14 @@ class convert(object):
                 self.commitcache[c].author = author
                 self.ui.status("%d %s\n" % (num, desc))
                 self.copy(c)
-
-            tags = self.source.gettags()
-            ctags = {}
-            for k in tags:
-                v = tags[k]
-                if v in self.map:
-                    ctags[k] = self.map[v]
-
-            if c and ctags:
-                nrev = self.dest.puttags(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)
+                if c in newtags:
+                    self.ui.status(' * tagged %s\n' % ', '.join(newtags[c]))
+                    for tag in newtags[c]:
+                        nrev = self.dest.puttag(tag, self.map[c])
+                        # 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.writeauthormap()
         finally:
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -69,6 +69,19 @@ class convert_mercurial(converter_sink):
 
         return p2
 
+    def puttag(self, tag, rev):
+        ctx = self.repo.changectx(rev)
+        extra = {}
+        if ctx.branch():
+            extra['branch'] = ctx.branch()
+        date = '%d %d' % ctx.date()
+        msg = 'imported tag %s' % tag
+
+        n = self.repo._tag(tag, ctx.node(), msg, False, 'convert-repo', date,
+                           parent=ctx.node(), extra=extra)
+
+        return hg.hex(n)
+
     def puttags(self, tags):
         try:
             old = self.repo.wfile(".hgtags").read()


More information about the Mercurial-devel mailing list