changeset 44591:967e2e81f762

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().
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Mar 2020 13:39:39 +0900
parents 482a6aac1f15
children f913ece27ff5
files mercurial/revset.py tests/test-template-functions.t
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat Mar 21 13:27:47 2020 +0900
+++ b/mercurial/revset.py	Sat Mar 21 13:39:39 2020 +0900
@@ -2109,7 +2109,10 @@
         # 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])
 
 
--- a/tests/test-template-functions.t	Sat Mar 21 13:27:47 2020 +0900
+++ b/tests/test-template-functions.t	Sat Mar 21 13:39:39 2020 +0900
@@ -1269,6 +1269,12 @@
   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()