Patchwork shelve: allow multiple shelves with --patch and --stat

login
register
mail settings
Submitter Pulkit Goyal
Date Jan. 13, 2017, 7:57 p.m.
Message ID <9dc4d056d85a041b2b28.1484337433@pulkit-goyal>
Download mbox | patch
Permalink /patch/18213/
State Superseded
Headers show

Comments

Pulkit Goyal - Jan. 13, 2017, 7:57 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1484337187 -19800
#      Sat Jan 14 01:23:07 2017 +0530
# Node ID 9dc4d056d85a041b2b28587b3b84608b1f0903a5
# Parent  e9bc34f57537249115de4de5c0990365ef65298e
shelve: allow multiple shelves with --patch and --stat

Before this patch, there was a single way to see multiple shelves using
`--patch --list` which show all the shelves. Doing `--patch s1 s2` returns an
error. This patch allows to show multiple shelves using `--patch` and `--stat`.
Anton Shestakov - Jan. 14, 2017, 6:09 a.m.
On Sat, 14 Jan 2017 01:27:13 +0530
Pulkit Goyal <7895pulkit@gmail.com> wrote:

> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1484337187 -19800
> #      Sat Jan 14 01:23:07 2017 +0530
> # Node ID 9dc4d056d85a041b2b28587b3b84608b1f0903a5
> # Parent  e9bc34f57537249115de4de5c0990365ef65298e
> shelve: allow multiple shelves with --patch and --stat
> 
> Before this patch, there was a single way to see multiple shelves using
> `--patch --list` which show all the shelves. Doing `--patch s1 s2` returns an
> error. This patch allows to show multiple shelves using `--patch` and `--stat`.

Sure...

> diff -r e9bc34f57537 -r 9dc4d056d85a hgext/shelve.py
> --- a/hgext/shelve.py	Sun Jan 08 10:08:29 2017 +0800
> +++ b/hgext/shelve.py	Sat Jan 14 01:23:07 2017 +0530
> @@ -523,13 +523,13 @@
>                      ui.write(chunk, label=label)
>  
>  def singlepatchcmds(ui, repo, pats, opts, subcommand):

...but then it's not about "single patch" anymore.

> -    """subcommand that displays a single shelf"""
> -    if len(pats) != 1:
> -        raise error.Abort(_("--%s expects a single shelf") % subcommand)
> -    shelfname = pats[0]
> +    """subcommand that displays shelves"""
> +    if len(pats) == 0:
> +        raise error.Abort(_("--%s expects atleast one shelf") % subcommand)

"At least."
Pulkit Goyal - Jan. 15, 2017, 6:58 p.m.
>> diff -r e9bc34f57537 -r 9dc4d056d85a hgext/shelve.py
>> --- a/hgext/shelve.py Sun Jan 08 10:08:29 2017 +0800
>> +++ b/hgext/shelve.py Sat Jan 14 01:23:07 2017 +0530
>> @@ -523,13 +523,13 @@
>>                      ui.write(chunk, label=label)
>>
>>  def singlepatchcmds(ui, repo, pats, opts, subcommand):
>
> ...but then it's not about "single patch" anymore.

Yeah but I was afraid that this function might be used anywehere else.
Though `grep` tells me that it's not but I tried to be on safe side.
>
>> -    """subcommand that displays a single shelf"""
>> -    if len(pats) != 1:
>> -        raise error.Abort(_("--%s expects a single shelf") % subcommand)
>> -    shelfname = pats[0]
>> +    """subcommand that displays shelves"""
>> +    if len(pats) == 0:
>> +        raise error.Abort(_("--%s expects atleast one shelf") % subcommand)
>
> "At least."

