context: don't hex encode all unknown 20 char revision specs (issue4890)
authorMads Kiilerich <madski@unity3d.com>
Fri, 09 Oct 2015 01:19:37 +0200
changeset 26604 a3fcc8e3136b
parent 26603 517ffec37dee
child 26605 ef21a2c41629
context: don't hex encode all unknown 20 char revision specs (issue4890) d3908c911d5e introduced nice hexified display of missing nodes. It did however also make missing 20 character revision specifications be shown as hex - very confusing. Users are often wrong and somehow specify revisions that don't exist. Nodes will however rarely be missing ... and they will only look like a user provided revision specification and be all ascii in 1 of 4*10**9. With this change, missing revisions will only be hexified if they really look like binary nodes. This change will thus improve the error reporting UI in the common case and only very rarely make it confusing in the opposite direction of how it was before.
mercurial/context.py
tests/test-pull.t
--- a/mercurial/context.py	Mon Oct 12 00:45:24 2015 -0700
+++ b/mercurial/context.py	Fri Oct 09 01:19:37 2015 +0200
@@ -5,6 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import re
+
 from node import nullid, nullrev, wdirid, short, hex, bin
 from i18n import _
 import mdiff, error, util, scmutil, subrepo, patch, encoding, phases
@@ -22,6 +24,8 @@
 # dirty in the working copy.
 _newnode = '!' * 21
 
+nonascii = re.compile(r'[^\x21-\x7f]').search
+
 class basectx(object):
     """A basectx object represents the common logic for its children:
     changectx: read-only context that is already present in the repo,
@@ -466,7 +470,7 @@
                 msg = _("working directory has unknown parent '%s'!")
                 raise error.Abort(msg % short(changeid))
             try:
-                if len(changeid) == 20:
+                if len(changeid) == 20 and nonascii(changeid):
                     changeid = hex(changeid)
             except TypeError:
                 pass
--- a/tests/test-pull.t	Mon Oct 12 00:45:24 2015 -0700
+++ b/tests/test-pull.t	Fri Oct 09 01:19:37 2015 +0200
@@ -52,6 +52,18 @@
   $ hg rollback --dry-run --verbose
   repository tip rolled back to revision -1 (undo pull: http://foo:***@localhost:$HGPORT/)
 
+Test pull of non-existing 20 character revision specification, making sure plain ascii identifiers
+not are encoded like a node:
+
+  $ hg pull -r 'xxxxxxxxxxxxxxxxxxxy'
+  pulling from http://foo@localhost:$HGPORT/
+  abort: unknown revision 'xxxxxxxxxxxxxxxxxxxy'!
+  [255]
+  $ hg pull -r 'xxxxxxxxxxxxxxxxxx y'
+  pulling from http://foo@localhost:$HGPORT/
+  abort: unknown revision '7878787878787878787878787878787878782079'!
+  [255]
+
 Issue622: hg init && hg pull -u URL doesn't checkout default branch
 
   $ cd ..