/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

Implement Tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Map from Git sha's to Bazaar objects."""
18
18
 
 
19
import stat
 
20
 
19
21
import bzrlib
20
 
 
21
22
from bzrlib import ui
22
 
 
23
23
from bzrlib.errors import NoSuchRevision
24
24
 
25
25
from bzrlib.plugins.git.mapping import (
30
30
 
31
31
from dulwich.objects import (
32
32
    Blob,
 
33
    Tree,
33
34
    )
34
35
 
35
36
 
86
87
        blob._text = text
87
88
        return blob
88
89
 
89
 
    def _get_tree(self, path, revid):
90
 
        raise NotImplementedError(self._get_tree)
 
90
    def _get_tree(self, path, revid, inv=None):
 
91
        """Return a Git Tree object from a path and a revision stored in bzr.
 
92
 
 
93
        :param path: path in the tree.
 
94
        :param revision: Revision of the tree.
 
95
        """
 
96
        if inv is None:
 
97
            inv = self.repository.get_inventory(revid)
 
98
        tree = Tree()
 
99
        fileid = inv.path2id(path)
 
100
        for name, ie in inv[fileid].children.iteritems():
 
101
            if ie.kind == "directory":
 
102
                subtree = self._get_tree(inv.id2path(ie.file_id), revid, inv)
 
103
                tree.add(stat.S_IFDIR, name.encode('UTF-8'), subtree.sha().hexdigest())
 
104
            elif ie.kind == "file":
 
105
                blob = self._get_blob(inv.path2id(ie.file_id), revid)
 
106
                mode = stat.S_IFREG | 0644
 
107
                if ie.executable:
 
108
                    mode |= 0111
 
109
                tree.add(mode, name.encode('UTF-8'), blob.sha().hexdigest())
 
110
            elif ie.kind == "symlink":
 
111
                raise AssertionError("Symlinks not yet supported")
 
112
        tree.serialize()
 
113
        return tree
91
114
 
92
115
    def _get_commit(self, revid, tree_sha):
93
116
        rev = self.repository.get_revision(revid)