##// END OF EJS Templates
revset: make repo.anyrevs accept customized alias override (API)...
Jun Wu -
r33336:4672db16 default
parent child Browse files
Show More
@@ -1960,9 +1960,11 b' def debugrevspec(ui, repo, expr, **opts)'
1960 one. Returns 1 if the optimized result differs.
1960 one. Returns 1 if the optimized result differs.
1961 """
1961 """
1962 opts = pycompat.byteskwargs(opts)
1962 opts = pycompat.byteskwargs(opts)
1963 aliases = ui.configitems('revsetalias')
1963 stages = [
1964 stages = [
1964 ('parsed', lambda tree: tree),
1965 ('parsed', lambda tree: tree),
1965 ('expanded', lambda tree: revsetlang.expandaliases(ui, tree)),
1966 ('expanded', lambda tree: revsetlang.expandaliases(tree, aliases,
1967 ui.warn)),
1966 ('concatenated', revsetlang.foldconcat),
1968 ('concatenated', revsetlang.foldconcat),
1967 ('analyzed', revsetlang.analyze),
1969 ('analyzed', revsetlang.analyze),
1968 ('optimized', revsetlang.optimize),
1970 ('optimized', revsetlang.optimize),
@@ -648,16 +648,19 b' class localrepository(object):'
648 for r in self.revs(expr, *args):
648 for r in self.revs(expr, *args):
649 yield self[r]
649 yield self[r]
650
650
651 def anyrevs(self, specs, user=False):
651 def anyrevs(self, specs, user=False, localalias=None):
652 '''Find revisions matching one of the given revsets.
652 '''Find revisions matching one of the given revsets.
653
653
654 Revset aliases from the configuration are not expanded by default. To
654 Revset aliases from the configuration are not expanded by default. To
655 expand user aliases, specify ``user=True``.
655 expand user aliases, specify ``user=True``. To provide some local
656 definitions overriding user aliases, set ``localalias`` to
657 ``{name: definitionstring}``.
656 '''
658 '''
657 if user:
659 if user:
658 m = revset.matchany(self.ui, specs, repo=self)
660 m = revset.matchany(self.ui, specs, repo=self,
661 localalias=localalias)
659 else:
662 else:
660 m = revset.matchany(None, specs)
663 m = revset.matchany(None, specs, localalias=localalias)
661 return m(self)
664 return m(self)
662
665
663 def url(self):
666 def url(self):
@@ -2001,12 +2001,15 b' def match(ui, spec, repo=None, order=def'
2001 """
2001 """
2002 return matchany(ui, [spec], repo=repo, order=order)
2002 return matchany(ui, [spec], repo=repo, order=order)
2003
2003
2004 def matchany(ui, specs, repo=None, order=defineorder):
2004 def matchany(ui, specs, repo=None, order=defineorder, localalias=None):
2005 """Create a matcher that will include any revisions matching one of the
2005 """Create a matcher that will include any revisions matching one of the
2006 given specs
2006 given specs
2007
2007
2008 If order=followorder, a matcher takes the ordering specified by the input
2008 If order=followorder, a matcher takes the ordering specified by the input
2009 set.
2009 set.
2010
2011 If localalias is not None, it is a dict {name: definitionstring}. It takes
2012 precedence over [revsetalias] config section.
2010 """
2013 """
2011 if not specs:
2014 if not specs:
2012 def mfunc(repo, subset=None):
2015 def mfunc(repo, subset=None):
@@ -2023,8 +2026,15 b' def matchany(ui, specs, repo=None, order'
2023 tree = ('or',
2026 tree = ('or',
2024 ('list',) + tuple(revsetlang.parse(s, lookup) for s in specs))
2027 ('list',) + tuple(revsetlang.parse(s, lookup) for s in specs))
2025
2028
2029 aliases = []
2030 warn = None
2026 if ui:
2031 if ui:
2027 tree = revsetlang.expandaliases(ui, tree)
2032 aliases.extend(ui.configitems('revsetalias'))
2033 warn = ui.warn
2034 if localalias:
2035 aliases.extend(localalias.items())
2036 if aliases:
2037 tree = revsetlang.expandaliases(tree, aliases, warn=warn)
2028 tree = revsetlang.foldconcat(tree)
2038 tree = revsetlang.foldconcat(tree)
2029 tree = revsetlang.analyze(tree, order)
2039 tree = revsetlang.analyze(tree, order)
2030 tree = revsetlang.optimize(tree)
2040 tree = revsetlang.optimize(tree)
@@ -561,14 +561,16 b' class _aliasrules(parser.basealiasrules)'
561 if tree[0] == 'func' and tree[1][0] == 'symbol':
561 if tree[0] == 'func' and tree[1][0] == 'symbol':
562 return tree[1][1], getlist(tree[2])
562 return tree[1][1], getlist(tree[2])
563
563
564 def expandaliases(ui, tree):
564 def expandaliases(tree, aliases, warn=None):
565 aliases = _aliasrules.buildmap(ui.configitems('revsetalias'))
565 """Expand aliases in a tree, aliases is a list of (name, value) tuples"""
566 aliases = _aliasrules.buildmap(aliases)
566 tree = _aliasrules.expand(aliases, tree)
567 tree = _aliasrules.expand(aliases, tree)
567 # warn about problematic (but not referred) aliases
568 # warn about problematic (but not referred) aliases
568 for name, alias in sorted(aliases.iteritems()):
569 if warn is not None:
569 if alias.error and not alias.warned:
570 for name, alias in sorted(aliases.iteritems()):
570 ui.warn(_('warning: %s\n') % (alias.error))
571 if alias.error and not alias.warned:
571 alias.warned = True
572 warn(_('warning: %s\n') % (alias.error))
573 alias.warned = True
572 return tree
574 return tree
573
575
574 def foldconcat(tree):
576 def foldconcat(tree):
@@ -4259,4 +4259,27 b' loading it'
4259 hg: parse error: unknown identifier: custom1
4259 hg: parse error: unknown identifier: custom1
4260 [255]
4260 [255]
4261
4261
4262 Test repo.anyrevs with customized revset overrides
4263
4264 $ cat > $TESTTMP/printprevset.py <<EOF
4265 > from mercurial import encoding
4266 > def reposetup(ui, repo):
4267 > alias = {}
4268 > p = encoding.environ.get('P')
4269 > if p:
4270 > alias['P'] = p
4271 > revs = repo.anyrevs(['P'], user=True, localalias=alias)
4272 > ui.write('P=%r' % list(revs))
4273 > EOF
4274
4275 $ cat >> .hg/hgrc <<EOF
4276 > custompredicate = !
4277 > printprevset = $TESTTMP/printprevset.py
4278 > EOF
4279
4280 $ hg --config revsetalias.P=1 log -r . -T '\n'
4281 P=[1]
4282 $ P=3 hg --config revsetalias.P=2 log -r . -T '\n'
4283 P=[3]
4284
4262 $ cd ..
4285 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now