~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Robert Collins
  • Date: 2005-10-08 00:03:38 UTC
  • mto: (1185.1.51)
  • mto: This revision was merged to the branch mainline in revision 1422.
  • Revision ID: robertc@robertcollins.net-20051008000338-91e577a411df6c37
make reweave visible as a weave method, and quickly integrate into fetch

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
 
84
84
class WeaveFormatError(WeaveError):
85
85
    """Weave invariant violated"""
 
86
 
 
87
 
 
88
class WeaveParentMismatch(WeaveError):
 
89
    """Parents are mismatched between two revisions."""
86
90
    
87
91
 
88
92
class Weave(object):
783
787
        """
784
788
        if other.numversions() == 0:
785
789
            return          # nothing to update, easy
 
790
        # two loops so that we do not change ourselves before verifying it
 
791
        # will be ok
786
792
        # work through in index order to make sure we get all dependencies
787
793
        for other_idx, name in enumerate(other._names):
 
794
            if self._check_version_consistent(other, other_idx, name):
 
795
                continue
 
796
        for other_idx, name in enumerate(other._names):
788
797
            # TODO: If all the parents of the other version are already 
789
798
            # present then we can avoid some work by just taking the delta
790
799
            # and adjusting the offsets.
791
 
            if self._check_version_consistent(other, other_idx, name):
792
 
                continue
793
800
            new_parents = self._imported_parents(other, other_idx)
794
801
            lines = other.get_lines(other_idx)
795
802
            sha1 = other._sha1s[other_idx]
833
840
            n1.sort()
834
841
            n2.sort()
835
842
            if n1 != n2:
836
 
                # XXX: Perhaps return a specific exception for this so
837
 
                # we can retry through reweave().
838
 
                raise WeaveError("inconsistent parents for version {%s}: "
839
 
                                 "%s vs %s"
840
 
                                 % (name, n1, n2))
 
843
                raise WeaveParentMismatch("inconsistent parents "
 
844
                    "for version {%s}: %s vs %s" % (name, n1, n2))
841
845
            else:
842
846
                return True         # ok!
843
847
        else:
844
848
            return False
845
849
 
 
850
    def reweave(self, other):
 
851
        """Reweave self with other."""
 
852
        new_weave = reweave(self, other)
 
853
        for attr in self.__slots__:
 
854
            setattr(self, attr, getattr(new_weave, attr))
 
855
 
846
856
 
847
857
def reweave(wa, wb):
848
858
    """Combine two weaves and return the result.