~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Robert Collins
  • Date: 2007-07-25 00:52:21 UTC
  • mfrom: (2650 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2651.
  • Revision ID: robertc@robertcollins.net-20070725005221-0ysm6il5mqnme3wz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib import (
26
26
    errors,
27
27
    osutils,
 
28
    multiparent,
28
29
    tsort,
29
30
    revision,
30
31
    ui,
32
33
from bzrlib.transport.memory import MemoryTransport
33
34
""")
34
35
 
 
36
from cStringIO import StringIO
 
37
 
35
38
from bzrlib.inter import InterObject
36
39
from bzrlib.textmerge import TextMerge
37
40
from bzrlib.symbol_versioning import (deprecated_function,
264
267
            result[version_id] = self.get_delta(version_id)
265
268
        return result
266
269
 
 
270
    def make_mpdiffs(self, version_ids):
 
271
        """Create multiparent diffs for specified versions"""
 
272
        knit_versions = set()
 
273
        for version_id in version_ids:
 
274
            knit_versions.add(version_id)
 
275
            knit_versions.update(self.get_parents(version_id))
 
276
        lines = dict(zip(knit_versions,
 
277
            self._get_lf_split_line_list(knit_versions)))
 
278
        diffs = []
 
279
        for version_id in version_ids:
 
280
            target = lines[version_id]
 
281
            parents = [lines[p] for p in self.get_parents(version_id)]
 
282
            if len(parents) > 0:
 
283
                left_parent_blocks = self._extract_blocks(version_id,
 
284
                                                          parents[0], target)
 
285
            else:
 
286
                left_parent_blocks = None
 
287
            diffs.append(multiparent.MultiParent.from_lines(target, parents,
 
288
                         left_parent_blocks))
 
289
        return diffs
 
290
 
 
291
    def _extract_blocks(self, version_id, source, target):
 
292
        return None
 
293
 
 
294
    def add_mpdiffs(self, records):
 
295
        """Add mpdiffs to this versionedfile
 
296
 
 
297
        Records should be iterables of version, parents, expected_sha1,
 
298
        mpdiff.  mpdiff should be a MultiParent instance.
 
299
        """
 
300
        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)
 
310
            vf_parents[version] = version_text
 
311
            if expected_sha1 != self.get_sha1(version):
 
312
                raise errors.VersionedFileInvalidChecksum(version)
 
313
 
267
314
    def get_sha1(self, version_id):
268
315
        """Get the stored sha1 sum for the given revision.
269
316
        
271
318
        """
272
319
        raise NotImplementedError(self.get_sha1)
273
320
 
 
321
    def get_sha1s(self, version_ids):
 
322
        """Get the stored sha1 sums for the given revisions.
 
323
 
 
324
        :param version_ids: The names of the versions to lookup
 
325
        :return: a list of sha1s in order according to the version_ids
 
326
        """
 
327
        raise NotImplementedError(self.get_sha1)
 
328
 
274
329
    def get_suffixes(self):
275
330
        """Return the file suffixes associated with this versioned file."""
276
331
        raise NotImplementedError(self.get_suffixes)
300
355
        """
301
356
        raise NotImplementedError(self.get_lines)
302
357
 
 
358
    def _get_lf_split_line_list(self, version_ids):
 
359
        return [StringIO(t).readlines() for t in self.get_texts(version_ids)]
 
360
 
303
361
    def get_ancestry(self, version_ids, topo_sorted=True):
304
362
        """Return a list of all ancestors of given version(s). This
305
363
        will not include the null revision.