Show More
@@ -773,6 +773,42 def headrevs(revs, parentsfn): | |||||
773 |
|
773 | |||
774 | return headrevs |
|
774 | return headrevs | |
775 |
|
775 | |||
|
776 | def headrevssubset(revsfn, parentrevsfn, startrev=None, stoprevs=None): | |||
|
777 | """Returns the set of all revs that have no children with control. | |||
|
778 | ||||
|
779 | ``revsfn`` is a callable that with no arguments returns an iterator over | |||
|
780 | all revision numbers in topological order. With a ``start`` argument, it | |||
|
781 | returns revision numbers starting at that number. | |||
|
782 | ||||
|
783 | ``parentrevsfn`` is a callable receiving a revision number and returns an | |||
|
784 | iterable of parent revision numbers, where values can include nullrev. | |||
|
785 | ||||
|
786 | ``startrev`` is a revision number at which to start the search. | |||
|
787 | ||||
|
788 | ``stoprevs`` is an iterable of revision numbers that, when encountered, | |||
|
789 | will stop DAG traversal beyond them. Parents of revisions in this | |||
|
790 | collection will be heads. | |||
|
791 | """ | |||
|
792 | if startrev is None: | |||
|
793 | startrev = nullrev | |||
|
794 | ||||
|
795 | stoprevs = set(stoprevs or []) | |||
|
796 | ||||
|
797 | reachable = {startrev} | |||
|
798 | heads = {startrev} | |||
|
799 | ||||
|
800 | for rev in revsfn(start=startrev + 1): | |||
|
801 | for prev in parentrevsfn(rev): | |||
|
802 | if prev in reachable: | |||
|
803 | if rev not in stoprevs: | |||
|
804 | reachable.add(rev) | |||
|
805 | heads.add(rev) | |||
|
806 | ||||
|
807 | if prev in heads and prev not in stoprevs: | |||
|
808 | heads.remove(prev) | |||
|
809 | ||||
|
810 | return heads | |||
|
811 | ||||
776 | def linearize(revs, parentsfn): |
|
812 | def linearize(revs, parentsfn): | |
777 | """Linearize and topologically sort a list of revisions. |
|
813 | """Linearize and topologically sort a list of revisions. | |
778 |
|
814 |
@@ -1069,25 +1069,16 class revlog(object): | |||||
1069 | return [self.node(r) for r in self.headrevs()] |
|
1069 | return [self.node(r) for r in self.headrevs()] | |
1070 |
|
1070 | |||
1071 | if start is None: |
|
1071 | if start is None: | |
1072 |
start = null |
|
1072 | start = nullrev | |
1073 | if stop is None: |
|
1073 | else: | |
1074 |
st |
|
1074 | start = self.rev(start) | |
1075 | stoprevs = set([self.rev(n) for n in stop]) |
|
1075 | ||
1076 |
st |
|
1076 | stoprevs = set(self.rev(n) for n in stop or []) | |
1077 | reachable = {startrev} |
|
1077 | ||
1078 | heads = {startrev} |
|
1078 | revs = dagop.headrevssubset(self.revs, self.parentrevs, startrev=start, | |
1079 |
|
1079 | stoprevs=stoprevs) | ||
1080 | parentrevs = self.parentrevs |
|
1080 | ||
1081 | for r in self.revs(start=startrev + 1): |
|
1081 | return [self.node(rev) for rev in revs] | |
1082 | for p in parentrevs(r): |
|
|||
1083 | if p in reachable: |
|
|||
1084 | if r not in stoprevs: |
|
|||
1085 | reachable.add(r) |
|
|||
1086 | heads.add(r) |
|
|||
1087 | if p in heads and p not in stoprevs: |
|
|||
1088 | heads.remove(p) |
|
|||
1089 |
|
||||
1090 | return [self.node(r) for r in heads] |
|
|||
1091 |
|
1082 | |||
1092 | def children(self, node): |
|
1083 | def children(self, node): | |
1093 | """find the children of a given node""" |
|
1084 | """find the children of a given node""" |
General Comments 0
You need to be logged in to leave comments.
Login now