Patchwork [1,of,3,RFC,V3] revset: add wdir() function to specify workingctx revision by command

login
register
mail settings
Submitter Yuya Nishihara
Date March 19, 2015, 4:23 p.m.
Message ID <ac80716bb799448df018.1426782192@mimosa>
Download mbox | patch
Permalink /patch/8165/
State Accepted
Commit 0e41f110e69efad849c1eb82a0a887106d21e853
Headers show

Comments

Yuya Nishihara - March 19, 2015, 4:23 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1408164256 -32400
#      Sat Aug 16 13:44:16 2014 +0900
# Node ID ac80716bb799448df0181f5a3169b7242bdf8400
# Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
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.
Matt Harbison - March 20, 2015, 3:43 a.m.
On Thu, 19 Mar 2015 12:23:12 -0400, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1408164256 -32400
> #      Sat Aug 16 13:44:16 2014 +0900
> # Node ID ac80716bb799448df0181f5a3169b7242bdf8400
> # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
> revset: add wdir() function to specify workingctx revision by command

I like this.  I've wanted to see the uncommitted changes in the thg file  
history more than once.

> List of commands that will potentially support workingctx revision:
>
>   command   default  remarks
>   --------  -------   
> -----------------------------------------------------
>   annotate  p1       useful
>   archive   p1       might be useful

Could be useful on Windows to get a tree copy that excludes the .hg dir,  
and/or in the non zip formats without a 3rd party utility being installed.

>   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

Useful on Windows (built in 'find' is not nearly as useful).

>   identify  wdir     (default)
>   locate    wdir     (default)
>   log       tip:0    might be useful with -p or -G option
>   parents   wdir     (default)
>   status    wdir     (default)

Based on this table, largefiles will need some fixes to support archive  
and cat (assuming annotate, diff, export and grep aren't useful on a  
largefile), but that doesn't look too complicated.

