/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Aaron Bentley
  • Date: 2007-08-15 01:11:27 UTC
  • mfrom: (2699 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2700.
  • Revision ID: aaron.bentley@utoronto.ca-20070815011127-0il5s8oqmt26bma7
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
            new_full[-1] = new_full[-1][:-1]
126
126
        self.add_lines(version_id, parents, new_full)
127
127
 
128
 
    def add_lines(self, version_id, parents, lines, parent_texts=None):
 
128
    def add_lines(self, version_id, parents, lines, parent_texts=None,
 
129
                  left_matching_blocks=None):
129
130
        """Add a single text on top of the versioned file.
130
131
 
131
132
        Must raise RevisionAlreadyPresent if the new version is
138
139
             version_id to allow delta optimisations. 
139
140
             VERY IMPORTANT: the texts must be those returned
140
141
             by add_lines or data corruption can be caused.
 
142
        :param left_matching_blocks: a hint about which areas are common
 
143
            between the text and its left-hand-parent.  The format is
 
144
            the SequenceMatcher.get_matching_blocks format.
141
145
        :return: An opaque representation of the inserted version which can be
142
146
                 provided back to future add_lines calls in the parent_texts
143
147
                 dictionary.
145
149
        version_id = osutils.safe_revision_id(version_id)
146
150
        parents = [osutils.safe_revision_id(v) for v in parents]
147
151
        self._check_write_ok()
148
 
        return self._add_lines(version_id, parents, lines, parent_texts)
 
152
        return self._add_lines(version_id, parents, lines, parent_texts,
 
153
                               left_matching_blocks)
149
154
 
150
 
    def _add_lines(self, version_id, parents, lines, parent_texts):
 
155
    def _add_lines(self, version_id, parents, lines, parent_texts,
 
156
                   left_matching_blocks):
151
157
        """Helper to do the class specific add_lines."""
152
158
        raise NotImplementedError(self.add_lines)
153
159
 
298
304
        mpdiff.  mpdiff should be a MultiParent instance.
299
305
        """
300
306
        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)
 
307
        mpvf = multiparent.MultiMemoryVersionedFile()
 
308
        versions = []
 
309
        for version, parent_ids, expected_sha1, mpdiff in records:
 
310
            versions.append(version)
 
311
            mpvf.add_diff(mpdiff, version, parent_ids)
 
312
        needed_parents = set()
 
313
        for version, parent_ids, expected_sha1, mpdiff in records:
 
314
            needed_parents.update(p for p in parent_ids
 
315
                                  if not mpvf.has_version(p))
 
316
        for parent_id, lines in zip(needed_parents,
 
317
                                 self._get_lf_split_line_list(needed_parents)):
 
318
            mpvf.add_version(lines, parent_id, [])
 
319
        for (version, parent_ids, expected_sha1, mpdiff), lines in\
 
320
            zip(records, mpvf.get_line_list(versions)):
 
321
            if len(parent_ids) == 1:
 
322
                left_matching_blocks = list(mpdiff.get_matching_blocks(0,
 
323
                    mpvf.get_diff(parent_ids[0]).num_lines()))
 
324
            else:
 
325
                left_matching_blocks = None
 
326
            version_text = self.add_lines(version, parent_ids, lines,
 
327
                vf_parents, left_matching_blocks=left_matching_blocks)
310
328
            vf_parents[version] = version_text
311
 
            if expected_sha1 != self.get_sha1(version):
 
329
        for (version, parent_ids, expected_sha1, mpdiff), sha1 in\
 
330
             zip(records, self.get_sha1s(versions)):
 
331
            if expected_sha1 != sha1:
312
332
                raise errors.VersionedFileInvalidChecksum(version)
313
333
 
314
334
    def get_sha1(self, version_id):