Patchwork [2,of,2,STABLE] revset: mask specific names for named() predicate

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Feb. 3, 2015, 1:04 p.m.
Message ID <244d92671cebd0b600a1.1422968684@juju>
Download mbox | patch
Permalink /patch/7628/
State Superseded
Commit 38824c53c2f1cabe9d57f252c4bb895862b2cd0b
Headers show

Comments

Katsunori FUJIWARA - Feb. 3, 2015, 1:04 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1422968239 -32400
#      Tue Feb 03 21:57:19 2015 +0900
# Branch stable
# Node ID 244d92671cebd0b600a192f1c896b4ba598621dd
# Parent  147878ac1d02298847d5b2a0d2e06063b2fefe91
revset: mask specific names for named() predicate

Before this patch, revset predicate "tags()" and "named('tags')"
differ from each other, because the former doesn't include "tip" but
the latter does.

For equivalence, "named('tags')" shouldn't include the revision
corresponded to "tip". But just removing "tip" from the "tags"
namespace may cause unexpected failure of looking "tip" tag up in
other code paths.

To mask specific names ("tip" in this case) for "named()" predicate,
this patch introduces "revsetmasks" into "namespaces", and makes
"named()" predicate examine whether each names are masked by the
namespace, to which they belong.
Pierre-Yves David - Feb. 3, 2015, 4:05 p.m.
On 02/03/2015 01:04 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1422968239 -32400
> #      Tue Feb 03 21:57:19 2015 +0900
> # Branch stable
> # Node ID 244d92671cebd0b600a192f1c896b4ba598621dd
> # Parent  147878ac1d02298847d5b2a0d2e06063b2fefe91
> revset: mask specific names for named() predicate
>
> Before this patch, revset predicate "tags()" and "named('tags')"
> differ from each other, because the former doesn't include "tip" but
> the latter does.
>
> For equivalence, "named('tags')" shouldn't include the revision
> corresponded to "tip". But just removing "tip" from the "tags"
> namespace may cause unexpected failure of looking "tip" tag up in
> other code paths.
>
> To mask specific names ("tip" in this case) for "named()" predicate,
> this patch introduces "revsetmasks" into "namespaces", and makes
> "named()" predicate examine whether each names are masked by the
> namespace, to which they belong.

The code itself seems right. But I'm not sure I want to add addition 
complexity for old legacy stuff. Is the presence of "tip" here a real 
issue. Or should "tip| really be in that set at all ?? We are also 
adding MQ stuff in the "tag" namespace. This is probably the right time 
to clean this whole mess for the namespace version (`hg tag` is already 
doomed).

So, lets change the definition of "tags" as registered as a namespaces 
to be only tags added with `hg tags` (maybe even distinct global and local)

(this is a patch rejection)

Patch

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -41,7 +41,8 @@  class namespaces(object):
                       # i18n: column positioning for "hg log"
                       logfmt=_("tag:         %s\n"),
                       listnames=tagnames,
-                      namemap=tagnamemap, nodemap=tagnodemap)
+                      namemap=tagnamemap, nodemap=tagnodemap,
+                      revsetmasks=set(['tip']))
         self.addnamespace(n)
 
         bnames = lambda repo: repo.branchmap().keys()
@@ -126,11 +127,13 @@  class namespace(object):
                    dictionary)
       'namemap': function that takes a name and returns a list of nodes
       'nodemap': function that takes a node and returns a list of names
+      'revsetmasks': set of names to be masked for revset predicate "named()"
 
     """
 
     def __init__(self, name, templatename=None, logname=None, colorname=None,
-                 logfmt=None, listnames=None, namemap=None, nodemap=None):
+                 logfmt=None, listnames=None, namemap=None, nodemap=None,
+                 revsetmasks=None):
         """create a namespace
 
         name: the namespace to be registered (in plural form)
@@ -144,6 +147,7 @@  class namespace(object):
         listnames: function to list all names
         namemap: function that inputs a node, output name(s)
         nodemap: function that inputs a name, output node(s)
+        revsetmasks: set of names to be masked for revset predicate "named()"
 
         """
         self.name = name
@@ -168,6 +172,11 @@  class namespace(object):
             # i18n: column positioning for "hg log"
             self.logfmt = ("%s:" % self.logname).ljust(13) + "%s\n"
 
+        if revsetmasks is None:
+            self.revsetmasks = set()
+        else:
+            self.revsetmasks = revsetmasks
+
     def names(self, repo, node):
         """method that returns a (sorted) list of names in a namespace that
         match a given node"""
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1277,7 +1277,8 @@  def named(repo, subset, x):
     names = set()
     for ns in namespaces:
         for name in ns.listnames(repo):
-            names.update(repo[n].rev() for n in ns.nodes(repo, name))
+            if name not in ns.revsetmasks:
+                names.update(repo[n].rev() for n in ns.nodes(repo, name))
 
     names -= set([node.nullrev])
     return subset & names
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -791,7 +791,6 @@  we can use patterns when searching for t
   6
   $ log 'named("tags")'
   6
-  9
 
 issue2437