[PATCH V2] revset: make id() to not abort on an unknown 40-byte string

Alexander Drozdov al.drozdov at gmail.com
Tue Apr 14 05:40:48 UTC 2015


# HG changeset patch
# User Alexander Drozdov <al.drozdov at gmail.com>
# Date 1428988858 -10800
#      Tue Apr 14 08:20:58 2015 +0300
# Node ID 31e872ad0473ed27cf48b518fee28f34049a9698
# Parent  52ff737c63d2b2cb41185549aa9c35bc47317032
revset: make id() to not abort on an unknown 40-byte string

Instead, just return an empty set in the case as for less-then-40-byte
strings.

diff -r 52ff737c63d2 -r 31e872ad0473 mercurial/revset.py
--- a/mercurial/revset.py	Thu Apr 09 16:18:38 2015 -0400
+++ b/mercurial/revset.py	Tue Apr 14 08:20:58 2015 +0300
@@ -1293,7 +1293,10 @@
     # i18n: "id" is a keyword
     n = getstring(l[0], _("id requires a string"))
     if len(n) == 40:
-        rn = repo[n].rev()
+        try:
+            rn = repo[n].rev()
+        except error.RepoLookupError:
+            rn = None
     else:
         rn = None
         pm = repo.changelog._partialmatch(n)
diff -r 52ff737c63d2 -r 31e872ad0473 tests/test-revset.t
--- a/tests/test-revset.t	Thu Apr 09 16:18:38 2015 -0400
+++ b/tests/test-revset.t	Tue Apr 14 08:20:58 2015 +0300
@@ -554,6 +554,21 @@
   hg: parse error: rev expects a number
   [255]
 
+Test hexadecimal revision
+  $ log 'id(2)'
+  abort: 00changelog.i at 2: ambiguous identifier!
+  [255]
+  $ log 'id(23268)'
+  4
+  $ log 'id(2785f51eece)'
+  0
+  $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)'
+  8
+  $ log 'id(d5d0dcbdc4a)'
+  $ log 'id(d5d0dcbdc4w)'
+  $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)'
+  $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)'
+
 Test null revision
   $ log '(null)'
   -1


More information about the Mercurial-devel mailing list