~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-17 09:40:51 UTC
  • mfrom: (3518.1.2 virtualvf)
  • Revision ID: pqm@pqm.ubuntu.com-20080717094051-cgyo1zagozwcd4mm
(Jelmer) Add VirtualVersionedFiles class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1323
1323
        PlanWeaveMerge.__init__(self, plan, a_marker, b_marker)
1324
1324
 
1325
1325
 
 
1326
class VirtualVersionedFiles(VersionedFiles):
 
1327
    """Dummy implementation for VersionedFiles that uses other functions for 
 
1328
    obtaining fulltexts and parent maps.
 
1329
 
 
1330
    This is always on the bottom of the stack and uses string keys 
 
1331
    (rather than tuples) internally.
 
1332
    """
 
1333
 
 
1334
    def __init__(self, get_parent_map, get_lines):
 
1335
        """Create a VirtualVersionedFiles.
 
1336
 
 
1337
        :param get_parent_map: Same signature as Repository.get_parent_map.
 
1338
        :param get_lines: Should return lines for specified key or None if 
 
1339
                          not available.
 
1340
        """
 
1341
        super(VirtualVersionedFiles, self).__init__()
 
1342
        self._get_parent_map = get_parent_map
 
1343
        self._get_lines = get_lines
 
1344
        
 
1345
    def check(self, progressbar=None):
 
1346
        """See VersionedFiles.check.
 
1347
 
 
1348
        :note: Always returns True for VirtualVersionedFiles.
 
1349
        """
 
1350
        return True
 
1351
 
 
1352
    def add_mpdiffs(self, records):
 
1353
        """See VersionedFiles.mpdiffs.
 
1354
 
 
1355
        :note: Not implemented for VirtualVersionedFiles.
 
1356
        """
 
1357
        raise NotImplementedError(self.add_mpdiffs)
 
1358
 
 
1359
    def get_parent_map(self, keys):
 
1360
        """See VersionedFiles.get_parent_map."""
 
1361
        return dict([((k,), tuple([(p,) for p in v]))
 
1362
            for k,v in self._get_parent_map([k for (k,) in keys]).iteritems()])
 
1363
 
 
1364
    def get_sha1s(self, keys):
 
1365
        """See VersionedFiles.get_sha1s."""
 
1366
        ret = {}
 
1367
        for (k,) in keys:
 
1368
            lines = self._get_lines(k)
 
1369
            if lines is not None:
 
1370
                if not isinstance(lines, list):
 
1371
                    raise AssertionError
 
1372
                ret[(k,)] = osutils.sha_strings(lines)
 
1373
        return ret
 
1374
 
 
1375
    def get_record_stream(self, keys, ordering, include_delta_closure):
 
1376
        """See VersionedFiles.get_record_stream."""
 
1377
        for (k,) in list(keys):
 
1378
            lines = self._get_lines(k)
 
1379
            if lines is not None:
 
1380
                if not isinstance(lines, list):
 
1381
                    raise AssertionError
 
1382
                yield FulltextContentFactory((k,), None, 
 
1383
                        sha1=osutils.sha_strings(lines),
 
1384
                        text=''.join(lines))
 
1385
            else:
 
1386
                yield AbsentContentFactory((k,))
 
1387
 
 
1388
 
 
1389