/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

Add basic infrastructure for dpush.

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
48
49
        for branch in repo.find_branches(using=True):
 
50
            #FIXME: Look for 'master' or 'trunk' in here, and set HEAD accordingly...
49
51
            #FIXME: Need to get branch path relative to its repository and use this instead of nick
50
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]
51
55
        return ret
52
56
 
53
57
    def apply_pack(self, refs, read):
126
130
 
127
131
                commits_to_send.update([p for p in rev.parent_ids if not p in rev_done])
128
132
 
129
 
                for sha, obj in inventory_to_tree_and_blobs(repo, self.mapping, commit):
 
133
                for sha, obj, path in inventory_to_tree_and_blobs(repo, self.mapping, commit):
130
134
                    if sha not in obj_sent:
131
135
                        obj_sent.add(sha)
132
 
                        objects.add(obj)
 
136
                        objects.add((obj, path))
133
137
 
134
 
                objects.add(revision_to_commit(rev, self.mapping, sha))
 
138
                objects.add((mapping.export_commit(rev, sha), None))
135
139
 
136
140
        finally:
137
141
            repo.unlock()
139
143
        return (len(objects), iter(objects))
140
144
 
141
145
 
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
 
 
162
146
def inventory_to_tree_and_blobs(repo, mapping, revision_id):
163
147
    stack = []
164
148
    cur = ""
170
154
        while stack and not path.startswith(cur):
171
155
            tree.serialize()
172
156
            sha = tree.sha().hexdigest()
173
 
            yield sha, tree
 
157
            yield sha, tree, path
174
158
            t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
175
159
            cur, tree = stack.pop()
176
160
            tree.add(*t)
186
170
            blob = Blob()
187
171
            _, blob._text = repo.iter_files_bytes([(entry.file_id, revision_id, path)]).next()
188
172
            sha = blob.sha().hexdigest()
189
 
            yield sha, blob
 
173
            yield sha, blob, path
190
174
 
191
175
            name = splitpath(path)[-1:][0].encode('UTF-8')
192
176
            mode = stat.S_IFREG | 0644
197
181
    while len(stack) > 1:
198
182
        tree.serialize()
199
183
        sha = tree.sha().hexdigest()
200
 
        yield sha, tree
 
184
        yield sha, tree, path
201
185
        t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
202
186
        cur, tree = stack.pop()
203
187
        tree.add(*t)
204
188
 
205
189
    tree.serialize()
206
 
    yield tree.sha().hexdigest(), tree
 
190
    yield tree.sha().hexdigest(), tree, path
207
191