/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

  • Committer: John Carr
  • Date: 2009-01-13 20:26:54 UTC
  • mto: (0.217.53 git-serve)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: john.carr@unrouted.co.uk-20090113202654-9hsels0a9r35o7u0
Rename upload-pack and receive-pack so they don't clash with the Git versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
import os, tempfile
30
30
 
31
 
import stat
32
 
S_IFGITLINK = 0160000
33
 
 
34
 
#S_IFREG | 0664 # *Might* see this; would fail fsck --strict
35
 
 
 
31
# FIXME: Remove this in favor of something in the mapping...
 
32
_mode = -1
 
33
def get_umask():
 
34
    global _mode
 
35
    if _mode == -1:
 
36
        _mode = os.umask(0)
 
37
        os.umask(_mode)
 
38
    return _mode
36
39
 
37
40
class BzrBackend(Backend):
38
41
 
45
48
        ret = {}
46
49
        repo_dir = BzrDir.open(self.directory)
47
50
        repo = repo_dir.open_repository()
48
 
        branch = None
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())
55
54
        return ret
56
55
 
57
56
    def apply_pack(self, refs, read):
109
108
 
110
109
        repo = Repository.open(self.directory)
111
110
 
112
 
        objects = set()
113
 
 
114
111
        repo.lock_read()
115
112
        try:
116
113
            have = graph_walker.next()
130
127
 
131
128
                commits_to_send.update([p for p in rev.parent_ids if not p in rev_done])
132
129
 
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))
 
133
                        yield obj
137
134
 
138
 
                objects.add((mapping.export_commit(rev, sha), None))
 
135
                yield revision_to_commit(rev, self.mapping, sha)
139
136
 
140
137
        finally:
141
138
            repo.unlock()
142
139
 
143
 
        return (len(objects), iter(objects))
144
140
 
 
141
def revision_to_commit(rev, mapping, tree_sha):
 
142
    """
 
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:
 
146
    """
 
147
    commit = Commit()
 
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']
 
155
    else:
 
156
        commit._author = rev.committer
 
157
    commit._commit_time = rev.timestamp
 
158
    commit.serialize()
 
159
    print commit.sha().hexdigest()
 
160
    return commit
145
161
 
146
162
def inventory_to_tree_and_blobs(repo, mapping, revision_id):
147
163
    stack = []
154
170
        while stack and not path.startswith(cur):
155
171
            tree.serialize()
156
172
            sha = tree.sha().hexdigest()
157
 
            yield sha, tree, path
158
 
            t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
 
173
            yield sha, tree
 
174
            t = (get_umask(), splitpath(cur)[-1:][0].encode('UTF-8'), sha)
159
175
            cur, tree = stack.pop()
160
176
            tree.add(*t)
161
177
 
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
 
            mode = stat.S_IFREG | 0644
177
 
            if entry.executable:
178
 
                mode |= 0111
 
192
            mode = get_umask()
179
193
            tree.add(mode, name, sha)
180
194
 
181
195
    while len(stack) > 1:
182
196
        tree.serialize()
183
197
        sha = tree.sha().hexdigest()
184
 
        yield sha, tree, path
185
 
        t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
 
198
        yield sha, tree
 
199
        t = (get_umask(), splitpath(cur)[-1:][0].encode('UTF-8'), sha)
186
200
        cur, tree = stack.pop()
187
201
        tree.add(*t)
188
202
 
189
203
    tree.serialize()
190
 
    yield tree.sha().hexdigest(), tree, path
 
204
    yield tree.sha().hexdigest(), tree
191
205