comparison mercurial/templater.py @ 22304:5678b0e3608f

templater: enable alias predicates to be used in "revset()" function Before this patch, predicates defined in "[revsetalias]" can't be used in the query specified to template function "revset()", because: - "revset()" uses "localrepository.revs()" to get query result, but - "localrepository.revs()" passes "None" as "ui" to "revset.match()", then - "revset.match()" can't recognize any alias predicates To enable alias predicates to be used in "revset()" function, this patch invokes "revset.match()" directly with "repo.ui". This patch doesn't make "localrepository.revs()" pass "self.ui" to "revset.match()", because this may be intentional implementation to prevent alias predicates from shadowing built-in ones and breaking functions internally using "localrepository.revs()". Even if it isn't intentional one, the check for shadowing should be implemented (maybe on default branch) before fixing it for safety.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 23 Aug 2014 21:23:02 +0900
parents 2896d450fec4
children 40ce05b50148
comparison
equal deleted inserted replaced
22300:35ab037de989 22304:5678b0e3608f
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 import sys, os, re 9 import sys, os, re
10 import util, config, templatefilters, templatekw, parser, error 10 import util, config, templatefilters, templatekw, parser, error
11 import revset as revsetmod
11 import types 12 import types
12 import minirst 13 import minirst
13 14
14 # template parsing 15 # template parsing
15 16
368 369
369 raw = args[0][1] 370 raw = args[0][1]
370 ctx = mapping['ctx'] 371 ctx = mapping['ctx']
371 repo = ctx._repo 372 repo = ctx._repo
372 373
374 def query(expr):
375 m = revsetmod.match(repo.ui, expr)
376 return m(repo, revsetmod.spanset(repo))
377
373 if len(args) > 1: 378 if len(args) > 1:
374 formatargs = list([a[0](context, mapping, a[1]) for a in args[1:]]) 379 formatargs = list([a[0](context, mapping, a[1]) for a in args[1:]])
375 revs = repo.revs(raw, *formatargs) 380 revs = query(revsetmod.formatspec(raw, *formatargs))
376 revs = list([str(r) for r in revs]) 381 revs = list([str(r) for r in revs])
377 else: 382 else:
378 revsetcache = mapping['cache'].setdefault("revsetcache", {}) 383 revsetcache = mapping['cache'].setdefault("revsetcache", {})
379 if raw in revsetcache: 384 if raw in revsetcache:
380 revs = revsetcache[raw] 385 revs = revsetcache[raw]
381 else: 386 else:
382 revs = repo.revs(raw) 387 revs = query(raw)
383 revs = list([str(r) for r in revs]) 388 revs = list([str(r) for r in revs])
384 revsetcache[raw] = revs 389 revsetcache[raw] = revs
385 390
386 return templatekw.showlist("revision", revs, **mapping) 391 return templatekw.showlist("revision", revs, **mapping)
387 392