46
49
repo_dir = BzrDir.open(self.directory)
47
50
repo = repo_dir.open_repository()
49
51
for branch in repo.find_branches(using=True):
50
#FIXME: Look for 'master' or 'trunk' in here, and set HEAD accordingly...
51
52
#FIXME: Need to get branch path relative to its repository and use this instead of nick
52
ret["refs/heads/"+branch.nick] = self.mapping.revision_id_bzr_to_foreign(branch.last_revision())[0]
53
if 'HEAD' not in ret and branch:
54
ret['HEAD'] = self.mapping.revision_id_bzr_to_foreign(branch.last_revision())[0]
53
ret["refs/heads/"+branch.nick] = self.mapping.revision_id_bzr_to_foreign(branch.last_revision())
57
56
def apply_pack(self, refs, read):
131
128
commits_to_send.update([p for p in rev.parent_ids if not p in rev_done])
133
for sha, obj, path in inventory_to_tree_and_blobs(repo, self.mapping, commit):
130
for sha, obj in inventory_to_tree_and_blobs(repo, self.mapping, commit):
134
131
if sha not in obj_sent:
135
132
obj_sent.add(sha)
136
objects.add((obj, path))
138
objects.add((mapping.export_commit(rev, sha), None))
135
yield revision_to_commit(rev, self.mapping, sha)
143
return (len(objects), iter(objects))
141
def revision_to_commit(rev, mapping, tree_sha):
143
Turn a Bazaar revision in to a Git commit
144
:param tree_sha: HACK parameter (until we can retrieve this from the mapping)
145
:return dulwich.objects.Commit represent the revision:
148
commit._tree = tree_sha
149
for p in rev.parent_ids:
150
commit._parents.append(mapping.revision_id_bzr_to_foreign(p))
151
commit._message = rev.message
152
commit._committer = rev.committer
153
if 'author' in rev.properties:
154
commit._author = rev.properties['author']
156
commit._author = rev.committer
157
commit._commit_time = rev.timestamp
159
print commit.sha().hexdigest()
146
162
def inventory_to_tree_and_blobs(repo, mapping, revision_id):
154
170
while stack and not path.startswith(cur):
156
172
sha = tree.sha().hexdigest()
157
yield sha, tree, path
158
t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
174
t = (get_umask(), splitpath(cur)[-1:][0].encode('UTF-8'), sha)
159
175
cur, tree = stack.pop()
171
187
_, blob._text = repo.iter_files_bytes([(entry.file_id, revision_id, path)]).next()
172
188
sha = blob.sha().hexdigest()
173
yield sha, blob, path
175
191
name = splitpath(path)[-1:][0].encode('UTF-8')
176
mode = stat.S_IFREG | 0644
179
193
tree.add(mode, name, sha)
181
195
while len(stack) > 1:
183
197
sha = tree.sha().hexdigest()
184
yield sha, tree, path
185
t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
199
t = (get_umask(), splitpath(cur)[-1:][0].encode('UTF-8'), sha)
186
200
cur, tree = stack.pop()
190
yield tree.sha().hexdigest(), tree, path
204
yield tree.sha().hexdigest(), tree