diff mercurial/localrepo.py @ 2320:dbdce3b99988

fix parsing of tags. make parse errors useful. add new tag tests. old code read every head of .hgtags. delete and recreate of .hgtags gave new head, but if error in deleted rev, .hgtags had error messages every time it was parsed. this was very hard to fix, because deleted revs hard to get back and update, needed merges too. new code reads .hgtags on every head. advantage is if parse error happens with new code, is possible to fix them by editing .hgtags on a head and committing. NOTE: new code uses binary search of manifest of each head to be fast, but still much slower than old code. best thing would be to have delete record stored in filelog so we never touch manifest. could find live heads directly from filelog. this is more work than i want now. new tests check for parse of tags on different heads, and inaccessible heads created by delete and recreate of .hgtags.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 18 May 2006 23:31:12 -0700
parents 7c2623aedeb4
children f0680b2d1d64 4f7745fc9823
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu May 18 23:02:24 2006 -0700
+++ b/mercurial/localrepo.py	Thu May 18 23:31:12 2006 -0700
@@ -166,37 +166,44 @@
                     return
                 s = l.split(" ", 1)
                 if len(s) != 2:
-                    self.ui.warn(_("%s: ignoring invalid tag\n") % context)
+                    self.ui.warn(_("%s: cannot parse entry\n") % context)
                     return
                 node, key = s
+                key = key.strip()
                 try:
                     bin_n = bin(node)
                 except TypeError:
-                    self.ui.warn(_("%s: ignoring invalid tag\n") % context)
+                    self.ui.warn(_("%s: node '%s' is not well formed\n") %
+                                 (context, node))
                     return
                 if bin_n not in self.changelog.nodemap:
-                    self.ui.warn(_("%s: ignoring invalid tag\n") % context)
+                    self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
+                                 (context, key))
                     return
-                self.tagscache[key.strip()] = bin_n
+                self.tagscache[key] = bin_n
 
-            # read each head of the tags file, ending with the tip
+            # read the tags file from each head, ending with the tip,
             # and add each tag found to the map, with "newer" ones
             # taking precedence
+            heads = self.heads()
+            heads.reverse()
             fl = self.file(".hgtags")
-            h = fl.heads()
-            h.reverse()
-            for r in h:
+            for node in heads:
+                change = self.changelog.read(node)
+                rev = self.changelog.rev(node)
+                fn, ff = self.manifest.find(change[0], '.hgtags')
+                if fn is None: continue
                 count = 0
-                for l in fl.read(r).splitlines():
+                for l in fl.read(fn).splitlines():
                     count += 1
-                    parsetag(l, ".hgtags:%d" % count)
-
+                    parsetag(l, _(".hgtags (rev %d:%s), line %d") %
+                             (rev, short(node), count))
             try:
                 f = self.opener("localtags")
                 count = 0
                 for l in f:
                     count += 1
-                    parsetag(l, "localtags:%d" % count)
+                    parsetag(l, _("localtags, line %d") % count)
             except IOError:
                 pass