# HG changeset patch
# Parent f786fc4b8764cd2a5526d259cf2f94d8a66924d9
convert: add incremental tagging mode

Instead of performing a whole conversion, then adding all the tags,
we propose to add a tag as soon as its parent was converted.

The old behavior is kept by default and the new one is used
if 'convert.incrementaltagging' is True.

diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -342,6 +342,9 @@ class converter(object):
             t = self.toposort(parents, sortmode)
             num = len(t)
             c = None
+            tags = self.source.gettags()
+            rtags = dict((v, k) for k, v in tags.items())
+            incr = self.ui.configbool('convert', 'incrementaltagging', False)
 
             self.ui.status(_("converting...\n"))
             for i, c in enumerate(t):                
@@ -357,29 +360,36 @@ class converter(object):
                 self.ui.progress(_('converting'), i, unit=_('revisions'),
                                  total=len(t))
                 self.copy(c)
+                tag = rtags.get(c)
+                if incr and tag:
+                    ctag = self.map.get(c, SKIPREV)
+                    if ctag != SKIPREV:
+                        self.maketags({tag: ctag})
             self.ui.progress(_('converting'), None)
 
-            tags = self.source.gettags()
-            ctags = {}
-            for k in tags:
-                v = tags[k]
-                if self.map.get(v, SKIPREV) != SKIPREV:
-                    ctags[k] = self.map[v]
-
-            if c and ctags:
-                nrev, tagsparent = self.dest.puttags(ctags)
-                if nrev and tagsparent:
-                    # write another hash correspondence to override the previous
-                    # one so we don't end up with extra tag heads
-                    tagsparents = [e for e in self.map.iteritems()
-                                   if e[1] == tagsparent]
-                    if tagsparents:
-                        self.map[tagsparents[0][0]] = nrev
+            if not incr:
+                ctags = {}
+                for k in tags:
+                    v = tags[k]
+                    if self.map.get(v, SKIPREV) != SKIPREV:
+                        ctags[k] = self.map[v]
+                if c and ctags:
+                    self.maketags(ctags)
 
             self.writeauthormap()
         finally:
             self.cleanup()
 
+    def maketags(self, ctags):
+        nrev, tagsparent = self.dest.puttags(ctags)
+        if nrev and tagsparent:
+            # write another hash correspondence to override the previous
+            # one so we don't end up with extra tag heads
+            tagsparents = [e for e in self.map.iteritems()
+                           if e[1] == tagsparent]
+            if tagsparents:
+                self.map[tagsparents[0][0]] = nrev
+
     def cleanup(self):
         try:
             self.dest.after()

