[PATCH 1 of 1] ( take 2 ) change tag computation to avoid surprises in case of multiple heads

Georg-W. Koltermann gwk.rko at googlemail.com
Sun Jan 7 12:45:28 CST 2007


# HG changeset patch
# User Georg.Koltermann at mscsoftware.com
# Date 1168195242 -3600
# Node ID 6a64de5982b74dfb7b3566359ee5762cd51fa1d5
# Parent  27230c29bfec36d5540fbe1c976810aefecfd1d2
FEATUREFIX: Change tag computation so that obsoleted tag lines (those lines in a tags file that are
superseded by subsequent lines of the same tag) are ignored.

Previously for any given tag the last entry in the tipmost tags file would win.  This caused
considerable surprises when a new tip was created off a historic version containing an
older .tags file.

With this change, lines that are superseded by newer entries in .tags files (called
obsoleted lines) are ignored in the process of tag computation. So creating a new
tip off a historic version will only result in exposing a new obsoleted tag entry which
is ignored, so having no effect on the final tag value.

diff -r 27230c29bfec -r 6a64de5982b7 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sun Dec 17 05:00:22 2006 +0100
+++ b/mercurial/localrepo.py	Sun Jan 07 19:40:42 2007 +0100
@@ -259,8 +259,9 @@ class localrepository(repo.repository):
         '''return a mapping of tag to node'''
         if not self.tagscache:
             self.tagscache = {}
-
-            def parsetag(line, context):
+            self._obsoletetagvalues = {}
+
+            def parsetag(line, context, tagsmap):
                 if not line:
                     return
                 s = l.split(" ", 1)
@@ -279,7 +280,10 @@ class localrepository(repo.repository):
                     self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
                                  (context, key))
                     return
-                self.tagscache[key] = bin_n
+                if key in tagsmap:
+                    self._obsoletetagvalues[(key, tagsmap[key])] = True
+                if not (key, bin_n) in self._obsoletetagvalues:
+                    tagsmap[key] = bin_n
 
             # read the tags file from each head, ending with the tip,
             # and add each tag found to the map, with "newer" ones
@@ -289,19 +293,23 @@ class localrepository(repo.repository):
                 f = (f and f.filectx(fnode) or
                      self.filectx('.hgtags', fileid=fnode))
                 count = 0
+                tagsmap = {}
                 for l in f.data().splitlines():
                     count += 1
-                    parsetag(l, _("%s, line %d") % (str(f), count))
+                    parsetag(l, _("%s, line %d") % (str(f), count), tagsmap)
+                self.tagscache.update(tagsmap)
 
             try:
                 f = self.opener("localtags")
                 count = 0
+                tagsmap = {}
                 for l in f:
                     # localtags are stored in the local character set
                     # while the internal tag table is stored in UTF-8
                     l = util.fromlocal(l)
                     count += 1
-                    parsetag(l, _("localtags, line %d") % count)
+                    parsetag(l, (_("localtags, line %d") % count), tagsmap)
+                self.tagscache.update(tagsmap)
             except IOError:
                 pass
 




More information about the Mercurial-devel mailing list