comparison mercurial/revset.py @ 33002: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
comparison
equal deleted inserted replaced
33001:92d0945a15e0 33002:272a44cac57e
236 236
237 if anc is not None and anc.rev() in subset: 237 if anc is not None and anc.rev() in subset:
238 return baseset([anc.rev()]) 238 return baseset([anc.rev()])
239 return baseset() 239 return baseset()
240 240
241 def _ancestors(repo, subset, x, followfirst=False): 241 def _ancestors(repo, subset, x, followfirst=False, stopdepth=None):
242 heads = getset(repo, fullreposet(repo), x) 242 heads = getset(repo, fullreposet(repo), x)
243 if not heads: 243 if not heads:
244 return baseset() 244 return baseset()
245 s = dagop.revancestors(repo, heads, followfirst) 245 s = dagop.revancestors(repo, heads, followfirst, stopdepth)
246 return subset & s 246 return subset & s
247 247
248 @predicate('ancestors(set)', safe=True) 248 @predicate('ancestors(set[, depth])', safe=True)
249 def ancestors(repo, subset, x): 249 def ancestors(repo, subset, x):
250 """Changesets that are ancestors of changesets in set, including the 250 """Changesets that are ancestors of changesets in set, including the
251 given changesets themselves. 251 given changesets themselves.
252 """ 252
253 args = getargsdict(x, 'ancestors', 'set') 253 If depth is specified, the result only includes changesets up to
254 the specified generation.
255 """
256 args = getargsdict(x, 'ancestors', 'set depth')
254 if 'set' not in args: 257 if 'set' not in args:
255 # i18n: "ancestors" is a keyword 258 # i18n: "ancestors" is a keyword
256 raise error.ParseError(_('ancestors takes at least 1 argument')) 259 raise error.ParseError(_('ancestors takes at least 1 argument'))
257 return _ancestors(repo, subset, args['set']) 260 stopdepth = None
261 if 'depth' in args:
262 # i18n: "ancestors" is a keyword
263 n = getinteger(args['depth'], _("ancestors expects an integer depth"))
264 if n < 0:
265 raise error.ParseError(_("negative depth"))
266 stopdepth = n + 1
267 return _ancestors(repo, subset, args['set'], stopdepth=stopdepth)
258 268
259 @predicate('_firstancestors', safe=True) 269 @predicate('_firstancestors', safe=True)
260 def _firstancestors(repo, subset, x): 270 def _firstancestors(repo, subset, x):
261 # ``_firstancestors(set)`` 271 # ``_firstancestors(set)``
262 # Like ``ancestors(set)`` but follows only the first parents. 272 # Like ``ancestors(set)`` but follows only the first parents.