398
398
return self._parents[version]
401
def parent_names(self, version):
402
"""Return version names for parents of a version."""
403
return map(self.idx_to_name, self._parents[self.lookup(version)])
401
406
def minimal_parents(self, version):
402
407
"""Find the minimal set of parents for the version."""
403
408
included = self._parents[version]
774
779
retrieved from self after this call.
776
781
It is illegal for the two weaves to contain different values
782
or different parents for any version. See also reweave().
779
784
if other.numversions() == 0:
780
785
return # nothing to update, easy
848
"""Combine two weaves and return the result.
850
This works even if a revision R has different parents in
851
wa and wb. In the resulting weave all the parents are given.
853
This is done by just building up a new weave, maintaining ordering
854
of the versions in the two inputs. More efficient approaches
855
might be possible but it should only be necessary to do
856
this operation rarely, when a new previously ghost version is
861
queue_a = range(wa.numversions())
862
queue_b = range(wb.numversions())
863
# first determine combined parents of all versions
864
# map from version name -> all parent names
865
combined_parents = _reweave_parent_graphs(wa, wb)
866
mutter("combined parents: %r", combined_parents)
867
order = _make_reweave_order(wa._names, wb._names, combined_parents)
868
mutter("order to reweave: %r", order)
870
if name in wa._name_map:
871
lines = wa.get_lines(name)
872
if name in wb._name_map:
873
assert lines == wb.get_lines(name)
875
lines = wb.get_lines(name)
876
wr.add(name, combined_parents[name], lines)
880
def _reweave_parent_graphs(wa, wb):
881
"""Return combined parent ancestry for two weaves.
883
Returned as a list of (version_name, set(parent_names))"""
885
for weave in [wa, wb]:
886
for idx, name in enumerate(weave._names):
887
p = combined.setdefault(name, set())
888
p.update(map(weave.idx_to_name, weave._parents[idx]))
892
def _make_reweave_order(wa_order, wb_order, combined_parents):
893
"""Return an order to reweave versions respecting parents."""
897
next_a = next_b = None
898
len_a = len(wa_order)
899
len_b = len(wb_order)
900
while ia < len(wa_order) or ib < len(wb_order):
902
next_a = wa_order[ia]
906
if combined_parents[next_a].issubset(done):
908
result.append(next_a)
912
next_b = wb_order[ib]
916
elif combined_parents[next_b].issubset(done):
918
result.append(next_b)
921
raise WeaveError("don't know how to reweave at {%s} and {%s}"
840
926
def weave_toc(w):
841
927
"""Show the weave's table-of-contents"""
842
928
print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')