##// END OF EJS Templates
context: add followfirst arg to filectx and workingfilectx...
Patrick Mezard -
r16185:352053e6 default
parent child Browse files
Show More
@@ -611,11 +611,12 b' class filectx(object):'
611
611
612 return None
612 return None
613
613
614 def ancestors(self):
614 def ancestors(self, followfirst=False):
615 visit = {}
615 visit = {}
616 c = self
616 c = self
617 cut = followfirst and 1 or None
617 while True:
618 while True:
618 for parent in c.parents():
619 for parent in c.parents()[:cut]:
619 visit[(parent.rev(), parent.node())] = parent
620 visit[(parent.rev(), parent.node())] = parent
620 if not visit:
621 if not visit:
621 break
622 break
@@ -930,9 +931,10 b' class workingctx(changectx):'
930 finally:
931 finally:
931 wlock.release()
932 wlock.release()
932
933
933 def ancestors(self):
934 def ancestors(self, followfirst=False):
935 cut = followfirst and 1 or None
934 for a in self._repo.changelog.ancestors(
936 for a in self._repo.changelog.ancestors(
935 *[p.rev() for p in self._parents]):
937 *[p.rev() for p in self._parents[:cut]]):
936 yield changectx(self._repo, a)
938 yield changectx(self._repo, a)
937
939
938 def undelete(self, list):
940 def undelete(self, list):
@@ -441,63 +441,45 b' def first(repo, subset, x):'
441 """
441 """
442 return limit(repo, subset, x)
442 return limit(repo, subset, x)
443
443
444 def _follow(repo, subset, x, name, followfirst=False):
445 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
446 c = repo['.']
447 if l:
448 x = getstring(l[0], _("%s expected a filename") % name)
449 if x in c:
450 cx = c[x]
451 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
452 # include the revision responsible for the most recent version
453 s.add(cx.linkrev())
454 else:
455 return []
456 else:
457 cut = followfirst and 1 or None
458 cl = repo.changelog
459 s = set()
460 visit = [c.rev()]
461 while visit:
462 for prev in cl.parentrevs(visit.pop(0))[:cut]:
463 if prev not in s and prev != nodemod.nullrev:
464 visit.append(prev)
465 s.add(prev)
466 s.add(c.rev())
467
468 return [r for r in subset if r in s]
469
444 def follow(repo, subset, x):
470 def follow(repo, subset, x):
445 """``follow([file])``
471 """``follow([file])``
446 An alias for ``::.`` (ancestors of the working copy's first parent).
472 An alias for ``::.`` (ancestors of the working copy's first parent).
447 If a filename is specified, the history of the given file is followed,
473 If a filename is specified, the history of the given file is followed,
448 including copies.
474 including copies.
449 """
475 """
450 # i18n: "follow" is a keyword
476 return _follow(repo, subset, x, 'follow')
451 l = getargs(x, 0, 1, _("follow takes no arguments or a filename"))
452 c = repo['.']
453 if l:
454 x = getstring(l[0], _("follow expected a filename"))
455 if x in c:
456 cx = c[x]
457 s = set(ctx.rev() for ctx in cx.ancestors())
458 # include the revision responsible for the most recent version
459 s.add(cx.linkrev())
460 else:
461 return []
462 else:
463 s = set(repo.changelog.ancestors(c.rev()))
464 s.add(c.rev())
465
466 return [r for r in subset if r in s]
467
477
468 def _followfirst(repo, subset, x):
478 def _followfirst(repo, subset, x):
469 # ``followfirst([file])``
479 # ``followfirst([file])``
470 # Like ``follow([file])`` but follows only the first parent of
480 # Like ``follow([file])`` but follows only the first parent of
471 # every revision or file revision.
481 # every revision or file revision.
472 # i18n: "_followfirst" is a keyword
482 return _follow(repo, subset, x, '_followfirst', followfirst=True)
473 l = getargs(x, 0, 1, _("_followfirst takes no arguments or a filename"))
474 c = repo['.']
475 if l:
476 x = getstring(l[0], _("_followfirst expected a filename"))
477 if x not in c:
478 return []
479 cx = c[x]
480 visit = {}
481 s = set([cx.linkrev()])
482 while True:
483 for p in cx.parents()[:1]:
484 visit[(p.rev(), p.node())] = p
485 if not visit:
486 break
487 cx = visit.pop(max(visit))
488 s.add(cx.rev())
489 else:
490 cl = repo.changelog
491 s = set()
492 visit = [c.rev()]
493 while visit:
494 for prev in cl.parentrevs(visit.pop(0))[:1]:
495 if prev not in s and prev != nodemod.nullrev:
496 visit.append(prev)
497 s.add(prev)
498 s.add(c.rev())
499
500 return [r for r in subset if r in s]
501
483
502 def getall(repo, subset, x):
484 def getall(repo, subset, x):
503 """``all()``
485 """``all()``
General Comments 0
You need to be logged in to leave comments. Login now