Patchwork commands.push: abort when revisions evaluate to empty set (BC)

login
register
mail settings
Submitter Gregory Szorc
Date March 24, 2015, 1:24 a.m.
Message ID <241336687741af53e422.1427160293@gps-mbp.local>
Download mbox | patch
Permalink /patch/8229/
State Accepted
Commit 69bd0ec2f9be865a95a1e3f2c335d313dab61d15
Headers show

Comments

Gregory Szorc - March 24, 2015, 1:24 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1427160061 25200
#      Mon Mar 23 18:21:01 2015 -0700
# Node ID 241336687741af53e42288e6248f0467058384e3
# Parent  1cfded2fa1a92ee9b55d1f62675569e340a39083
commands.push: abort when revisions evaluate to empty set (BC)

If the "-r" argument is specified to "hg push," the user has expressed
an intent for a specific changeset to be present on the remote. If that
expression cannot be mapped to a known changeset, the user's intent is
ambiguous and cannot be acted upon without making assumptions.

Previously, if arguments to `push -r <rev>` evaluated to an empty set
(perhaps the user specified a revset that didn't evaluate to anything),
the empty "revs" list would be passed down to "exchange.push" where
it appears the empty list was being interpreted as "push everything."

This patch adds validation to the "-r" argument to the push command. If
the argument is specified but doesn't resolve to a changeset, the
command will abort instead of doing something potentially unexpected.

This patch is technically breaking backwards compatibility. I believe
this is justified because the new behavior closes a crack that could
result in undefined or under-defined behavior. Also, this patch doesn't
drop client capabilities because if users really wanted to push all
changesets, they can simply omit the "-r" argument from push completely.
Matt Mackall - March 24, 2015, 2:25 p.m.
On Mon, 2015-03-23 at 18:24 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1427160061 25200
> #      Mon Mar 23 18:21:01 2015 -0700
> # Node ID 241336687741af53e42288e6248f0467058384e3
> # Parent  1cfded2fa1a92ee9b55d1f62675569e340a39083
> commands.push: abort when revisions evaluate to empty set (BC)

Queued for default, thanks.
Pierre-Yves David - March 24, 2015, 11:39 p.m.
On 03/24/2015 07:25 AM, Matt Mackall wrote:
> On Mon, 2015-03-23 at 18:24 -0700, Gregory Szorc wrote:
>> # HG changeset patch
>> # User Gregory Szorc <gregory.szorc@gmail.com>
>> # Date 1427160061 25200
>> #      Mon Mar 23 18:21:01 2015 -0700
>> # Node ID 241336687741af53e42288e6248f0467058384e3
>> # Parent  1cfded2fa1a92ee9b55d1f62675569e340a39083
>> commands.push: abort when revisions evaluate to empty set (BC)
>
> Queued for default, thanks.

I've already instructed people to run "hg push -r null". But I currently 
fail to recall the reason.

I'll try to find out if this was important.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5121,8 +5121,11 @@  def push(ui, repo, dest=None, **opts):
             raise
 
     if revs:
         revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
+        if not revs:
+            raise util.Abort(_("specified revisions evaluate to an empty set"),
+                             hint=_("use different revision arguments"))
 
     repo._subtoppath = dest
     try:
         # push subrepos depth-first for coherent ordering
diff --git a/tests/test-push-warn.t b/tests/test-push-warn.t
--- a/tests/test-push-warn.t
+++ b/tests/test-push-warn.t
@@ -18,8 +18,16 @@ 
   $ echo foo > t3
   $ hg add t3
   $ hg commit -m "3"
 
+Specifying a revset that evaluates to null will abort
+
+  $ hg push -r '0 & 1' ../a
+  pushing to ../a
+  abort: specified revisions evaluate to an empty set
+  (use different revision arguments)
+  [255]
+
   $ hg push ../a
   pushing to ../a
   searching for changes
   remote has heads on branch 'default' that are not known locally: 1c9246a22a0a