Patchwork [stable] rebase: empty revset should be a gentle no-op with exit code 1, not an error

login
register
mail settings
Submitter Mads Kiilerich
Date May 1, 2014, 3 p.m.
Message ID <1b9a7c7221b195d8ebcb.1398956452@mk-desktop>
Download mbox | patch
Permalink /patch/4462/
State Accepted
Commit 799c494189a9db994cd6ce7fd924e9825b3fe425
Headers show

Comments

Mads Kiilerich - May 1, 2014, 3 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1398955670 -7200
#      Thu May 01 16:47:50 2014 +0200
# Branch stable
# Node ID 1b9a7c7221b195d8ebcb8632dcb4ea571a6f1676
# Parent  e2031c8ca4f8939a21fea454cb64b7a2744d9c8d
rebase: empty revset should be a gentle no-op with exit code 1, not an error
Matt Mackall - May 1, 2014, 3:48 p.m.
On Thu, 2014-05-01 at 17:00 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1398955670 -7200
> #      Thu May 01 16:47:50 2014 +0200
> # Branch stable
> # Node ID 1b9a7c7221b195d8ebcb8632dcb4ea571a6f1676
> # Parent  e2031c8ca4f8939a21fea454cb64b7a2744d9c8d
> rebase: empty revset should be a gentle no-op with exit code 1, not an error

Queued for stable, thanks.
Jordi GutiƩrrez Hermoso - May 1, 2014, 4:17 p.m.
On Thu, 2014-05-01 at 17:00 +0200, Mads Kiilerich wrote:

> rebase: empty revset should be a gentle no-op with exit code 1, not
> an error

Out of curiousity, what is the difference between these two? I ask
because I've been wondering what to do when similar error conditions
occur with hg fold in Evolve.

- Jordi G. H.
Matt Mackall - May 1, 2014, 4:30 p.m.
On Thu, 2014-05-01 at 12:17 -0400, Jordi GutiƩrrez Hermoso wrote:
> On Thu, 2014-05-01 at 17:00 +0200, Mads Kiilerich wrote:
> 
> > rebase: empty revset should be a gentle no-op with exit code 1, not
> > an error
> 
> Out of curiousity, what is the difference between these two? I ask
> because I've been wondering what to do when similar error conditions
> occur with hg fold in Evolve.

Aborts raise an exit code of 255, which is not the documented exit code
for "nothing to rebase".

A small digression here: lots of people think of Unix exit codes as
error codes, but there is a >40 year history of standard Unix tools
returning non-zero exit codes for non-error conditions. For instance,
the grep manpage says:

EXIT STATUS
       The exit status is 0 if selected lines are found, and 1 if  not  found.
       If an error occurred the exit status is 2.  (Note: POSIX error handling
       code should check for '2' or greater.)

We also see here the pattern of "indicate no results via non-zero exit
code". We copy this pattern in a bunch of places (though perhaps not
enough!).

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -228,15 +228,17 @@  def rebase(ui, repo, **opts):
             elif srcf:
                 src = scmutil.revrange(repo, [srcf])
                 if not src:
-                    raise util.Abort(_('empty "source" revision set - '
-                                       'nothing to rebase'))
+                    ui.status(_('empty "source" revision set - '
+                                'nothing to rebase\n'))
+                    return 1
                 rebaseset = repo.revs('(%ld)::', src)
                 assert rebaseset
             else:
                 base = scmutil.revrange(repo, [basef or '.'])
                 if not base:
-                    raise util.Abort(_('empty "base" revision set - '
-                                       "can't compute rebase set"))
+                    ui.status(_('empty "base" revision set - '
+                                "can't compute rebase set\n"))
+                    return 1
                 rebaseset = repo.revs(
                     '(children(ancestor(%ld, %d)) and ::(%ld))::',
                     base, dest, base)
diff --git a/tests/test-rebase-parameters.t b/tests/test-rebase-parameters.t
--- a/tests/test-rebase-parameters.t
+++ b/tests/test-rebase-parameters.t
@@ -84,12 +84,12 @@  These fail:
   [1]
 
   $ hg rebase --source '1 & !1'
-  abort: empty "source" revision set - nothing to rebase
-  [255]
+  empty "source" revision set - nothing to rebase
+  [1]
 
   $ hg rebase --base '1 & !1'
-  abort: empty "base" revision set - can't compute rebase set
-  [255]
+  empty "base" revision set - can't compute rebase set
+  [1]
 
   $ hg rebase
   nothing to rebase - working directory parent is also destination