~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

(mbp) merge bzr.dev to 0.8, prepare for release

Show diffs side-by-side

added added

removed removed

Lines of Context:
463
463
        """
464
464
 
465
465
        assert isinstance(version_id, basestring)
 
466
        self._check_lines_not_unicode(lines)
 
467
        self._check_lines_are_lines(lines)
466
468
        if not sha1:
467
469
            sha1 = sha_strings(lines)
468
470
        if version_id in self._name_map:
710
712
            raise WeaveFormatError("unclosed deletion blocks at end of weave: %s"
711
713
                                   % dset)
712
714
 
 
715
    def plan_merge(self, ver_a, ver_b):
 
716
        """Return pseudo-annotation indicating how the two versions merge.
 
717
 
 
718
        This is computed between versions a and b and their common
 
719
        base.
 
720
 
 
721
        Weave lines present in none of them are skipped entirely.
 
722
        """
 
723
        inc_a = set(self.get_ancestry([ver_a]))
 
724
        inc_b = set(self.get_ancestry([ver_b]))
 
725
        inc_c = inc_a & inc_b
 
726
 
 
727
        for lineno, insert, deleteset, line in\
 
728
            self.walk([ver_a, ver_b]):
 
729
            if deleteset & inc_c:
 
730
                # killed in parent; can't be in either a or b
 
731
                # not relevant to our work
 
732
                yield 'killed-base', line
 
733
            elif insert in inc_c:
 
734
                # was inserted in base
 
735
                killed_a = bool(deleteset & inc_a)
 
736
                killed_b = bool(deleteset & inc_b)
 
737
                if killed_a and killed_b:
 
738
                    yield 'killed-both', line
 
739
                elif killed_a:
 
740
                    yield 'killed-a', line
 
741
                elif killed_b:
 
742
                    yield 'killed-b', line
 
743
                else:
 
744
                    yield 'unchanged', line
 
745
            elif insert in inc_a:
 
746
                if deleteset & inc_a:
 
747
                    yield 'ghost-a', line
 
748
                else:
 
749
                    # new in A; not in B
 
750
                    yield 'new-a', line
 
751
            elif insert in inc_b:
 
752
                if deleteset & inc_b:
 
753
                    yield 'ghost-b', line
 
754
                else:
 
755
                    yield 'new-b', line
 
756
            else:
 
757
                # not in either revision
 
758
                yield 'irrelevant', line
 
759
 
 
760
        yield 'unchanged', ''           # terminator
 
761
 
713
762
    def _extract(self, versions):
714
763
        """Yield annotation of lines in included set.
715
764
 
839
888
                       expected_sha1, measured_sha1))
840
889
        return result
841
890
 
842
 
    def get_sha1(self, name):
843
 
        """Get the stored sha1 sum for the given revision.
844
 
        
845
 
        :param name: The name of the version to lookup
846
 
        """
847
 
        return self._sha1s[self._lookup(name)]
 
891
    def get_sha1(self, version_id):
 
892
        """See VersionedFile.get_sha1()."""
 
893
        return self._sha1s[self._lookup(version_id)]
848
894
 
849
895
    @deprecated_method(zero_eight)
850
896
    def numversions(self):
931
977
        if not other.versions():
932
978
            return          # nothing to update, easy
933
979
 
934
 
        if version_ids:
935
 
            for version_id in version_ids:
936
 
                if not other.has_version(version_id) and not ignore_missing:
937
 
                    raise RevisionNotPresent(version_id, self._weave_name)
938
 
        else:
939
 
            version_ids = other.versions()
 
980
        if not version_ids:
 
981
            # versions is never none, InterWeave checks this.
 
982
            return 0
940
983
 
941
984
        # two loops so that we do not change ourselves before verifying it
942
985
        # will be ok
1419
1462
class InterWeave(InterVersionedFile):
1420
1463
    """Optimised code paths for weave to weave operations."""
1421
1464
    
1422
 
    _matching_file_factory = staticmethod(WeaveFile)
 
1465
    _matching_file_from_factory = staticmethod(WeaveFile)
 
1466
    _matching_file_to_factory = staticmethod(WeaveFile)
1423
1467
    
1424
1468
    @staticmethod
1425
1469
    def is_compatible(source, target):
1432
1476
 
1433
1477
    def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False):
1434
1478
        """See InterVersionedFile.join."""
1435
 
        if self.target.versions() == []:
1436
 
            # optimised copy
 
1479
        version_ids = self._get_source_version_ids(version_ids, ignore_missing)
 
1480
        if self.target.versions() == [] and version_ids is None:
1437
1481
            self.target._copy_weave_content(self.source)
1438
1482
            return
1439
1483
        try: