Patchwork [4,of,4,nullrev] revset: extend fullreposet to make "null" revision magically appears in set

login
register
mail settings
Submitter Yuya Nishihara
Date March 4, 2015, 3:19 p.m.
Message ID <f1c8cea08e6ae9d2e367.1425482376@mimosa>
Download mbox | patch
Permalink /patch/7901/
State Accepted
Headers show

Comments

Yuya Nishihara - March 4, 2015, 3:19 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1420725945 -32400
#      Thu Jan 08 23:05:45 2015 +0900
# Node ID f1c8cea08e6ae9d2e367fd65fee184c04e4932d9
# Parent  617bcddf3f7f7ec2f4589de35b4f80f211d08f2e
revset: extend fullreposet to make "null" revision magically appears in set

As per fullreposet.__and__, it can omit the range check of rev.  Therefore,
"null" revision is accepted automagically.

It seems this can fix many query results involving null symbol.  Originally,
the simplest "(null)" query did fail if there were hidden revisions.  Tests
are randomly chosen.

fullreposet mimics the behavior of localrepo, where "null" revision is not
listed but contained.
Matt Mackall - March 4, 2015, 8:16 p.m.
On Thu, 2015-03-05 at 00:19 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1420725945 -32400
> #      Thu Jan 08 23:05:45 2015 +0900
> # Node ID f1c8cea08e6ae9d2e367fd65fee184c04e4932d9
> # Parent  617bcddf3f7f7ec2f4589de35b4f80f211d08f2e
> revset: extend fullreposet to make "null" revision magically appears in set

These are queued for default, thanks!

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -323,8 +323,6 @@  def _getrevsource(repo, r):
 
 def stringset(repo, subset, x):
     x = repo[x].rev()
-    if x == -1 and len(subset) == len(repo):
-        return baseset([-1])
     if x in subset:
         return baseset([x])
     return baseset()
@@ -3312,16 +3310,17 @@  class spanset(abstractsmartset):
 class fullreposet(spanset):
     """a set containing all revisions in the repo
 
-    This class exists to host special optimization.
+    This class exists to host special optimization and magic to handle virtual
+    revisions such as "null".
     """
 
     def __init__(self, repo):
         super(fullreposet, self).__init__(repo)
 
     def __contains__(self, rev):
+        # assumes the given rev is valid
         hidden = self._hiddenrevs
-        return ((self._start <= rev < self._end)
-                and not (hidden and rev in hidden))
+        return not (hidden and rev in hidden)
 
     def __and__(self, other):
         """As self contains the whole repo, all of the other set should also be
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -187,6 +187,8 @@  check that various commands work well wi
   [255]
   $ hg debugrevspec 'rev(6)'
   $ hg debugrevspec 'rev(4)'
+  $ hg debugrevspec 'null'
+  -1
 
 Check that public changeset are not accounted as obsolete:
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -478,8 +478,33 @@  Test explicit numeric revision
   [255]
 
 Test null revision
+  $ log '(null)'
+  -1
+  $ log '(null:0)'
+  -1
+  0
+  $ log '(0:null)'
+  0
+  -1
+  $ log 'null::0'
+  -1
+  0
+  $ log 'null:tip - 0:'
+  -1
+  $ log 'null: and null::' | head -1
+  -1
+  $ log 'null: or 0:' | head -2
+  -1
+  0
   $ log 'ancestors(null)'
   -1
+  $ log 'reverse(null:)' | tail -2
+  0
+  -1
+  $ log 'first(null:)'
+  -1
+  $ log 'min(null:)'
+  -1
   $ log 'tip:null and all()' | tail -2
   1
   0