Patchwork [4,of,5] revset: use integer representation of wdir() in revset

login
register
mail settings
Submitter Yuya Nishihara
Date July 9, 2015, 2:42 p.m.
Message ID <152dec0b10b0e6505866.1436452972@mimosa>
Download mbox | patch
Permalink /patch/9935/
State Accepted
Headers show

Comments

Yuya Nishihara - July 9, 2015, 2:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1426490226 -32400
#      Mon Mar 16 16:17:06 2015 +0900
# Node ID 152dec0b10b0e6505866b94a389db40f96fc7d16
# Parent  3002f049bad78c12323dc78c862c6771fb7f511e
revset: use integer representation of wdir() in revset

This is the simplest way to handle wdir() revision in revset. None didn't
work well because revset heavily depends on integer operations such as min(),
max(), sorted(), x:y, etc.

One downside is that we cannot do "wctx.rev() in set" because wctx.rev() is
still None. We could wrap the result set by wdirproxyset that translates None
to wdirrev, but it seems overengineered at this point.

    result = getset(repo, subset, tree)
    if 'wdir' in funcsused(tree):
        result = wdirproxyset(result)

Test cases need the '(all() + wdir()) &' hack because we have yet to fix the
bootstrapping issue of null and wdir.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1481,7 +1481,7 @@  def parents(repo, subset, x):
         up = ps.update
         parentrevs = cl.parentrevs
         for r in getset(repo, fullreposet(repo), x):
-            if r is None:
+            if r == node.wdirrev:
                 up(p.rev() for p in repo[r].parents())
             else:
                 up(parentrevs(r))
@@ -1986,8 +1986,8 @@  def user(repo, subset, x):
 def wdir(repo, subset, x):
     # i18n: "wdir" is a keyword
     getargs(x, 0, 0, _("wdir takes no arguments"))
-    if None in subset or isinstance(subset, fullreposet):
-        return baseset([None])
+    if node.wdirrev in subset or isinstance(subset, fullreposet):
+        return baseset([node.wdirrev])
     return baseset()
 
 # for internal use
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -2392,4 +2392,12 @@  should not draw line down to null due to
      summary:     add a
   
 
+working-directory revision
+
+  $ hg log -G -qr '. + wdir()'
+  o  2147483647:ffffffffffff
+  |
+  @  3:5918b8d165d1
+  |
+
   $ cd ..
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -721,11 +721,19 @@  BROKEN: should be '-1'
 
 Test working-directory revision
   $ hg debugrevspec 'wdir()'
-  None
+  2147483647
   $ hg debugrevspec 'tip or wdir()'
   9
-  None
+  2147483647
   $ hg debugrevspec '0:tip and wdir()'
+  $ log '(all() + wdir()) & min(. + wdir())'
+  9
+  $ log '(all() + wdir()) & max(. + wdir())'
+  2147483647
+  $ log '(all() + wdir()) & first(wdir() + .)'
+  2147483647
+  $ log '(all() + wdir()) & last(. + wdir())'
+  2147483647
 
   $ log 'outgoing()'
   8