Show More
@@ -24,7 +24,7 b' from .thirdparty import (' | |||||
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | from . import ( |
|
26 | from . import ( | |
27 |
dag |
|
27 | dagop, | |
28 | error, |
|
28 | error, | |
29 | match as matchmod, |
|
29 | match as matchmod, | |
30 | mdiff, |
|
30 | mdiff, | |
@@ -587,8 +587,8 b' def _sortnodesnormal(store, nodes, reord' | |||||
587 | # for generaldelta revlogs, we linearize the revs; this will both be |
|
587 | # for generaldelta revlogs, we linearize the revs; this will both be | |
588 | # much quicker and generate a much smaller bundle |
|
588 | # much quicker and generate a much smaller bundle | |
589 | if (store._generaldelta and reorder is None) or reorder: |
|
589 | if (store._generaldelta and reorder is None) or reorder: | |
590 | dag = dagutil.revlogdag(store) |
|
590 | revs = set(store.rev(n) for n in nodes) | |
591 |
return dag.linearize( |
|
591 | return dagop.linearize(revs, store.parentrevs) | |
592 | else: |
|
592 | else: | |
593 | return sorted([store.rev(n) for n in nodes]) |
|
593 | return sorted([store.rev(n) for n in nodes]) | |
594 |
|
594 |
@@ -738,3 +738,40 b' def headrevs(revs, parentsfn):' | |||||
738 | headrevs.discard(node.nullrev) |
|
738 | headrevs.discard(node.nullrev) | |
739 |
|
739 | |||
740 | return headrevs |
|
740 | return headrevs | |
|
741 | ||||
|
742 | def linearize(revs, parentsfn): | |||
|
743 | """Linearize and topologically sort a list of revisions. | |||
|
744 | ||||
|
745 | The linearization process tires to create long runs of revs where a child | |||
|
746 | rev comes immediately after its first parent. This is done by visiting the | |||
|
747 | heads of the revs in inverse topological order, and for each visited rev, | |||
|
748 | visiting its second parent, then its first parent, then adding the rev | |||
|
749 | itself to the output list. | |||
|
750 | ||||
|
751 | Returns a list of revision numbers. | |||
|
752 | """ | |||
|
753 | visit = list(sorted(headrevs(revs, parentsfn), reverse=True)) | |||
|
754 | finished = set() | |||
|
755 | result = [] | |||
|
756 | ||||
|
757 | while visit: | |||
|
758 | rev = visit.pop() | |||
|
759 | if rev < 0: | |||
|
760 | rev = -rev - 1 | |||
|
761 | ||||
|
762 | if rev not in finished: | |||
|
763 | result.append(rev) | |||
|
764 | finished.add(rev) | |||
|
765 | ||||
|
766 | else: | |||
|
767 | visit.append(-rev - 1) | |||
|
768 | ||||
|
769 | for prev in parentsfn(rev): | |||
|
770 | if prev == node.nullrev or prev not in revs or prev in finished: | |||
|
771 | continue | |||
|
772 | ||||
|
773 | visit.append(prev) | |||
|
774 | ||||
|
775 | assert len(result) == len(revs) | |||
|
776 | ||||
|
777 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now