Patchwork [STABLE,V2] scmutil: abort if an empty revision is given to revpair()

login
register
mail settings
Submitter Matt Harbison
Date Nov. 1, 2015, 6:02 p.m.
Message ID <7e21cf51738b1c2e1797.1446400947@Envy>
Download mbox | patch
Permalink /patch/11256/
State Accepted
Headers show

Comments

Matt Harbison - Nov. 1, 2015, 6:02 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1446342346 14400
#      Sat Oct 31 21:45:46 2015 -0400
# Branch stable
# Node ID 7e21cf51738b1c2e17975ad0adfff836ea973766
# Parent  6474b64045fb83733d6f7b774bbc8b2869bd1fed
scmutil: abort if an empty revision is given to revpair()

When using 'extdiff --patch' to check the changes in a rebase, 'precursors(x)'
evaluated to an empty set because I forgot the --hidden flag, so the other
revision was used as the replacement for the empty set.  The result was the
patch for the other revision was diffed against itself, and the tool saying
there were no differences.  That's misleading since the expected diff args were
silently changed, so it's better to bail out.

The other uses of scmutil.revpair() are commands.diff and commands.status, and
it doesn't make sense to allow an empty revision there either.  The code here
was suggested by Yuya Nishihara.
Matt Mackall - Nov. 1, 2015, 6:22 p.m.
On Sun, 2015-11-01 at 13:02 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1446342346 14400
> #      Sat Oct 31 21:45:46 2015 -0400
> # Branch stable
> # Node ID 7e21cf51738b1c2e17975ad0adfff836ea973766
> # Parent  6474b64045fb83733d6f7b774bbc8b2869bd1fed
> scmutil: abort if an empty revision is given to revpair()

Queued for stable, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -717,6 +717,9 @@ 
 
     if first is None:
         raise error.Abort(_('empty revision range'))
+    if (first == second and len(revs) >= 2
+        and not all(revrange(repo, [r]) for r in revs)):
+        raise error.Abort(_('empty revision on one side of range'))
 
     # if top-level is range expression, the result must always be a pair
     if first == second and len(revs) == 1 and not _pairspec(revs[0]):
diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t
--- a/tests/test-extdiff.t
+++ b/tests/test-extdiff.t
@@ -70,6 +70,12 @@ 
   [1]
 #endif
 
+Specifying an empty revision should abort.
+
+  $ hg extdiff --patch --rev 'ancestor()' --rev 1
+  abort: empty revision on one side of range
+  [255]
+
 Test diff during merge:
 
   $ hg update -C 0