revset: add wdir() function to specify workingctx revision by command
The main purpose of wdir() is to annotate working-directory files.
Currently many commands and revsets cannot handle workingctx and may raise
exception. For example, -r ":wdir()" results in TypeError. This problem will
be addressed by future patches.
We could add "wdir" symbol instead, but it would conflict with the existing
tag, bookmark or branch. So I decided not to.
List of commands that will potentially support workingctx revision:
command default remarks
-------- ------- -----------------------------------------------------
annotate p1 useful
archive p1 might be useful
cat p1 might be useful on Windows (no cat)
diff p1:wdir (default)
export p1 might be useful if wctx can have draft commit message
files wdir (default)
grep tip:0 might be useful
identify wdir (default)
locate wdir (default)
log tip:0 might be useful with -p or -G option
parents wdir (default)
status wdir (default)
This patch includes minimal test of "hg status" that should be able to handle
the workingctx revision.
--- a/mercurial/revset.py Tue Mar 17 13:41:24 2015 -0700
+++ b/mercurial/revset.py Sat Aug 16 13:44:16 2014 +0900
@@ -1852,6 +1852,16 @@
"""
return author(repo, subset, x)
+def wdir(repo, subset, x):
+ """``wdir()``
+ Working directory.
+ """
+ # i18n: "wdir" is a keyword
+ getargs(x, 0, 0, _("wdir takes no arguments"))
+ if None in subset:
+ return baseset([None])
+ return baseset()
+
# for internal use
def _list(repo, subset, x):
s = getstring(x, "internal error")
@@ -1947,6 +1957,7 @@
"tagged": tagged,
"user": user,
"unstable": unstable,
+ "wdir": wdir,
"_list": _list,
"_intlist": _intlist,
"_hexlist": _hexlist,
@@ -2019,6 +2030,7 @@
"tagged",
"user",
"unstable",
+ "wdir",
"_list",
"_intlist",
"_hexlist",
--- a/tests/test-revset.t Tue Mar 17 13:41:24 2015 -0700
+++ b/tests/test-revset.t Sat Aug 16 13:44:16 2014 +0900
@@ -509,6 +509,14 @@
1
0
+Test working-directory revision
+ $ hg debugrevspec 'wdir()'
+ None
+ $ hg debugrevspec 'tip or wdir()'
+ 9
+ None
+ $ hg debugrevspec '0:tip and wdir()'
+
$ log 'outgoing()'
8
9
--- a/tests/test-status.t Tue Mar 17 13:41:24 2015 -0700
+++ b/tests/test-status.t Sat Aug 16 13:44:16 2014 +0900
@@ -240,6 +240,17 @@
$ rm deleted
$ hg copy modified copied
+Specify working directory revision explicitly, that should be the same as
+"hg status"
+
+ $ hg status --change "wdir()"
+ M modified
+ A added
+ A copied
+ R removed
+ ! deleted
+ ? unknown
+
Run status with 2 different flags.
Check if result is the same or different.
If result is not as expected, raise error