From patchwork Mon Jan 14 12:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3, of, 7, V2] revset: enforce "%d" to be interpreted as literal revision number (API) (BC) From: Boris Feld X-Patchwork-Id: 37723 Message-Id: <18309ce7974f4479b089.1547467993@localhost.localdomain> To: mercurial-devel@mercurial-scm.org Date: Mon, 14 Jan 2019 13:13:13 +0100 diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py --- a/mercurial/revsetlang.py +++ b/mercurial/revsetlang.py @@ -583,7 +583,7 @@ def _quote(s): def _formatargtype(c, arg): if c == 'd': - return '%d' % int(arg) + return 'rev(%d)' % int(arg) elif c == 's': return _quote(arg) elif c == 'r': @@ -638,7 +638,7 @@ def formatspec(expr, *args): Supported arguments: %r = revset expression, parenthesized - %d = int(arg), no quoting + %d = rev(int(arg)), no quoting %s = string(arg), escaped and single-quoted %b = arg.branch(), escaped and single-quoted %n = hex(arg), single-quoted @@ -650,9 +650,9 @@ def formatspec(expr, *args): >>> formatspec(b'%r:: and %lr', b'10 or 11', (b"this()", b"that()")) '(10 or 11):: and ((this()) or (that()))' >>> formatspec(b'%d:: and not %d::', 10, 20) - '10:: and not 20::' + 'rev(10):: and not rev(20)::' >>> formatspec(b'%ld or %ld', [], [1]) - "_list('') or 1" + "_list('') or rev(1)" >>> formatspec(b'keyword(%s)', b'foo\\xe9') "keyword('foo\\\\xe9')" >>> b = lambda: b'default' diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -723,7 +723,7 @@ def revrange(repo, specs, localalias=Non allspecs = [] for spec in specs: if isinstance(spec, int): - spec = revsetlang.formatspec('rev(%d)', spec) + spec = revsetlang.formatspec('%d', spec) allspecs.append(spec) return repo.anyrevs(allspecs, user=True, localalias=localalias)