~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-10-05 03:46:56 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1403.
  • Revision ID: mbp@sourcefrog.net-20051005034656-cefbc4b61764a895
- more development of Weave.join()

Show diffs side-by-side

added added

removed removed

Lines of Context:
767
767
        """
768
768
        if other.numversions() == 0:
769
769
            return          # nothing to update, easy
770
 
        self._check_consistent_with(other)
771
 
        raise NotImplementedError()
772
 
 
773
 
 
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):
778
776
                continue
779
 
            if self._sha1s[self._names[name]] != other._sha1s[other._names[name]]:
 
777
            new_parents = []
 
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)
 
788
 
 
789
    def _check_version_consistent(self, other, other_idx, name):
 
790
        """Check if a version in consistent in this and other.
 
791
        
 
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)
 
796
        if this_idx != -1:
 
797
            if self._sha1s[this_idx] != other._sha1s[other_idx]:
780
798
                raise WeaveError("inconsistent texts for version {%s} in %r and %r"
781
 
                                 % name, self, other)
782
 
 
 
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))
 
803
            else:
 
804
                return True         # ok!
 
805
        else:
 
806
            return False
783
807
 
784
808
 
785
809
def weave_toc(w):