~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to multiparent.py

  • Committer: Aaron Bentley
  • Date: 2007-04-13 11:44:05 UTC
  • mto: (2520.4.1 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070413114405-ldopk3ihc7g2gz22
Support using disk for knit reconstruction

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
 
233
233
    def __init__(self, snapshot_interval=25, max_snapshots=None):
234
234
        self._diffs = {}
 
235
        self._diff_offset = {}
235
236
        self._lines = {}
236
237
        self._parents = {}
237
238
        self._snapshots = set()
282
283
        self._lines[version_id] = lines
283
284
 
284
285
    def add_diff(self, diff, version_id, parent_ids):
285
 
        self._diffs[version_id] = diff
 
286
        self._diffs[version_id] = ''
 
287
        outfile = open('pknit', 'ab')
 
288
        start = outfile.tell()
 
289
        outfile.writelines(diff.to_patch())
 
290
        end = outfile.tell()
 
291
        self._diff_offset[version_id] = (start, end)
286
292
        self._parents[version_id] = parent_ids
287
293
 
288
294
    def import_versionedfile(self, vf, snapshots, no_cache=True,
360
366
            return self._lines[version_id]
361
367
        except KeyError:
362
368
            pass
363
 
        diff = self._diffs[version_id]
 
369
        diff = self.get_diff(version_id)
364
370
        lines = []
365
 
        reconstructor = _Reconstructor(self._diffs, self._lines,
 
371
        reconstructor = _Reconstructor(self, self._lines,
366
372
                                       self._parents)
367
373
        reconstructor.reconstruct_version(lines, version_id)
368
374
        #self._lines[version_id] = lines
369
375
        return lines
370
376
 
 
377
    def get_diff(self, version_id):
 
378
        infile = open('pknit', 'rb')
 
379
        start, end = self._diff_offset[version_id]
 
380
        infile.seek(start)
 
381
        text = infile.read(end - start)
 
382
        return MultiParent.from_patch(text.splitlines(True))
371
383
 
372
384
class _Reconstructor(object):
373
385
    """Build a text from the diffs, ancestry graph and cached lines"""
395
407
            try:
396
408
                start, end, kind, data, iterator = self.cursor[req_version_id]
397
409
            except KeyError:
398
 
                iterator = self.diffs[req_version_id].range_iterator()
 
410
                iterator = self.diffs.get_diff(req_version_id).range_iterator()
399
411
                start, end, kind, data = iterator.next()
400
412
            if start > req_start:
401
 
                iterator = self.diffs[req_version_id].range_iterator()
 
413
                iterator = self.diffs.get_diff(req_version_id).range_iterator()
402
414
                start, end, kind, data = iterator.next()
403
415
 
404
416
            # find the first hunk relevant to the request
422
434
                pending_reqs.append((new_version_id, new_start, new_end))
423
435
 
424
436
    def reconstruct_version(self, lines, version_id):
425
 
        length = self.diffs[version_id].num_lines()
 
437
        length = self.diffs.get_diff(version_id).num_lines()
426
438
        return self._reconstruct(lines, version_id, 0, length)
427
439
 
428
440
def gzip_string(lines):