/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

Add tests for generate_file_id.

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,
77
73
 
78
74
    def revision_tree(self, revid):
79
75
        try:
80
 
            tree = self._cache[revid]
 
76
            return self._cache[revid]
81
77
        except KeyError:
82
78
            tree = self.repository.revision_tree(revid)
83
79
            self.add(tree)
84
 
        assert tree.get_revision_id() == tree.inventory.revision_id
85
 
        return tree
 
80
            return tree
86
81
 
87
82
    def iter_revision_trees(self, revids):
88
 
        trees = {}
89
 
        todo = []
90
 
        for revid in revids:
91
 
            try:
92
 
                tree = self._cache[revid]
93
 
            except KeyError:
94
 
                todo.append(revid)
95
 
            else:
96
 
                assert tree.get_revision_id() == revid
97
 
                assert tree.inventory.revision_id == revid
98
 
                trees[revid] = tree
99
 
        for tree in self.repository.revision_trees(todo):
 
83
        trees = dict([(k, self._cache.get(k)) for k in revids]) 
 
84
        for tree in self.repository.revision_trees(
 
85
                [r for r, v in trees.iteritems() if v is None]):
100
86
            trees[tree.get_revision_id()] = tree
101
87
            self.add(tree)
102
88
        return (trees[r] for r in revids)
224
210
            new_trees[posixpath.dirname(path[1])] = parent[1]
225
211
        elif kind[1] not in (None, "directory"):
226
212
            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"):
 
213
        if path[0] is not None and parent[0] in tree.inventory and tree.inventory[parent[0]].kind == "directory":
230
214
            # Removal
231
215
            new_trees[posixpath.dirname(path[0])] = parent[0]
232
216
    
241
225
    for path in unusual_modes:
242
226
        parent_path = posixpath.dirname(path)
243
227
        new_trees[parent_path] = tree.path2id(parent_path)
244
 
 
 
228
    
245
229
    trees = {}
246
230
    while new_trees:
247
231
        items = new_trees.items()
342
326
        self._update_sha_map()
343
327
        return iter(self._cache.idmap.sha1s())
344
328
 
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
 
        """
 
329
    def _reconstruct_commit(self, rev, tree_sha, roundtrip):
354
330
        def parent_lookup(revid):
355
331
            try:
356
332
                return self._lookup_revision_sha1(revid)
357
333
            except errors.NoSuchRevision:
358
334
                return None
359
335
        return self.mapping.export_commit(rev, tree_sha, parent_lookup,
360
 
            roundtrip, verifiers)
 
336
            roundtrip)
361
337
 
362
338
    def _create_fileid_map_blob(self, inv):
363
339
        # FIXME: This can probably be a lot more efficient, 
402
378
                root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
403
379
                yield self.mapping.BZR_FILE_IDS_FILE, b, None
404
380
        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
381
        commit_obj = self._reconstruct_commit(rev, root_tree.id,
411
 
            roundtrip=roundtrip, verifiers=verifiers)
 
382
            roundtrip=roundtrip)
412
383
        try:
413
384
            foreign_revid, mapping = mapping_registry.parse_revision_id(
414
385
                rev.revision_id)
427
398
        updater = self._get_updater(rev)
428
399
        for path, obj, ie in self._revision_to_objects(rev, tree,
429
400
            roundtrip=True):
430
 
            if isinstance(obj, Commit):
431
 
                testament3 = StrictTestament3(rev, tree.inventory)
432
 
                ie = { "testament3-sha1": testament3.as_sha1() }
433
401
            updater.add_object(obj, ie, path)
434
402
        commit_obj = updater.finish()
435
403
        return commit_obj.id
547
515
        ret = {}
548
516
        for sha in shas:
549
517
            if sha == ZERO_SHA:
550
 
                ret[sha] = ("commit", (NULL_REVISION, None, {}))
 
518
                ret[sha] = NULL_REVISION
551
519
                continue
552
520
            try:
553
521
                ret[sha] = self._cache.idmap.lookup_git_sha(sha)
575
543
        (type, type_data) = self.lookup_git_sha(sha)
576
544
        # convert object to git object
577
545
        if type == "commit":
578
 
            (revid, tree_sha, verifiers) = type_data
 
546
            (revid, tree_sha) = type_data
579
547
            try:
580
548
                rev = self.repository.get_revision(revid)
581
549
            except errors.NoSuchRevision:
582
550
                trace.mutter('entry for %s %s in shamap: %r, but not found in '
583
551
                             'repository', type, sha, type_data)
584
552
                raise KeyError(sha)
585
 
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True,
586
 
                verifiers=verifiers)
 
553
            commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True)
587
554
            _check_expected_sha(sha, commit)
588
555
            return commit
589
556
        elif type == "blob":