/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

Avoid using os module in transportgit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
            return # Already there, no need to write again
170
170
        self.transport.put_bytes(path, obj.as_legacy_object())
171
171
 
172
 
    def move_in_pack(self, path):
 
172
    def move_in_pack(self, f):
173
173
        """Move a specific file containing a pack into the pack directory.
174
174
 
175
175
        :note: The file should be on the same file system as the
177
177
 
178
178
        :param path: Path to the pack file.
179
179
        """
180
 
        import os
181
 
        p = PackData(path)
 
180
        f.seek(0)
 
181
        p = PackData(None, f, len(f.getvalue()))
182
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)
 
183
        basename = "pack-%s" % iter_sha1(entry[0] for entry in entries)
 
184
        f.seek(0)
 
185
        self.pack_transport.put_file(basename + ".pack", f)
 
186
        index_path = self.pack_transport.local_abspath(basename+".idx")
 
187
        write_pack_index_v2(index_path, entries, p.get_stored_checksum())
 
188
        idx = load_pack_index_file(basename+".idx",
 
189
                self.pack_transport.get(basename+".idx"))
 
190
        final_pack = Pack.from_objects(p, idx)
189
191
        self._add_known_pack(final_pack)
190
192
        return final_pack
191
193
 
195
197
        :return: Fileobject to write to and a commit function to 
196
198
            call when the pack is finished.
197
199
        """
198
 
        import os, tempfile
199
 
        fd, path = tempfile.mkstemp(dir=self.pack_transport.local_abspath('.'), suffix=".pack")
200
 
        f = os.fdopen(fd, 'wb')
 
200
        from cStringIO import StringIO
 
201
        f = StringIO()
201
202
        def commit():
202
 
            f.close()
203
 
            if os.path.getsize(path) > 0:
204
 
                return self.move_in_pack(path)
 
203
            if len(f.getvalue()) > 0:
 
204
                return self.move_in_pack(f)
205
205
            else:
206
206
                return None
207
207
        return f, commit