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

TestĀ transportgit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from dulwich.pack import (
32
32
    PackData,
33
33
    Pack,
 
34
    iter_sha1,
34
35
    load_pack_index_file,
 
36
    write_pack_index_v2,
35
37
    )
36
38
from dulwich.repo import (
37
39
    BaseRepo,
128
130
        ret = []
129
131
        for name in self._pack_names():
130
132
            if name.startswith("pack-") and name.endswith(".pack"):
131
 
                pd = PackData(name, self.pack_transport.get(name))
 
133
                size = self.pack_transport.stat(name).st_size
 
134
                pd = PackData(name, self.pack_transport.get(name), size=size)
132
135
                idxname = name.replace(".pack", ".idx")
133
136
                idx = load_pack_index_file(idxname, self.pack_transport.get(idxname))
134
137
                ret.append(Pack.from_objects(pd, idx))
166
169
            return # Already there, no need to write again
167
170
        self.transport.put_bytes(path, obj.as_legacy_object())
168
171
 
 
172
    def move_in_pack(self, path):
 
173
        """Move a specific file containing a pack into the pack directory.
 
174
 
 
175
        :note: The file should be on the same file system as the
 
176
            packs directory.
 
177
 
 
178
        :param path: Path to the pack file.
 
179
        """
 
180
        import os
 
181
        p = PackData(path)
 
182
        entries = p.sorted_entries()
 
183
        basename = os.path.join(self.pack_transport.local_abspath('.'),
 
184
            "pack-%s" % iter_sha1(entry[0] for entry in entries))
 
185
        write_pack_index_v2(basename+".idx", entries, p.get_stored_checksum())
 
186
        p.close()
 
187
        os.rename(path, basename + ".pack")
 
188
        final_pack = Pack(basename)
 
189
        self._add_known_pack(final_pack)
 
190
        return final_pack
 
191
 
169
192
    def add_pack(self):
170
193
        """Add a new pack to this object store. 
171
194
 
172
195
        :return: Fileobject to write to and a commit function to 
173
196
            call when the pack is finished.
174
197
        """
175
 
        raise NotImplementedError(self.add_pack)
 
198
        import os, tempfile
 
199
        fd, path = tempfile.mkstemp(dir=self.pack_transport.local_abspath('.'), suffix=".pack")
 
200
        f = os.fdopen(fd, 'wb')
 
201
        def commit():
 
202
            f.close()
 
203
            if os.path.getsize(path) > 0:
 
204
                return self.move_in_pack(path)
 
205
            else:
 
206
                return None
 
207
        return f, commit
176
208
 
177
209
    @classmethod
178
210
    def init(cls, transport):