Patchwork [2,of,3] revset: fix crash by repo.revs('%d', tip + 1)

login
register
mail settings
Submitter Yuya Nishihara
Date March 21, 2020, 5:26 a.m.
Message ID <1c189a6e5aa76bf71d50.1584768414@mimosa>
Download mbox | patch
Permalink /patch/45859/
State Accepted
Headers show

Comments

Yuya Nishihara - March 21, 2020, 5:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1584765579 -32400
#      Sat Mar 21 13:39:39 2020 +0900
# Node ID 1c189a6e5aa76bf71d5078597fd01c1f959244a2
# Parent  d0aa302e184789f1af3048814d23d0a4cedcca15
revset: fix crash by repo.revs('%d', tip + 1)

IndexError shouldn't be raised from a revset predicate. The error message
is copied from scmutil.revsymbol().

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2109,7 +2109,10 @@  def _rev(repo, subset, x):
         # i18n: "rev" is a keyword
         raise error.ParseError(_(b"rev expects a number"))
     if l not in _virtualrevs:
-        repo.changelog.node(l)  # check that the rev exists
+        try:
+            repo.changelog.node(l)  # check that the rev exists
+        except IndexError:
+            raise error.RepoLookupError(_(b"unknown revision '%d'") % l)
     return subset & baseset([l])
 
 
diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t
--- a/tests/test-template-functions.t
+++ b/tests/test-template-functions.t
@@ -1269,6 +1269,12 @@  default. join() should agree with the de
   2147483647
   $ hg log -T '{revset("%d", rev)}\n' -r'null'
   -1
+  $ hg log -T '{revset("%d", rev + 1)}\n' -r'tip'
+  abort: unknown revision '3'!
+  [255]
+  $ hg log -T '{revset("%d", rev - 1)}\n' -r'null'
+  abort: unknown revision '-2'!
+  [255]
 
 Invalid arguments passed to revset()