Patchwork [1,of,3,STABLE] tags: prevent local tag from overwriting existing global tag

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 24, 2013, 3:12 p.m.
Message ID <e20be67cf59c775a9df3.1366816347@feefifofum>
Download mbox | patch
Permalink /patch/1476/
State Rejected, archived
Headers show

Comments

Katsunori FUJIWARA - April 24, 2013, 3:12 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1366814858 -32400
#      Wed Apr 24 23:47:38 2013 +0900
# Branch stable
# Node ID e20be67cf59c775a9df3b1b462ea4ee402ba89b3
# Parent  70675d77fd4a78d3e57723550d9f3031345d38e4
tags: prevent local tag from overwriting existing global tag

Before this patch, local tag has higher priority than existing global
tag in many cases, because ".hg/localtags" is read in after ".hgtags"
on each head revisions.

This causes unexpected behavior like below:

    1. "hg tag -l foo" creates local "foo"

    2. "hg tag -f foo" creates global "foo" (and should overwrite
       local one)

    3. but "hg tags -v" shows "foo" as "local" one, even though global
       "foo" is recorded in history, because local tag "foo" has
       higher priority than global one

    4. "hg tag -l --remove foo" removes local "foo"

    5. "hg tags -v" doesn't show "foo", because local tag "foo"
       related to "null" revision still has higher priority than
       global one

In this case, user should edit ".hg/localtags" directly to see "foo"
as global.

This patch prevents local tags from overwriting existing global ones
for consistent view of tags.
Matt Mackall - April 24, 2013, 9:33 p.m.
On Thu, 2013-04-25 at 00:12 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1366814858 -32400
> #      Wed Apr 24 23:47:38 2013 +0900
> # Branch stable
> # Node ID e20be67cf59c775a9df3b1b462ea4ee402ba89b3
> # Parent  70675d77fd4a78d3e57723550d9f3031345d38e4
> tags: prevent local tag from overwriting existing global tag
> 
> Before this patch, local tag has higher priority than existing global
> tag in many cases, because ".hg/localtags" is read in after ".hgtags"
> on each head revisions.

That's intentional. The logic is that, lacking any way to compare
ordering between local and global tags, "my tag" is more important than
"their tag".

This has the advantage that I have the ability to -change- a local tag
locally to have control over exactly this sort of conflict should I have
been so foolish as to pick a local tag name that collides with a global
one. Moving global tags to resolve such a conflict is a less good idea.

Even if it wasn't intentional, it now has 8 years of precedent, and we
can't guess if people are depending on it continuing to work this way.
Katsunori FUJIWARA - April 25, 2013, 7:25 a.m.
At Wed, 24 Apr 2013 16:33:02 -0500,
Matt Mackall wrote:
> 
> On Thu, 2013-04-25 at 00:12 +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1366814858 -32400
> > #      Wed Apr 24 23:47:38 2013 +0900
> > # Branch stable
> > # Node ID e20be67cf59c775a9df3b1b462ea4ee402ba89b3
> > # Parent  70675d77fd4a78d3e57723550d9f3031345d38e4
> > tags: prevent local tag from overwriting existing global tag
> > 
> > Before this patch, local tag has higher priority than existing global
> > tag in many cases, because ".hg/localtags" is read in after ".hgtags"
> > on each head revisions.
> 
> That's intentional. The logic is that, lacking any way to compare
> ordering between local and global tags, "my tag" is more important than
> "their tag".
> 
> This has the advantage that I have the ability to -change- a local tag
> locally to have control over exactly this sort of conflict should I have
> been so foolish as to pick a local tag name that collides with a global
> one. Moving global tags to resolve such a conflict is a less good idea.
> 
> Even if it wasn't intentional, it now has 8 years of precedent, and we
> can't guess if people are depending on it continuing to work this way.
> 
> -- 
> Mathematics is the supreme nostalgia of our time.

OK, I withdraw this patch series.

Instead of this, I'll post another series adding some description or
hint to avoid confusion from local tag overwriting, because current
documentation seems not to be enough for non-programmer users.

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -71,7 +71,7 @@ 
     filetags = _readtags(
         ui, repo, data.splitlines(), "localtags",
         recode=encoding.fromlocal)
-    _updatetags(filetags, "local", alltags, tagtypes)
+    _updatetags(filetags, "local", alltags, tagtypes, overwrite=False)
 
 def _readtags(ui, repo, lines, fn, recode=None):
     '''Read tag definitions from a file (or any source of lines).
@@ -112,7 +112,7 @@ 
         filetags[name] = (nodebin, hist)
     return filetags
 
-def _updatetags(filetags, tagtype, alltags, tagtypes):
+def _updatetags(filetags, tagtype, alltags, tagtypes, overwrite=True):
     '''Incorporate the tag info read from one file into the two
     dictionaries, alltags and tagtypes, that contain all tag
     info (global across all heads plus local).'''
@@ -123,6 +123,9 @@ 
             tagtypes[name] = tagtype
             continue
 
+        if not overwrite:
+            continue
+
         # we prefer alltags[name] if:
         #  it supersedes us OR
         #  mutual supersedes and it has a higher rank
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -381,4 +381,12 @@ 
   localtag                           0:bbd179dfa0a7 local
   globaltag                          0:bbd179dfa0a7
 
+Test that the local tag overwriting global one is ignored
+
+  $ echo "a0b6fe111088c8c29567d3876cc466aa02927cae globaltag" >> .hg/localtags
+  $ hg tags -v
+  tip                                1:a0b6fe111088
+  localtag                           0:bbd179dfa0a7 local
+  globaltag                          0:bbd179dfa0a7
+
   $ cd ..