/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 server.py

Return mapping in revision_id_bzr_to_foreign() as required by the interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        ret = {}
46
46
        repo_dir = BzrDir.open(self.directory)
47
47
        repo = repo_dir.open_repository()
48
 
        branch = None
49
48
        for branch in repo.find_branches(using=True):
50
 
            #FIXME: Look for 'master' or 'trunk' in here, and set HEAD accordingly...
51
49
            #FIXME: Need to get branch path relative to its repository and use this instead of nick
52
50
            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]
55
51
        return ret
56
52
 
57
53
    def apply_pack(self, refs, read):
130
126
 
131
127
                commits_to_send.update([p for p in rev.parent_ids if not p in rev_done])
132
128
 
133
 
                for sha, obj, path in inventory_to_tree_and_blobs(repo, self.mapping, commit):
 
129
                for sha, obj in inventory_to_tree_and_blobs(repo, self.mapping, commit):
134
130
                    if sha not in obj_sent:
135
131
                        obj_sent.add(sha)
136
 
                        objects.add((obj, path))
 
132
                        objects.add(obj)
137
133
 
138
 
                objects.add((mapping.export_commit(rev, sha), None))
 
134
                objects.add(revision_to_commit(rev, self.mapping, sha))
139
135
 
140
136
        finally:
141
137
            repo.unlock()
143
139
        return (len(objects), iter(objects))
144
140
 
145
141
 
 
142
def revision_to_commit(rev, mapping, tree_sha):
 
143
    """
 
144
    Turn a Bazaar revision in to a Git commit
 
145
    :param tree_sha: HACK parameter (until we can retrieve this from the mapping)
 
146
    :return dulwich.objects.Commit represent the revision:
 
147
    """
 
148
    commit = Commit()
 
149
    commit._tree = tree_sha
 
150
    for p in rev.parent_ids:
 
151
        commit._parents.append(mapping.revision_id_bzr_to_foreign(p)[0])
 
152
    commit._message = rev.message
 
153
    commit._committer = rev.committer
 
154
    if 'author' in rev.properties:
 
155
        commit._author = rev.properties['author']
 
156
    else:
 
157
        commit._author = rev.committer
 
158
    commit._commit_time = long(rev.timestamp)
 
159
    commit.serialize()
 
160
    return commit
 
161
 
146
162
def inventory_to_tree_and_blobs(repo, mapping, revision_id):
147
163
    stack = []
148
164
    cur = ""
154
170
        while stack and not path.startswith(cur):
155
171
            tree.serialize()
156
172
            sha = tree.sha().hexdigest()
157
 
            yield sha, tree, path
 
173
            yield sha, tree
158
174
            t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
159
175
            cur, tree = stack.pop()
160
176
            tree.add(*t)
170
186
            blob = Blob()
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
 
189
            yield sha, blob
174
190
 
175
191
            name = splitpath(path)[-1:][0].encode('UTF-8')
176
192
            mode = stat.S_IFREG | 0644
181
197
    while len(stack) > 1:
182
198
        tree.serialize()
183
199
        sha = tree.sha().hexdigest()
184
 
        yield sha, tree, path
 
200
        yield sha, tree
185
201
        t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
186
202
        cur, tree = stack.pop()
187
203
        tree.add(*t)
188
204
 
189
205
    tree.serialize()
190
 
    yield tree.sha().hexdigest(), tree, path
 
206
    yield tree.sha().hexdigest(), tree
191
207