~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Robert Collins
  • Date: 2007-08-22 01:41:24 UTC
  • mfrom: (2740 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2741.
  • Revision ID: robertc@robertcollins.net-20070822014124-wiinlne4nin2f2tm
Merge bzr.dev to resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
from bzrlib.inter import InterObject
39
39
from bzrlib.textmerge import TextMerge
40
 
from bzrlib.symbol_versioning import (deprecated_function,
41
 
        deprecated_method,
42
 
        zero_eight,
43
 
        )
44
40
 
45
41
 
46
42
class VersionedFile(object):
69
65
        """Copy this versioned file to name on transport."""
70
66
        raise NotImplementedError(self.copy_to)
71
67
 
72
 
    @deprecated_method(zero_eight)
73
 
    def names(self):
74
 
        """Return a list of all the versions in this versioned file.
75
 
 
76
 
        Please use versionedfile.versions() now.
77
 
        """
78
 
        return self.versions()
79
 
 
80
68
    def versions(self):
81
69
        """Return a unsorted list of versions."""
82
70
        raise NotImplementedError(self.versions)
125
113
            new_full[-1] = new_full[-1][:-1]
126
114
        self.add_lines(version_id, parents, new_full)
127
115
 
128
 
    def add_lines(self, version_id, parents, lines, parent_texts=None):
 
116
    def add_lines(self, version_id, parents, lines, parent_texts=None,
 
117
                  left_matching_blocks=None):
129
118
        """Add a single text on top of the versioned file.
130
119
 
131
120
        Must raise RevisionAlreadyPresent if the new version is
138
127
             version_id to allow delta optimisations. 
139
128
             VERY IMPORTANT: the texts must be those returned
140
129
             by add_lines or data corruption can be caused.
 
130
        :param left_matching_blocks: a hint about which areas are common
 
131
            between the text and its left-hand-parent.  The format is
 
132
            the SequenceMatcher.get_matching_blocks format.
141
133
        :return: An opaque representation of the inserted version which can be
142
134
                 provided back to future add_lines calls in the parent_texts
143
135
                 dictionary.
145
137
        version_id = osutils.safe_revision_id(version_id)
146
138
        parents = [osutils.safe_revision_id(v) for v in parents]
147
139
        self._check_write_ok()
148
 
        return self._add_lines(version_id, parents, lines, parent_texts)
 
140
        return self._add_lines(version_id, parents, lines, parent_texts,
 
141
                               left_matching_blocks)
149
142
 
150
 
    def _add_lines(self, version_id, parents, lines, parent_texts):
 
143
    def _add_lines(self, version_id, parents, lines, parent_texts,
 
144
                   left_matching_blocks):
151
145
        """Helper to do the class specific add_lines."""
152
146
        raise NotImplementedError(self.add_lines)
153
147
 
298
292
        mpdiff.  mpdiff should be a MultiParent instance.
299
293
        """
300
294
        vf_parents = {}
301
 
        for version, parents, expected_sha1, mpdiff in records:
302
 
            mpvf = multiparent.MultiMemoryVersionedFile()
303
 
            needed_parents = [p for p in parents if not mpvf.has_version(p)]
304
 
            parent_lines = self._get_lf_split_line_list(needed_parents)
305
 
            for parent_id, lines in zip(needed_parents, parent_lines):
306
 
                mpvf.add_version(lines, parent_id, [])
307
 
            mpvf.add_diff(mpdiff, version, parents)
308
 
            lines = mpvf.get_line_list([version])[0]
309
 
            version_text = self.add_lines(version, parents, lines, vf_parents)
 
295
        mpvf = multiparent.MultiMemoryVersionedFile()
 
296
        versions = []
 
297
        for version, parent_ids, expected_sha1, mpdiff in records:
 
298
            versions.append(version)
 
299
            mpvf.add_diff(mpdiff, version, parent_ids)
 
300
        needed_parents = set()
 
301
        for version, parent_ids, expected_sha1, mpdiff in records:
 
302
            needed_parents.update(p for p in parent_ids
 
303
                                  if not mpvf.has_version(p))
 
304
        for parent_id, lines in zip(needed_parents,
 
305
                                 self._get_lf_split_line_list(needed_parents)):
 
306
            mpvf.add_version(lines, parent_id, [])
 
307
        for (version, parent_ids, expected_sha1, mpdiff), lines in\
 
308
            zip(records, mpvf.get_line_list(versions)):
 
309
            if len(parent_ids) == 1:
 
310
                left_matching_blocks = list(mpdiff.get_matching_blocks(0,
 
311
                    mpvf.get_diff(parent_ids[0]).num_lines()))
 
312
            else:
 
313
                left_matching_blocks = None
 
314
            version_text = self.add_lines(version, parent_ids, lines,
 
315
                vf_parents, left_matching_blocks=left_matching_blocks)
310
316
            vf_parents[version] = version_text
311
 
            if expected_sha1 != self.get_sha1(version):
 
317
        for (version, parent_ids, expected_sha1, mpdiff), sha1 in\
 
318
             zip(records, self.get_sha1s(versions)):
 
319
            if expected_sha1 != sha1:
312
320
                raise errors.VersionedFileInvalidChecksum(version)
313
321
 
314
322
    def get_sha1(self, version_id):
413
421
        """
414
422
        raise NotImplementedError(self.get_graph_with_ghosts)
415
423
 
416
 
    @deprecated_method(zero_eight)
417
 
    def parent_names(self, version):
418
 
        """Return version names for parents of a version.
419
 
        
420
 
        See get_parents for the current api.
421
 
        """
422
 
        return self.get_parents(version)
423
 
 
424
424
    def get_parents(self, version_id):
425
425
        """Return version names for parents of a version.
426
426
 
521
521
        """
522
522
        self.finished = True
523
523
 
524
 
    @deprecated_method(zero_eight)
525
 
    def walk(self, version_ids=None):
526
 
        """Walk the versioned file as a weave-like structure, for
527
 
        versions relative to version_ids.  Yields sequence of (lineno,
528
 
        insert, deletes, text) for each relevant line.
529
 
 
530
 
        Must raise RevisionNotPresent if any of the specified versions
531
 
        are not present in the file history.
532
 
 
533
 
        :param version_ids: the version_ids to walk with respect to. If not
534
 
                            supplied the entire weave-like structure is walked.
535
 
 
536
 
        walk is deprecated in favour of iter_lines_added_or_present_in_versions
537
 
        """
538
 
        raise NotImplementedError(self.walk)
539
 
 
540
 
    @deprecated_method(zero_eight)
541
 
    def iter_names(self):
542
 
        """Walk the names list."""
543
 
        return iter(self.versions())
544
 
 
545
524
    def plan_merge(self, ver_a, ver_b):
546
525
        """Return pseudo-annotation indicating how the two versions merge.
547
526