Not a blocker to adding this revset, but do you have any thoughts on how  
to get the workingctx in a subrepo?  (Consider something like 'hg cat -r  
wdir() subrepo/file.txt'.)  I was hoping for something that didn't require  
extra work for each command, but the above list isn't too long, so maybe  
command specific support is OK.

I wish there was a 1 char symbol too, but 'wdir()' seems fine to me given  
how scarce they are.  Is '_' the only symbol left (that won't cause shell  
problems)?

--Matt
Yuya Nishihara - March 20, 2015, 2:11 p.m.
On Thu, 19 Mar 2015 23:43:46 -0400, Matt Harbison wrote:
> On Thu, 19 Mar 2015 12:23:12 -0400, Yuya Nishihara <yuya@tcha.org> wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1408164256 -32400
> > #      Sat Aug 16 13:44:16 2014 +0900
> > # Node ID ac80716bb799448df0181f5a3169b7242bdf8400
> > # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
> > revset: add wdir() function to specify workingctx revision by command
> 
> I like this.  I've wanted to see the uncommitted changes in the thg file  
> history more than once.
> 
> > List of commands that will potentially support workingctx revision:
> >
> >   command   default  remarks
> >   --------  -------   
> > -----------------------------------------------------
> >   annotate  p1       useful
> >   archive   p1       might be useful
> 
> Could be useful on Windows to get a tree copy that excludes the .hg dir,  
> and/or in the non zip formats without a 3rd party utility being installed.
> 
> >   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
> 
> Useful on Windows (built in 'find' is not nearly as useful).
> 
> >   identify  wdir     (default)
> >   locate    wdir     (default)
> >   log       tip:0    might be useful with -p or -G option
> >   parents   wdir     (default)
> >   status    wdir     (default)
> 
> Based on this table, largefiles will need some fixes to support archive
> and cat (assuming annotate, diff, export and grep aren't useful on a
> largefile), but that doesn't look too complicated.

Good point.

> Not a blocker to adding this revset, but do you have any thoughts on how  
> to get the workingctx in a subrepo?  (Consider something like 'hg cat -r  
> wdir() subrepo/file.txt'.)

I don't have good idea. changectx could have a different function that returns
a subrepo at ctx.subrev(), but only workingctx needs such distinction.

  ctx.wsub(path) -> subrepo at substate[1]
  wctx.wsub(path) -> subrepo at None

> I wish there was a 1 char symbol too, but 'wdir()' seems fine to me given
> how scarce they are.  Is '_' the only symbol left (that won't cause shell
> problems)?

I've proposed a nullary operator '+' before, but it's too magical.

Regards,
Matt Harbison - March 21, 2015, 12:11 a.m.
On Fri, 20 Mar 2015 10:11:53 -0400, Yuya Nishihara <yuya@tcha.org> wrote:

> On Thu, 19 Mar 2015 23:43:46 -0400, Matt Harbison wrote:
>> On Thu, 19 Mar 2015 12:23:12 -0400, Yuya Nishihara <yuya@tcha.org>  
>> wrote:
>> > # HG changeset patch
>> > # User Yuya Nishihara <yuya@tcha.org>
>> > # Date 1408164256 -32400
>> > #      Sat Aug 16 13:44:16 2014 +0900
>> > # Node ID ac80716bb799448df0181f5a3169b7242bdf8400
>> > # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
>> > revset: add wdir() function to specify workingctx revision by command
>>
>> I like this.  I've wanted to see the uncommitted changes in the thg file
>> history more than once.
>>
>> > List of commands that will potentially support workingctx revision:
>> >
>> >   command   default  remarks
>> >   --------  -------
>> > -----------------------------------------------------
>> >   annotate  p1       useful
>> >   archive   p1       might be useful
>>
>> Could be useful on Windows to get a tree copy that excludes the .hg dir,
>> and/or in the non zip formats without a 3rd party utility being  
>> installed.
>>
>> >   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
>>
>> Useful on Windows (built in 'find' is not nearly as useful).
>>
>> >   identify  wdir     (default)
>> >   locate    wdir     (default)
>> >   log       tip:0    might be useful with -p or -G option
>> >   parents   wdir     (default)
>> >   status    wdir     (default)
>>
>> Based on this table, largefiles will need some fixes to support archive
>> and cat (assuming annotate, diff, export and grep aren't useful on a
>> largefile), but that doesn't look too complicated.
>
> Good point.
>
>> Not a blocker to adding this revset, but do you have any thoughts on how
>> to get the workingctx in a subrepo?  (Consider something like 'hg cat -r
>> wdir() subrepo/file.txt'.)
>
> I don't have good idea. changectx could have a different function that  
> returns
> a subrepo at ctx.subrev(), but only workingctx needs such distinction.
>
>   ctx.wsub(path) -> subrepo at substate[1]
>   wctx.wsub(path) -> subrepo at None

I'll give this a try.  I was really hoping to hide it inside  
subrepo.subrepo(), but this might be an easier transition.

>> I wish there was a 1 char symbol too, but 'wdir()' seems fine to me  
>> given
>> how scarce they are.  Is '_' the only symbol left (that won't cause  
>> shell
>> problems)?
>
> I've proposed a nullary operator '+' before, but it's too magical.

FWIW, it doesn't seem magical to me.  It seems fairly reasonable given  
that 'hg identify' prints a '+' when there are changes to the working  
directory.  No changes basically implies '.' instead of the working  
directory anyway.  Granted, identify probably isn't used daily, and may  
therefore be one of the more obscure commands.

--Matt
Matt Mackall - March 23, 2015, 7:52 p.m.
On Fri, 2015-03-20 at 20:11 -0400, Matt Harbison wrote:
> On Fri, 20 Mar 2015 10:11:53 -0400, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> > On Thu, 19 Mar 2015 23:43:46 -0400, Matt Harbison wrote:
> >> On Thu, 19 Mar 2015 12:23:12 -0400, Yuya Nishihara <yuya@tcha.org>  
> >> wrote:
> >> > # HG changeset patch
> >> > # User Yuya Nishihara <yuya@tcha.org>
> >> > # Date 1408164256 -32400
> >> > #      Sat Aug 16 13:44:16 2014 +0900
> >> > # Node ID ac80716bb799448df0181f5a3169b7242bdf8400
> >> > # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
> >> > revset: add wdir() function to specify workingctx revision by command
> >>
> >> I like this.  I've wanted to see the uncommitted changes in the thg file
> >> history more than once.
> >>
> >> > List of commands that will potentially support workingctx revision:
> >> >
> >> >   command   default  remarks
> >> >   --------  -------
> >> > -----------------------------------------------------
> >> >   annotate  p1       useful
> >> >   archive   p1       might be useful
> >>
> >> Could be useful on Windows to get a tree copy that excludes the .hg dir,
> >> and/or in the non zip formats without a 3rd party utility being  
> >> installed.
> >>
> >> >   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
> >>
> >> Useful on Windows (built in 'find' is not nearly as useful).
> >>
> >> >   identify  wdir     (default)
> >> >   locate    wdir     (default)
> >> >   log       tip:0    might be useful with -p or -G option
> >> >   parents   wdir     (default)
> >> >   status    wdir     (default)
> >>
> >> Based on this table, largefiles will need some fixes to support archive
> >> and cat (assuming annotate, diff, export and grep aren't useful on a
> >> largefile), but that doesn't look too complicated.
> >
> > Good point.
> >
> >> Not a blocker to adding this revset, but do you have any thoughts on how
> >> to get the workingctx in a subrepo?  (Consider something like 'hg cat -r
> >> wdir() subrepo/file.txt'.)
> >
> > I don't have good idea. changectx could have a different function that  
> > returns
> > a subrepo at ctx.subrev(), but only workingctx needs such distinction.
> >
> >   ctx.wsub(path) -> subrepo at substate[1]
> >   wctx.wsub(path) -> subrepo at None
> 
> I'll give this a try.  I was really hoping to hide it inside  
> subrepo.subrepo(), but this might be an easier transition.
> 
> >> I wish there was a 1 char symbol too, but 'wdir()' seems fine to me  
> >> given
> >> how scarce they are.  Is '_' the only symbol left (that won't cause  
> >> shell
> >> problems)?
> >
> > I've proposed a nullary operator '+' before, but it's too magical.
> 
> FWIW, it doesn't seem magical to me.  It seems fairly reasonable given  
> that 'hg identify' prints a '+' when there are changes to the working  
> directory. 

It'd be great.. if "+" wasn't already a revset operator. As it is, I
don't see any sane way to use it. Consider the revset "++.-@^%" and tell
me if you really want to go there.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1852,6 +1852,16 @@  def user(repo, subset, x):
     """
     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 @@  symbols = {
     "tagged": tagged,
     "user": user,
     "unstable": unstable,
+    "wdir": wdir,
     "_list": _list,
     "_intlist": _intlist,
     "_hexlist": _hexlist,
@@ -2019,6 +2030,7 @@  safesymbols = set([
     "tagged",
     "user",
     "unstable",
+    "wdir",
     "_list",
     "_intlist",
     "_hexlist",
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -509,6 +509,14 @@  Test null revision
   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
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -240,6 +240,17 @@  Check 'status -q' and some combinations
   $ 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