176
177
raise errors.NoSuchRevision(self, revision_id)
177
178
# print "fetched revision:", git_commit_id
178
revision = self.get_mapping().import_commit(commit)
179
revision = self._parse_rev(commit, self.get_mapping())
179
180
assert revision is not None
190
191
def get_revisions(self, revids):
191
192
return [self.get_revision(r) for r in revids]
195
def _parse_rev(klass, commit, mapping):
196
"""Convert a git commit to a bzr revision.
198
:return: a `bzrlib.revision.Revision` object.
201
raise AssertionError("Commit object can't be None")
202
rev = ForeignRevision(commit.id, mapping, mapping.revision_id_foreign_to_bzr(commit.id))
203
rev.parent_ids = tuple([mapping.revision_id_foreign_to_bzr(p) for p in commit.parents])
204
rev.message = commit.message.decode("utf-8", "replace")
205
rev.committer = str(commit.committer).decode("utf-8", "replace")
206
if commit.committer != commit.author:
207
rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
208
rev.timestamp = commit.commit_time
193
212
def revision_trees(self, revids):
194
213
for revid in revids:
195
214
yield self.revision_tree(revid)
202
221
inv.revision_id = revision_id
203
222
return revisiontree.RevisionTree(self, inv, revision_id)
205
return GitRevisionTree(self, self.get_mapping(), revision_id)
224
return GitRevisionTree(self, revision_id)
207
226
def get_inventory(self, revision_id):
208
227
assert revision_id != None
215
234
return self._git.fetch_objects(determine_wants, graph_walker, progress)
237
def escape_file_id(file_id):
238
return file_id.replace('_', '__').replace(' ', '_s')
241
def unescape_file_id(file_id):
242
return file_id.replace("_s", " ").replace("__", "_")
218
245
class GitRevisionTree(revisiontree.RevisionTree):
220
def __init__(self, repository, mapping, revision_id):
247
def __init__(self, repository, revision_id):
221
248
self._repository = repository
222
249
self.revision_id = revision_id
223
assert isinstance(revision_id, str)
224
self.mapping = mapping
225
git_id = repository.lookup_git_revid(revision_id, self.mapping)
227
commit = repository._git.commit(git_id)
229
raise errors.NoSuchRevision(repository, revision_id)
230
self.tree = commit.tree
250
git_id = repository.lookup_git_revid(revision_id, repository.get_mapping())
251
self.tree = repository._git.commit(git_id).tree
231
252
self._inventory = inventory.Inventory(revision_id=revision_id)
232
253
self._inventory.root.revision = revision_id
233
254
self._build_inventory(self.tree, self._inventory.root, "")
249
270
child_path = name
251
272
child_path = urlutils.join(path, name)
252
file_id = self.mapping.generate_file_id(child_path)
273
file_id = escape_file_id(child_path.encode('utf-8'))
253
274
entry_kind = (mode & 0700000) / 0100000
254
275
if entry_kind == 0:
255
276
child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)