/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 object_store.py

Handle empty metadata.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from dulwich.objects import (
20
20
    Blob,
21
 
    Commit,
22
21
    Tree,
23
22
    sha_to_hex,
24
23
    )
36
35
from bzrlib.revision import (
37
36
    NULL_REVISION,
38
37
    )
39
 
from bzrlib.testament import(
40
 
    StrictTestament3,
41
 
    )
42
38
 
43
39
from bzrlib.plugins.git.mapping import (
44
40
    default_mapping,
342
338
        self._update_sha_map()
343
339
        return iter(self._cache.idmap.sha1s())
344
340
 
345
 
    def _reconstruct_commit(self, rev, tree_sha, roundtrip, verifiers):
346
 
        """Reconstruct a Commit object.
347
 
 
348
 
        :param rev: Revision object
349
 
        :param tree_sha: SHA1 of the root tree object
350
 
        :param roundtrip: Whether or not to roundtrip bzr metadata
351
 
        :param verifiers: Verifiers for the commits
352
 
        :return: Commit object
353
 
        """
 
341
    def _reconstruct_commit(self, rev, tree_sha, roundtrip):
354
342
        def parent_lookup(revid):
355
343
            try:
356
344
                return self._lookup_revision_sha1(revid)
357
345
            except errors.NoSuchRevision:
358
346
                return None
359
347
        return self.mapping.export_commit(rev, tree_sha, parent_lookup,
360
 
            roundtrip, verifiers)
 
348
            roundtrip)
361
349
 
362
350
    def _create_fileid_map_blob(self, inv):
363
351
        # FIXME: This can probably be a lot more efficient, 
402
390
                root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
403
391
                yield self.mapping.BZR_FILE_IDS_FILE, b, None
404
392
        yield "", root_tree, root_ie
405
 
        if roundtrip:
406
 
            testament3 = StrictTestament3(rev, tree.inventory)
407
 
            verifiers = { "testament3-sha1": testament3.as_sha1() }
408
 
        else:
409
 
            verifiers = {}
410
393
        commit_obj = self._reconstruct_commit(rev, root_tree.id,
411
 
            roundtrip=roundtrip, verifiers=verifiers)
 
394
            roundtrip=roundtrip)
412
395
        try:
413
396
            foreign_revid, mapping = mapping_registry.parse_revision_id(
414
397
                rev.revision_id)
427
410
        updater = self._get_updater(rev)
428
411
        for path, obj, ie in self._revision_to_objects(rev, tree,
429
412
            roundtrip=True):
430
 
            if isinstance(obj, Commit):
431
 
                testament3 = StrictTestament3(rev, tree.inventory)
432
 
                ie = { "testament3-sha1": testament3.as_sha1() }
433
413
            updater.add_object(obj, ie, path)
434
414
        commit_obj = updater.finish()
435
415
        return commit_obj.id
547
527
        ret = {}
548
528
        for sha in shas:
549
529
            if sha == ZERO_SHA:
550
 
                ret[sha] = ("commit", (NULL_REVISION, None, {}))
 
530
                ret[sha] = ("commit", (NULL_REVISION, None))
551
531
                continue
552
532
            try:
553
533
                ret[sha] = self._cache.idmap.lookup_git_sha(sha)
575
555
        (type, type_data) = self.lookup_git_sha(sha)
576
556
        # convert object to git object
577
557
        if type == "commit":
578
 
            (revid, tree_sha, verifiers) = type_data
 
558
            (revid, tree_sha) = type_data
579
559
            try:
580
560
                rev = self.repository.get_revision(revid)
581
561
            except errors.NoSuchRevision:
582
562
                trace.mutter('entry for %s %s in shamap: %r, but not found in '
583
563
                             'repository', type, sha, type_data)
584
564
                raise KeyError(sha)
585
 
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True,
586
 
                verifiers=verifiers)
 
565
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True)
587
566
            _check_expected_sha(sha, commit)
588
567
            return commit
589
568
        elif type == "blob":