768
768
if other.numversions() == 0:
769
769
return # nothing to update, easy
770
self._check_consistent_with(other)
771
raise NotImplementedError()
774
def _check_consistent_with(self, other):
775
"""Make sure any versions present in both weaves have consistent values."""
776
for name in self._names:
777
if name not in other._names:
770
# work through in index order to make sure we get all dependencies
771
for other_idx, name in enumerate(other._names):
772
# TODO: If all the parents of the other version are already
773
# present then we can avoid some work by just taking the delta
774
# and adjusting the offsets.
775
if self._check_version_consistent(other, other_idx, name):
779
if self._sha1s[self._names[name]] != other._sha1s[other._names[name]]:
778
for parent_idx in other._parents[other_idx]:
779
parent_name = other._names[parent_idx]
780
if parent_name not in self._names:
781
# should never happen
782
raise WeaveError("missing parent {%s} of {%s} in %r"
783
% (parent_name, name, self))
784
new_parents.append(self._names[parent_name])
785
lines = other.get_lines(other_idx)
786
sha1 = other._sha1s[other_idx]
787
self.add(name, new_parents, lines, sha1)
789
def _check_version_consistent(self, other, other_idx, name):
790
"""Check if a version in consistent in this and other.
792
If present & correct return True;
793
if not present in self return False;
794
if inconsistent raise error."""
795
this_idx = self._name_map.get(name, -1)
797
if self._sha1s[this_idx] != other._sha1s[other_idx]:
780
798
raise WeaveError("inconsistent texts for version {%s} in %r and %r"
799
% (name, self, other))
800
elif set(self._parents[this_idx]) != set(other._parents[other_idx]):
801
raise WeaveError("inconsistent parents for version {%s} in %r and %r"
802
% (name, self, other))
785
809
def weave_toc(w):