/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: Martin Pool
  • Date: 2008-07-21 07:48:30 UTC
  • mfrom: (3564 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3566.
  • Revision ID: mbp@sourcefrog.net-20080721074830-i1pgj2hswpfo6pav
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
893
893
                knit_keys.update(parent_keys)
894
894
        missing_keys = keys - set(parent_map)
895
895
        if missing_keys:
896
 
            raise errors.RevisionNotPresent(missing_keys.pop(), self)
 
896
            raise errors.RevisionNotPresent(list(missing_keys)[0], self)
897
897
        # We need to filter out ghosts, because we can't diff against them.
898
898
        maybe_ghosts = knit_keys - keys
899
899
        ghosts = maybe_ghosts - set(self.get_parent_map(maybe_ghosts))
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