I will send a V2 if there are no more problems in this.
Augie Fackler - Jan. 15, 2017, 10:40 p.m.
> On Jan 15, 2017, at 1:58 PM, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> 
>>> diff -r e9bc34f57537 -r 9dc4d056d85a hgext/shelve.py
>>> --- a/hgext/shelve.py Sun Jan 08 10:08:29 2017 +0800
>>> +++ b/hgext/shelve.py Sat Jan 14 01:23:07 2017 +0530
>>> @@ -523,13 +523,13 @@
>>>                     ui.write(chunk, label=label)
>>> 
>>> def singlepatchcmds(ui, repo, pats, opts, subcommand):
>> 
>> ...but then it's not about "single patch" anymore.
> 
> Yeah but I was afraid that this function might be used anywehere else.
> Though `grep` tells me that it's not but I tried to be on safe side.
>> 
>>> -    """subcommand that displays a single shelf"""
>>> -    if len(pats) != 1:
>>> -        raise error.Abort(_("--%s expects a single shelf") % subcommand)
>>> -    shelfname = pats[0]
>>> +    """subcommand that displays shelves"""
>>> +    if len(pats) == 0:
>>> +        raise error.Abort(_("--%s expects atleast one shelf") % subcommand)
>> 
>> "At least."
> 
> I will send a V2 if there are no more problems in this.

I’d go ahead and send v2.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r e9bc34f57537 -r 9dc4d056d85a hgext/shelve.py
--- a/hgext/shelve.py	Sun Jan 08 10:08:29 2017 +0800
+++ b/hgext/shelve.py	Sat Jan 14 01:23:07 2017 +0530
@@ -523,13 +523,13 @@ 
                     ui.write(chunk, label=label)
 
 def singlepatchcmds(ui, repo, pats, opts, subcommand):
-    """subcommand that displays a single shelf"""
-    if len(pats) != 1:
-        raise error.Abort(_("--%s expects a single shelf") % subcommand)
-    shelfname = pats[0]
+    """subcommand that displays shelves"""
+    if len(pats) == 0:
+        raise error.Abort(_("--%s expects atleast one shelf") % subcommand)
 
-    if not shelvedfile(repo, shelfname, patchextension).exists():
-        raise error.Abort(_("cannot find shelf %s") % shelfname)
+    for shelfname in pats:
+        if not shelvedfile(repo, shelfname, patchextension).exists():
+            raise error.Abort(_("cannot find shelf %s") % shelfname)
 
     listcmd(ui, repo, pats, opts)
 
diff -r e9bc34f57537 -r 9dc4d056d85a tests/test-shelve.t
--- a/tests/test-shelve.t	Sun Jan 08 10:08:29 2017 +0800
+++ b/tests/test-shelve.t	Sat Jan 14 01:23:07 2017 +0530
@@ -991,7 +991,7 @@ 
   x
   x
 
-shelve --patch and shelve --stat should work with a single valid shelfname
+shelve --patch and shelve --stat should work with valid shelfnames
 
   $ hg up --clean .
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -1008,11 +1008,29 @@ 
   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]
+  default-01      (1s ago)    changes to: create conflict
+  
+  diff --git a/shelf-patch-b b/shelf-patch-b
+  new file mode 100644
+  --- /dev/null
+  +++ b/shelf-patch-b
+  @@ -0,0 +1,1 @@
+  +patch b
+  default         (1s ago)    changes to: create conflict
+  
+  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-01
-  abort: --stat expects a single shelf
-  [255]
+  default-01      (1s ago)    changes to: create conflict
+   shelf-patch-b |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  default         (1s ago)    changes to: create conflict
+   shelf-patch-a |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
   $ hg shelve --patch default
   default         (*)* changes to: create conflict (glob)
   
@@ -1032,6 +1050,12 @@ 
   $ hg shelve --stat nonexistentshelf
   abort: cannot find shelf nonexistentshelf
   [255]
+  $ hg shelve --patch default nonexistentshelf
+  abort: cannot find shelf nonexistentshelf
+  [255]
+  $ hg shelve --patch
+  abort: --patch expects atleast one shelf
+  [255]
 
   $ cd ..