Patchwork [V4] revset: id() called with 40-byte strings should give the same results as for short strings

login
register
mail settings
Submitter Alexander Drozdov
Date May 3, 2015, 1:59 p.m.
Message ID <4123b7637e289c8f0bdd.1430661576@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/8863/
State Accepted
Commit b5c227f3e461923bd7ca099984374e6ca92f05ac
Headers show

Comments

Alexander Drozdov - May 3, 2015, 1:59 p.m.
# HG changeset patch
# User Alexander Drozdov <al.drozdov@gmail.com>
# Date 1429516340 -10800
#      Mon Apr 20 10:52:20 2015 +0300
# Node ID 4123b7637e289c8f0bddacb911ed54364d4d89f7
# Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
revset: id() called with 40-byte strings should give the same results as for short strings

The patch solves two issues:
1. id(unknown_full_hash) aborts, but id(unknown_short_hash) doesn't
2. id(40byte_tag_or_bookmark) returns tagged/bookmarked revision,
   but id(non-40byte_tag_or_bookmark) doesn't

After the patch:
1. id(unknown_full_hash) doesn't abort
2. id(40byte_tag_or_bookmark) returns empty set
Matt Mackall - May 4, 2015, 4:57 p.m.
On Sun, 2015-05-03 at 16:59 +0300, Alexander Drozdov wrote:
> # HG changeset patch
> # User Alexander Drozdov <al.drozdov@gmail.com>
> # Date 1429516340 -10800
> #      Mon Apr 20 10:52:20 2015 +0300
> # Node ID 4123b7637e289c8f0bddacb911ed54364d4d89f7
> # Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
> revset: id() called with 40-byte strings should give the same results as for short strings

I've gone ahead and queued this one for stable, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1294,7 +1294,10 @@  def node_(repo, subset, x):
     # i18n: "id" is a keyword
     n = getstring(l[0], _("id requires a string"))
     if len(n) == 40:
-        rn = repo[n].rev()
+        try:
+            rn = repo.changelog.rev(node.bin(n))
+        except (LookupError, TypeError):
+            rn = None
     else:
         rn = None
         pm = repo.changelog._partialmatch(n)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -87,6 +87,7 @@ 
   $ hg ci -Aqm9
 
   $ hg tag -r6 1.0
+  $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
   $ hg clone --quiet -U -r 7 . ../remote1
   $ hg clone --quiet -U -r 8 . ../remote2
@@ -554,6 +555,23 @@  Test explicit numeric revision
   hg: parse error: rev expects a number
   [255]
 
+Test hexadecimal revision
+  $ log 'id(2)'
+  abort: 00changelog.i@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)'
+  $ log 'id(1.0)'
+  $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)'
+
 Test null revision
   $ log '(null)'
   -1