Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revset.py @ 33018:272a44cac57e
revset: add depth limit to ancestors()
This is proposed by the issue5374, and will be a building block of set{gen}
(set subscript) operator.
https://www.mercurial-scm.org/wiki/RevsetOperatorPlan#ideas_from_mpm
# reverse(ancestors(tip)) using hg repo
2) 0.075408
3) 0.075951
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Jun 2017 00:22:41 +0900 |
parents | 577759ef2ed2 |
children | f63d111258da |
line wrap: on
line diff
--- a/mercurial/revset.py Sun Jun 18 00:11:48 2017 +0900 +++ b/mercurial/revset.py Sun Jun 18 00:22:41 2017 +0900 @@ -238,23 +238,33 @@ return baseset([anc.rev()]) return baseset() -def _ancestors(repo, subset, x, followfirst=False): +def _ancestors(repo, subset, x, followfirst=False, stopdepth=None): heads = getset(repo, fullreposet(repo), x) if not heads: return baseset() - s = dagop.revancestors(repo, heads, followfirst) + s = dagop.revancestors(repo, heads, followfirst, stopdepth) return subset & s -@predicate('ancestors(set)', safe=True) +@predicate('ancestors(set[, depth])', safe=True) def ancestors(repo, subset, x): """Changesets that are ancestors of changesets in set, including the given changesets themselves. + + If depth is specified, the result only includes changesets up to + the specified generation. """ - args = getargsdict(x, 'ancestors', 'set') + args = getargsdict(x, 'ancestors', 'set depth') if 'set' not in args: # i18n: "ancestors" is a keyword raise error.ParseError(_('ancestors takes at least 1 argument')) - return _ancestors(repo, subset, args['set']) + stopdepth = None + if 'depth' in args: + # i18n: "ancestors" is a keyword + n = getinteger(args['depth'], _("ancestors expects an integer depth")) + if n < 0: + raise error.ParseError(_("negative depth")) + stopdepth = n + 1 + return _ancestors(repo, subset, args['set'], stopdepth=stopdepth) @predicate('_firstancestors', safe=True) def _firstancestors(repo, subset, x):