/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

Support 'add' in empty directory.

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,
224
220
            new_trees[posixpath.dirname(path[1])] = parent[1]
225
221
        elif kind[1] not in (None, "directory"):
226
222
            raise AssertionError(kind[1])
227
 
        if (path[0] not in (None, "") and
228
 
            parent[0] in tree.inventory and
229
 
            tree.inventory[parent[0]].kind == "directory"):
 
223
        if path[0] is not None and parent[0] in tree.inventory and tree.inventory[parent[0]].kind == "directory":
230
224
            # Removal
231
225
            new_trees[posixpath.dirname(path[0])] = parent[0]
232
226
    
342
336
        self._update_sha_map()
343
337
        return iter(self._cache.idmap.sha1s())
344
338
 
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
 
        """
 
339
    def _reconstruct_commit(self, rev, tree_sha, roundtrip):
354
340
        def parent_lookup(revid):
355
341
            try:
356
342
                return self._lookup_revision_sha1(revid)
357
343
            except errors.NoSuchRevision:
358
344
                return None
359
345
        return self.mapping.export_commit(rev, tree_sha, parent_lookup,
360
 
            roundtrip, verifiers)
 
346
            roundtrip)
361
347
 
362
348
    def _create_fileid_map_blob(self, inv):
363
349
        # FIXME: This can probably be a lot more efficient, 
402
388
                root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
403
389
                yield self.mapping.BZR_FILE_IDS_FILE, b, None
404
390
        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
391
        commit_obj = self._reconstruct_commit(rev, root_tree.id,
411
 
            roundtrip=roundtrip, verifiers=verifiers)
 
392
            roundtrip=roundtrip)
412
393
        try:
413
394
            foreign_revid, mapping = mapping_registry.parse_revision_id(
414
395
                rev.revision_id)
427
408
        updater = self._get_updater(rev)
428
409
        for path, obj, ie in self._revision_to_objects(rev, tree,
429
410
            roundtrip=True):
430
 
            if isinstance(obj, Commit):
431
 
                testament3 = StrictTestament3(rev, tree.inventory)
432
 
                ie = { "testament3-sha1": testament3.as_sha1() }
433
411
            updater.add_object(obj, ie, path)
434
412
        commit_obj = updater.finish()
435
413
        return commit_obj.id
547
525
        ret = {}
548
526
        for sha in shas:
549
527
            if sha == ZERO_SHA:
550
 
                ret[sha] = ("commit", (NULL_REVISION, None, {}))
 
528
                ret[sha] = ("commit", (NULL_REVISION, None))
551
529
                continue
552
530
            try:
553
531
                ret[sha] = self._cache.idmap.lookup_git_sha(sha)
575
553
        (type, type_data) = self.lookup_git_sha(sha)
576
554
        # convert object to git object
577
555
        if type == "commit":
578
 
            (revid, tree_sha, verifiers) = type_data
 
556
            (revid, tree_sha) = type_data
579
557
            try:
580
558
                rev = self.repository.get_revision(revid)
581
559
            except errors.NoSuchRevision:
582
560
                trace.mutter('entry for %s %s in shamap: %r, but not found in '
583
561
                             'repository', type, sha, type_data)
584
562
                raise KeyError(sha)
585
 
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True,
586
 
                verifiers=verifiers)
 
563
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True)
587
564
            _check_expected_sha(sha, commit)
588
565
            return commit
589
566
        elif type == "blob":