31
from bzrlib.inventory import Inventory
32
from bzrlib.repository import InterRepository
33
from bzrlib.trace import info
36
from bzrlib.inventory import (
39
from bzrlib.repository import (
34
42
from bzrlib.tsort import topo_sort
44
from bzrlib.plugins.git.converter import (
36
47
from bzrlib.plugins.git.repository import (
41
from bzrlib.plugins.git.converter import GitObjectConverter
42
from bzrlib.plugins.git.remote import RemoteGitRepository
52
from bzrlib.plugins.git.remote import (
46
57
class BzrFetchGraphWalker(object):
85
def import_git_blob(repo, mapping, path, blob, inv, parent_invs, gitmap, executable):
96
def import_git_blob(texts, mapping, path, blob, inv, parent_invs, gitmap,
86
98
"""Import a git blob object into a bzr repository.
88
:param repo: bzr repository
100
:param texts: VersionedFiles to add to
89
101
:param path: Path in the tree
90
102
:param blob: A git blob
92
104
file_id = mapping.generate_file_id(path)
93
105
text_revision = inv.revision_id
94
repo.texts.add_lines((file_id, text_revision),
106
texts.add_lines((file_id, text_revision),
95
107
[(file_id, p[file_id].revision) for p in parent_invs if file_id in p],
96
108
osutils.split_lines(blob.data))
97
109
ie = inv.add_path(path, "file", file_id)
99
111
ie.text_size = len(blob.data)
100
112
ie.text_sha1 = osutils.sha_string(blob.data)
101
113
ie.executable = executable
102
gitmap._idmap.add_entry(blob.sha().hexdigest(), "blob", (ie.file_id, ie.revision))
105
def import_git_tree(repo, mapping, path, tree, inv, parent_invs,
106
gitmap, lookup_object):
114
gitmap._idmap.add_entry(blob.sha().hexdigest(), "blob",
115
(ie.file_id, ie.revision))
118
def import_git_tree(texts, mapping, path, tree, inv, parent_invs, gitmap,
107
120
"""Import a git tree object into a bzr repository.
109
:param repo: A Bzr repository object
122
:param texts: VersionedFiles object to add to
110
123
:param path: Path in the tree
111
124
:param tree: A git tree object
112
125
:param inv: Inventory object
114
127
file_id = mapping.generate_file_id(path)
115
128
text_revision = inv.revision_id
116
repo.texts.add_lines((file_id, text_revision),
129
texts.add_lines((file_id, text_revision),
117
130
[(file_id, p[file_id].revision) for p in parent_invs if file_id in p],
119
132
ie = inv.add_path(path, "directory", file_id)
120
133
ie.revision = text_revision
121
gitmap._idmap.add_entry(tree.sha().hexdigest(), "tree", (file_id, text_revision))
134
gitmap._idmap.add_entry(tree.sha().hexdigest(), "tree",
135
(file_id, text_revision))
122
136
for mode, name, hexsha in tree.entries():
123
137
entry_kind = (mode & 0700000) / 0100000
124
138
basename = name.decode("utf-8")
128
142
child_path = urlutils.join(path, name)
129
143
if entry_kind == 0:
130
144
tree = lookup_object(hexsha)
131
import_git_tree(repo, mapping, child_path, tree, inv, parent_invs, gitmap, lookup_object)
145
import_git_tree(texts, mapping, child_path, tree, inv,
146
parent_invs, gitmap, lookup_object)
132
147
elif entry_kind == 1:
133
148
blob = lookup_object(hexsha)
134
149
fs_mode = mode & 0777
135
import_git_blob(repo, mapping, child_path, blob, inv, parent_invs, gitmap, bool(fs_mode & 0111))
150
import_git_blob(texts, mapping, child_path, blob, inv,
151
parent_invs, gitmap, bool(fs_mode & 0111))
137
153
raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
156
172
root_trees[rev.revision_id] = object_iter[o.tree]
157
173
revisions[rev.revision_id] = rev
158
174
graph.append((rev.revision_id, rev.parent_ids))
159
target_git_object_retriever._idmap.add_entry(o.sha().hexdigest(), "commit", (rev.revision_id, o._tree))
175
target_git_object_retriever._idmap.add_entry(o.sha().hexdigest(),
176
"commit", (rev.revision_id, o._tree))
160
177
# Order the revisions
161
178
# Create the inventory objects
162
179
for i, revid in enumerate(topo_sort(graph)):
174
191
return object_iter[sha]
175
192
return target_git_object_retriever[sha]
176
193
parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
177
import_git_tree(repo, mapping, "", root_tree, inv, parent_invs,
194
import_git_tree(repo.texts, mapping, "", root_tree, inv, parent_invs,
178
195
target_git_object_retriever, lookup_object)
179
196
repo.add_revision(rev.revision_id, rev, inv)