mercurial/revset.py
changeset 18536 ae645d4f084c
parent 18495 8260fa9f30b9
child 18779 9e39a717a23e
equal deleted inserted replaced
18535:7068089c95a2 18536:ae645d4f084c
   275     # i18n: "adds" is a keyword
   275     # i18n: "adds" is a keyword
   276     pat = getstring(x, _("adds requires a pattern"))
   276     pat = getstring(x, _("adds requires a pattern"))
   277     return checkstatus(repo, subset, pat, 1)
   277     return checkstatus(repo, subset, pat, 1)
   278 
   278 
   279 def ancestor(repo, subset, x):
   279 def ancestor(repo, subset, x):
   280     """``ancestor(single, single)``
   280     """``ancestor(*changeset)``
   281     Greatest common ancestor of the two changesets.
   281     Greatest common ancestor of the changesets.
       
   282 
       
   283     Accepts 0 or more changesets.
       
   284     Will return empty list when passed no args.
       
   285     Greatest common ancestor of a single changeset is that changeset.
   282     """
   286     """
   283     # i18n: "ancestor" is a keyword
   287     # i18n: "ancestor" is a keyword
   284     l = getargs(x, 2, 2, _("ancestor requires two arguments"))
   288     l = getlist(x)
   285     r = list(repo)
   289     rl = list(repo)
   286     a = getset(repo, r, l[0])
   290     anc = None
   287     b = getset(repo, r, l[1])
   291 
   288     if len(a) != 1 or len(b) != 1:
   292     # (getset(repo, rl, i) for i in l) generates a list of lists
   289         # i18n: "ancestor" is a keyword
   293     rev = repo.changelog.rev
   290         raise error.ParseError(_("ancestor arguments must be single revisions"))
   294     ancestor = repo.changelog.ancestor
   291     an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
   295     node = repo.changelog.node
   292 
   296     for revs in (getset(repo, rl, i) for i in l):
   293     return [r for r in an if r in subset]
   297         for r in revs:
       
   298             if anc is None:
       
   299                 anc = r
       
   300             else:
       
   301                 anc = rev(ancestor(node(anc), node(r)))
       
   302 
       
   303     if anc is not None and anc in subset:
       
   304         return [anc]
       
   305     return []
   294 
   306 
   295 def _ancestors(repo, subset, x, followfirst=False):
   307 def _ancestors(repo, subset, x, followfirst=False):
   296     args = getset(repo, list(repo), x)
   308     args = getset(repo, list(repo), x)
   297     if not args:
   309     if not args:
   298         return []
   310         return []