[PATCH] commands.push: abort when revisions evaluate to empty set (BC)

Gregory Szorc gregory.szorc at gmail.com
Tue Mar 24 01:24:53 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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.

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


More information about the Mercurial-devel mailing list