Patchwork [2,of,2] shelve: allow --patch and --stat without --list when dealing with a single shelf

login
register
mail settings
Submitter Tony Tung
Date May 15, 2015, 4:43 a.m.
Message ID <aa5ee59328fcd86628f5.1431665016@andromeda.local>
Download mbox | patch
Permalink /patch/9086/
State Accepted
Headers show

Comments

Tony Tung - May 15, 2015, 4:43 a.m.
# HG changeset patch
# User Tony Tung <tonytung@fb.com>
# Date 1429043034 14400
#      Tue Apr 14 16:23:54 2015 -0400
# Node ID aa5ee59328fcd86628f5d0b2f23cf5cef239b85f
# Parent  78db3bff2fcfdaeb2e50f979454e59e707f26427
shelve: allow --patch and --stat without --list when dealing with a single shelf

It's annoying having to specify --list and --patch/--stat when all you
really want to do is to dump a patch.  This creates an explicit
--patch/--stat command that is executed if --list is not specified.  It
ensures that 1) there is only one shelf name specified and 2) that the
shelf exists.  Then it redirects to the original listcmd code.
Pierre-Yves David - May 15, 2015, 8:03 a.m.
On 05/14/2015 09:43 PM, Tony Tung wrote:
> # HG changeset patch
> # User Tony Tung <tonytung@fb.com>
> # Date 1429043034 14400
> #      Tue Apr 14 16:23:54 2015 -0400
> # Node ID aa5ee59328fcd86628f5d0b2f23cf5cef239b85f
> # Parent  78db3bff2fcfdaeb2e50f979454e59e707f26427
> shelve: allow --patch and --stat without --list when dealing with a single shelf
>
> It's annoying having to specify --list and --patch/--stat when all you
> really want to do is to dump a patch.  This creates an explicit
> --patch/--stat command that is executed if --list is not specified.  It
> ensures that 1) there is only one shelf name specified and 2) that the
> shelf exists.  Then it redirects to the original listcmd code.

These two looks great to me. Thanks

They are now pushed to the clowncopter.
Sean Farley - May 15, 2015, 4:58 p.m.
Tony Tung <tonytung@fb.com> writes:

> # HG changeset patch
> # User Tony Tung <tonytung@fb.com>
> # Date 1429043034 14400
> #      Tue Apr 14 16:23:54 2015 -0400
> # Node ID aa5ee59328fcd86628f5d0b2f23cf5cef239b85f
> # Parent  78db3bff2fcfdaeb2e50f979454e59e707f26427
> shelve: allow --patch and --stat without --list when dealing with a single shelf
>
> It's annoying having to specify --list and --patch/--stat when all you
> really want to do is to dump a patch.  This creates an explicit
> --patch/--stat command that is executed if --list is not specified.  It
> ensures that 1) there is only one shelf name specified and 2) that the
> shelf exists.  Then it redirects to the original listcmd code.

Awesome! Been meaning to look into that, thanks for doing it :-)

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -363,6 +363,17 @@ 
         finally:
             fp.close()
 
+def singlepatchcmds(ui, repo, pats, opts, subcommand):
+    """subcommand that displays a single shelf"""
+    if len(pats) != 1:
+        raise util.Abort(_("--%s expects a single shelf") % subcommand)
+    shelfname = pats[0]
+
+    if not shelvedfile(repo, shelfname, 'patch').exists():
+        raise util.Abort(_("cannot find shelf %s") % shelfname)
+
+    listcmd(ui, repo, pats, opts)
+
 def checkparents(repo, state):
     """check parent while resuming an unshelve"""
     if state.parents != repo.dirstate.parents():
@@ -701,8 +712,8 @@ 
         ('list', set(['list'])),
         ('message', set(['create'])),
         ('name', set(['create'])),
-        ('patch', set(['list'])),
-        ('stat', set(['list'])),
+        ('patch', set(['patch', 'list'])),
+        ('stat', set(['stat', 'list'])),
     ]
     def checkopt(opt):
         if opts[opt]:
@@ -719,11 +730,11 @@ 
         return deletecmd(ui, repo, pats)
     elif checkopt('list'):
         return listcmd(ui, repo, pats, opts)
+    elif checkopt('patch'):
+        return singlepatchcmds(ui, repo, pats, opts, subcommand='patch')
+    elif checkopt('stat'):
+        return singlepatchcmds(ui, repo, pats, opts, subcommand='stat')
     else:
-        for i in ('patch', 'stat'):
-            if opts[i]:
-                raise util.Abort(_("option '--%s' may not be "
-                                   "used when shelving a change") % (i,))
         return createcmd(ui, repo, pats, opts)
 
 def extsetup(ui):
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -862,4 +862,45 @@ 
   c
   x
   x
-  $ cd ..
+
+shelve --patch and shelve --stat should work with a single valid shelfname
+
+  $ hg up --clean .
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg shelve --list
+  $ echo 'patch a' > shelf-patch-a
+  $ hg add shelf-patch-a
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo 'patch b' > shelf-patch-b
+  $ hg add shelf-patch-b
+  $ hg shelve
+  shelved as default-01
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg shelve --patch default default-01
+  abort: --patch expects a single shelf
+  [255]
+  $ hg shelve --stat default default-01
+  abort: --stat expects a single shelf
+  [255]
+  $ hg shelve --patch default
+  default         (* ago)    changes to 'create conflict' (glob)
+  
+  diff --git a/shelf-patch-a b/shelf-patch-a
+  new file mode 100644
+  --- /dev/null
+  +++ b/shelf-patch-a
+  @@ -0,0 +1,1 @@
+  +patch a
+  $ hg shelve --stat default
+  default         (* ago)    changes to 'create conflict' (glob)
+   shelf-patch-a |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  $ hg shelve --patch nonexistentshelf
+  abort: cannot find shelf nonexistentshelf
+  [255]
+  $ hg shelve --stat nonexistentshelf
+  abort: cannot find shelf nonexistentshelf
+  [255]
+