/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

Check types of file ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 Jelmer Vernooij
 
2
# Copyright (C) 2008 John Carr
1
3
# Copyright (C) 2008 Canonical Ltd
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
18
20
import tempfile
19
21
 
20
22
from dulwich.server import TCPGitServer
21
 
import os
22
23
 
23
24
from bzrlib.bzrdir import (
24
25
    BzrDir,
47
48
    PackData,
48
49
    write_pack_index_v2,
49
50
    )
50
 
 
 
51
from dulwich.objects import (
 
52
    ShaFile,
 
53
    sha_to_hex,
 
54
    hex_to_sha,
 
55
    )
51
56
 
52
57
class BzrBackend(Backend):
53
58
 
75
80
        return ret
76
81
 
77
82
    def apply_pack(self, refs, read):
78
 
        """ apply pack from client to current repository """
 
83
        """apply pack from client to current repository"""
79
84
 
80
85
        fd, path = tempfile.mkstemp(suffix=".pack")
81
86
        f = os.fdopen(fd, 'w')
84
89
 
85
90
        p = PackData(path)
86
91
        entries = p.sorted_entries()
 
92
        heads = []
 
93
        for e in entries:
 
94
            sha = e[0]
 
95
            offset = e[1]
 
96
            t, o = p.get_object_at (offset)
 
97
            if t == 1 or t == 4:
 
98
                heads.append(sha)
87
99
        write_pack_index_v2(path[:-5]+".idx", entries, p.calculate_checksum())
88
100
 
89
 
        def get_objects():
90
 
            pack = Pack(path[:-5])
91
 
            for obj in pack.iterobjects():
92
 
                yield obj
 
101
        repo_dir = BzrDir.open_from_transport(self.transport)
 
102
        target = repo_dir.find_repository()
93
103
 
94
 
        target = Repository.open_from_transport(self.transport)
 
104
        objects = {}
 
105
        for tup in p.iterobjects():
 
106
            obj_type, obj = p.get_object_at (tup[0])
 
107
            if obj_type in range(1, 4):
 
108
                sf = ShaFile.from_raw_string (obj_type, obj)
 
109
                objects[hex_to_sha(sf.id)] = sf
95
110
 
96
111
        target.lock_write()
97
112
        try:
98
113
            target.start_write_group()
99
114
            try:
100
 
                import_git_objects(target, self.mapping, iter(get_objects()))
101
 
            finally:
 
115
                import_git_objects(target, self.mapping, objects,
 
116
                                   BazaarObjectStore (target, self.mapping),
 
117
                                   heads)
 
118
            except:
 
119
                target.abort_write_group()
 
120
                raise
 
121
            else:
102
122
                target.commit_write_group()
103
123
        finally:
104
124
            target.unlock()
132
152
            return repo.fetch_objects(determine_wants, graph_walker, None, progress)
133
153
 
134
154
        wants = determine_wants(self.get_refs())
 
155
        graph_walker.reset()
135
156
        repo.lock_read()
136
157
        store = BazaarObjectStore(repo)
137
158
        have = store.find_common_revisions(graph_walker)