From patchwork Mon Apr 13 06:11:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: revset: make id() to not abort on an unknown 40-byte string From: Alexander Drozdov X-Patchwork-Id: 8627 Message-Id: To: mercurial-devel@selenic.com Date: Mon, 13 Apr 2015 09:11:02 +0300 # HG changeset patch # User Alexander Drozdov # Date 1428905039 -10800 # Mon Apr 13 09:03:59 2015 +0300 # Node ID c2e3c9bce437a01584e4c32469c0f5d0fcf566d7 # 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 --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1292,13 +1292,10 @@ def node_(repo, subset, x): l = getargs(x, 1, 1, _("id requires one argument")) # i18n: "id" is a keyword n = getstring(l[0], _("id requires a string")) - if len(n) == 40: - rn = repo[n].rev() - else: - rn = None - pm = repo.changelog._partialmatch(n) - if pm is not None: - rn = repo.changelog.rev(pm) + rn = None + pm = repo.changelog._partialmatch(n) + if pm is not None: + rn = repo.changelog.rev(pm) if rn is None: return baseset() diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -554,6 +554,21 @@ 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)' + Test null revision $ log '(null)' -1