~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

Merge more bzr.dev, addressing some bugs. [still broken]

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
                time.ctime(), self.repo._upload_transport.base, random_name,
215
215
                plain_pack_list)
216
216
            start_time = time.time()
217
 
        write_stream = self.repo._upload_transport.open_file_stream(random_name)
 
217
        write_stream = self.repo._upload_transport.open_write_stream(random_name)
218
218
        if 'fetch' in debug.debug_flags:
219
219
            mutter('%s: create_pack: pack stream open: %s%s t+%6.3fs',
220
220
                time.ctime(), self.repo._upload_transport.base, random_name,
221
221
                time.time() - start_time)
222
222
        pack_hash = md5.new()
223
223
        buffer = []
224
 
        def write_data(bytes, update=pack_hash.update):
 
224
        def write_data(bytes, update=pack_hash.update, write=write_stream.write):
225
225
            buffer.append(bytes)
226
226
            if len(buffer) == 640:
227
227
                bytes = ''.join(buffer)
228
 
                write_stream(bytes)
 
228
                write(bytes)
229
229
                update(bytes)
230
230
                del buffer[:]
231
231
        writer = pack.ContainerWriter(write_data)
280
280
        writer.end()
281
281
        if len(buffer):
282
282
            bytes = ''.join(buffer)
283
 
            write_stream(bytes)
 
283
            write_stream.write(bytes)
284
284
            pack_hash.update(bytes)
285
285
        new_name = pack_hash.hexdigest()
286
286
        # if nothing has been written, discard the new pack.
294
294
        # add to names
295
295
        self.allocate(new_name)
296
296
        # rename into place
297
 
        self.repo._upload_transport.close_file_stream(random_name)
 
297
        write_stream.close()
298
298
        self.repo._upload_transport.rename(random_name, '../packs/' + new_name + '.pack')
299
299
        result = Pack()
300
300
        result.name = new_name
1152
1152
    def _start_write_group(self):
1153
1153
        random_name = self.control_files._lock.nonce
1154
1154
        self._open_pack_tuple = (self._upload_transport, random_name + '.pack')
1155
 
        write_stream = self._upload_transport.open_file_stream(random_name + '.pack')
 
1155
        write_stream = self._upload_transport.open_write_stream(random_name + '.pack')
 
1156
        self._write_stream = write_stream
1156
1157
        self._open_pack_hash = md5.new()
1157
 
        def write_data(bytes):
1158
 
            write_stream(bytes)
1159
 
            self._open_pack_hash.update(bytes)
 
1158
        def write_data(bytes, write=write_stream.write, update=self._open_pack_hash.update):
 
1159
            write(bytes)
 
1160
            update(bytes)
1160
1161
        self._open_pack_writer = pack.ContainerWriter(write_data)
1161
1162
        self._open_pack_writer.begin()
1162
1163
        self._packs.setup()
1181
1182
            self.weave_store.flush(new_name)
1182
1183
            self._inv_thunk.flush(new_name)
1183
1184
            self._revision_store.flush(new_name)
1184
 
            self._upload_transport.close_file_stream(self._open_pack_tuple[1])
 
1185
            self._write_stream.close()
1185
1186
            self._upload_transport.rename(self._open_pack_tuple[1],
1186
1187
                '../packs/' + new_name + '.pack')
1187
1188
            self._open_pack_tuple = None
1197
1198
        # delta.
1198
1199
        self._packs.reset()
1199
1200
        self._open_pack_hash = None
 
1201
        self._write_stream = None
1200
1202
 
1201
1203
    def get_inventory_weave(self):
1202
1204
        return self._inv_thunk.get_weave()
1269
1271
    def _start_write_group(self):
1270
1272
        random_name = self.control_files._lock.nonce
1271
1273
        self._open_pack_tuple = (self._upload_transport, random_name + '.pack')
1272
 
        write_stream = self._upload_transport.open_file_stream(random_name + '.pack')
 
1274
        write_stream = self._upload_transport.open_write_stream(random_name + '.pack')
 
1275
        self._write_stream = write_stream
1273
1276
        self._open_pack_hash = md5.new()
1274
 
        def write_data(bytes):
1275
 
            write_stream(bytes)
1276
 
            self._open_pack_hash.update(bytes)
 
1277
        def write_data(bytes, write=write_stream.write, update=self._open_pack_hash.update):
 
1278
            write(bytes)
 
1279
            update(bytes)
1277
1280
        self._open_pack_writer = pack.ContainerWriter(write_data)
1278
1281
        self._open_pack_writer.begin()
1279
1282
        self._packs.setup()
1298
1301
            self.weave_store.flush(new_name)
1299
1302
            self._inv_thunk.flush(new_name)
1300
1303
            self._revision_store.flush(new_name)
1301
 
            self._upload_transport.close_file_stream(self._open_pack_tuple[1])
 
1304
            self._write_stream.close()
1302
1305
            self._upload_transport.rename(self._open_pack_tuple[1],
1303
1306
                '../packs/' + new_name + '.pack')
1304
1307
            self._open_pack_tuple = None
1314
1317
        # delta.
1315
1318
        self._packs.reset()
1316
1319
        self._open_pack_hash = None
 
1320
        self._write_stream = None
1317
1321
 
1318
1322
    def get_inventory_weave(self):
1319
1323
        return self._inv_thunk.get_weave()