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

Partially fix pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Map from Git sha's to Bazaar objects."""
18
18
 
19
 
from dulwich.objects import (
20
 
    Blob,
21
 
    Tree,
22
 
    )
23
 
import stat
24
 
 
25
 
from bzrlib import (
26
 
    ui,
27
 
    )
 
19
import bzrlib
 
20
 
 
21
from bzrlib import ui
 
22
 
 
23
from bzrlib.errors import NoSuchRevision
28
24
 
29
25
from bzrlib.plugins.git.mapping import (
30
26
    inventory_to_tree_and_blobs,
31
27
    revision_to_commit,
32
28
    )
33
 
from bzrlib.plugins.git.shamap import (
34
 
    SqliteGitShaMap,
 
29
from bzrlib.plugins.git.shamap import GitShaMap
 
30
 
 
31
from dulwich.objects import (
 
32
    Blob,
35
33
    )
36
34
 
37
35
 
43
41
            self.mapping = self.repository.get_mapping()
44
42
        else:
45
43
            self.mapping = mapping
46
 
        self._idmap = SqliteGitShaMap(self.repository._transport)
 
44
        self._idmap = GitShaMap(self.repository._transport)
47
45
 
48
46
    def _update_sha_map(self):
49
47
        all_revids = self.repository.all_revision_ids()
57
55
                pb.update("updating git map", i, len(all_revids))
58
56
                self._update_sha_map_revision(revid)
59
57
        finally:
60
 
            self._idmap.commit()
61
58
            pb.finished()
62
59
 
63
60
    def _update_sha_map_revision(self, revid):
64
61
        inv = self.repository.get_inventory(revid)
65
 
        objects = inventory_to_tree_and_blobs(self.repository, self.mapping,
66
 
            revid)
 
62
        objects = inventory_to_tree_and_blobs(self.repository, self.mapping, revid)
67
63
        for sha, o, path in objects:
68
64
            if path == "":
69
65
                tree_sha = sha
70
66
            ie = inv[inv.path2id(path)]
71
67
            if ie.kind in ("file", "symlink"):
72
68
                self._idmap.add_entry(sha, "blob", (ie.file_id, ie.revision))
73
 
            elif ie.kind == "directory":
74
 
                self._idmap.add_entry(sha, "tree", (path, ie.revision))
75
69
            else:
76
 
                raise AssertionError()
 
70
                self._idmap.add_entry(sha, "tree", (ie.file_id, ie.revision))
77
71
        rev = self.repository.get_revision(revid)
78
 
        commit_obj = revision_to_commit(rev, tree_sha,
79
 
            self._idmap._parent_lookup)
80
 
        self._idmap.add_entry(commit_obj.sha().hexdigest(), "commit",
81
 
            (revid, tree_sha))
 
72
        commit_obj = revision_to_commit(rev, tree_sha, self._idmap._parent_lookup)
 
73
        self._idmap.add_entry(commit_obj.sha().hexdigest(), "commit", (revid, tree_sha))
82
74
 
83
75
    def _get_blob(self, fileid, revision):
84
 
        """Return a Git Blob object from a fileid and revision stored in bzr.
85
 
        
86
 
        :param fileid: File id of the text
87
 
        :param revision: Revision of the text
88
 
        """
89
 
        text = self.repository.texts.get_record_stream([(fileid, revision)],
90
 
            "unordered", True).next().get_bytes_as("fulltext")
 
76
        text = self.repository.texts.get_record_stream([(fileid, revision)], "unordered", True).next().get_bytes_as("fulltext")
91
77
        blob = Blob()
92
78
        blob._text = text
93
79
        return blob
94
80
 
95
 
    def _get_tree(self, path, revid, inv=None):
96
 
        """Return a Git Tree object from a path and a revision stored in bzr.
97
 
 
98
 
        :param path: path in the tree.
99
 
        :param revision: Revision of the tree.
100
 
        """
101
 
        if inv is None:
102
 
            inv = self.repository.get_inventory(revid)
103
 
        tree = Tree()
104
 
        fileid = inv.path2id(path)
105
 
        for name, ie in inv[fileid].children.iteritems():
106
 
            if ie.kind == "directory":
107
 
                subtree = self._get_tree(inv.id2path(ie.file_id), revid, inv)
108
 
                tree.add(stat.S_IFDIR, name.encode('UTF-8'),
109
 
                    subtree.sha().hexdigest())
110
 
            elif ie.kind == "file":
111
 
                blob = self._get_blob(ie.file_id, revid)
112
 
                mode = stat.S_IFREG | 0644
113
 
                if ie.executable:
114
 
                    mode |= 0111
115
 
                tree.add(mode, name.encode('UTF-8'), blob.sha().hexdigest())
116
 
            elif ie.kind == "symlink":
117
 
                raise AssertionError("Symlinks not yet supported")
118
 
        tree.serialize()
119
 
        return tree
 
81
    def _get_tree(self, fileid, revid):
 
82
        raise NotImplementedError(self._get_tree)
120
83
 
121
84
    def _get_commit(self, revid, tree_sha):
122
85
        rev = self.repository.get_revision(revid)