[PATCH 2 of 3 STABLE] tag: prevent old id from being written out if type of old differs from new one

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Apr 24 10:12:28 CDT 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1366815044 -32400
#      Wed Apr 24 23:50:44 2013 +0900
# Branch stable
# Node ID 4b8427b226d6ab5088678b585bd9700c43c835f5
# Parent  e20be67cf59c775a9df3b1b462ea4ee402ba89b3
tag: prevent old id from being written out if type of old differs from new one

Before this patch, tag overwriting always causes old tagged id to be
written out into management file (".hgtags" or ".hg/localtags"), even
if type of overwritten tag differs from type of overwriting one: from
local to global, and vice versa.

In the case of overwriting local tag by global one, old tagged id for
local tag may cause unexpected history/rank comparison between
".hgtags" on divergent head revisions.

This patch prevents old tagged id from being written out, if type of
it differs from new one.

This patch tests only the case of overwriting local tag by global one,
because reverse case should be aborted at command line checking.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -434,6 +434,7 @@
                 self.ui.warn(_("warning: tag %s conflicts with existing"
                 " branch name\n") % name)
 
+        tagtype = local and 'local' or 'global'
         def writetags(fp, names, munge, prevtags):
             fp.seek(0, 2)
             if prevtags and prevtags[-1] != '\n':
@@ -441,7 +442,7 @@
             for name in names:
                 m = munge and munge(name) or name
                 if (self._tagscache.tagtypes and
-                    name in self._tagscache.tagtypes):
+                    self._tagscache.tagtypes.get(name) == tagtype):
                     old = self.tags().get(name, nullid)
                     fp.write('%s %s\n' % (hex(old), m))
                 fp.write('%s %s\n' % (hex(node), m))
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -389,4 +389,18 @@
   localtag                           0:bbd179dfa0a7 local
   globaltag                          0:bbd179dfa0a7
 
+Test that the global tag overwriting local one is created without
+historical information about local one.
+
+  $ cat .hgtags
+  bbd179dfa0a71671c253b3ae0aa1513b60d199fa globaltag
+  $ hg tag -f -r 1 localtag
+  $ hg tags -v
+  tip                                2:17637385ece3
+  localtag                           1:a0b6fe111088
+  globaltag                          0:bbd179dfa0a7
+  $ cat .hgtags
+  bbd179dfa0a71671c253b3ae0aa1513b60d199fa globaltag
+  a0b6fe111088c8c29567d3876cc466aa02927cae localtag
+
   $ cd ..


More information about the Mercurial-devel mailing list