171
170
def get_revision(self, revision_id):
172
171
git_commit_id = self.lookup_git_revid(revision_id, self.get_mapping())
174
commit = self._git.commit(git_commit_id)
172
commit = self._git.commit(git_commit_id)
173
# print "fetched revision:", git_commit_id
176
175
raise errors.NoSuchRevision(self, revision_id)
177
# print "fetched revision:", git_commit_id
178
revision = self.get_mapping().import_commit(commit)
176
revision = self._parse_rev(commit, self.get_mapping())
179
177
assert revision is not None
190
188
def get_revisions(self, revids):
191
189
return [self.get_revision(r) for r in revids]
192
def _parse_rev(klass, commit, mapping):
193
"""Convert a git commit to a bzr revision.
195
:return: a `bzrlib.revision.Revision` object.
198
raise AssertionError("Commit object can't be None")
199
rev = ForeignRevision(commit.id, mapping, mapping.revision_id_foreign_to_bzr(commit.id))
200
rev.parent_ids = tuple([mapping.revision_id_foreign_to_bzr(p) for p in commit.parents])
201
rev.message = commit.message.decode("utf-8", "replace")
202
rev.committer = str(commit.committer).decode("utf-8", "replace")
203
if commit.committer != commit.author:
204
rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
205
rev.timestamp = commit.commit_time
193
209
def revision_trees(self, revids):
194
210
for revid in revids:
195
211
yield self.revision_tree(revid)
202
218
inv.revision_id = revision_id
203
219
return revisiontree.RevisionTree(self, inv, revision_id)
205
return GitRevisionTree(self, self.get_mapping(), revision_id)
221
return GitRevisionTree(self, revision_id)
207
223
def get_inventory(self, revision_id):
208
224
assert revision_id != None
211
227
def set_make_working_trees(self, trees):
214
def fetch_objects(self, determine_wants, graph_walker, progress=None):
215
return self._git.fetch_objects(determine_wants, graph_walker, progress)
230
def fetch_objects(self, determine_wants, graph_walker, pack_data):
231
raise NotImplementedError(self.fetch_objects)
234
def escape_file_id(file_id):
235
return file_id.replace('_', '__').replace(' ', '_s')
238
def unescape_file_id(file_id):
239
return file_id.replace("_s", " ").replace("__", "_")
218
242
class GitRevisionTree(revisiontree.RevisionTree):
220
def __init__(self, repository, mapping, revision_id):
244
def __init__(self, repository, revision_id):
221
245
self._repository = repository
222
246
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
247
git_id = repository.lookup_git_revid(revision_id, repository.get_mapping())
248
self.tree = repository._git.commit(git_id).tree
231
249
self._inventory = inventory.Inventory(revision_id=revision_id)
232
250
self._inventory.root.revision = revision_id
233
251
self._build_inventory(self.tree, self._inventory.root, "")
249
267
child_path = name
251
269
child_path = urlutils.join(path, name)
252
file_id = self.mapping.generate_file_id(child_path)
270
file_id = escape_file_id(child_path.encode('utf-8'))
253
271
entry_kind = (mode & 0700000) / 0100000
254
272
if entry_kind == 0:
255
273
child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)