~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_py.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-27 22:29:55 UTC
  • mto: (3735.39.2 clean)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090327222955-utifmfm888zerixt
Implement apply_delta_to_source which doesn't have to malloc another string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
362
362
        pos += 1
363
363
        if cmd & 0x80:
364
364
            offset, length, pos = decode_copy_instruction(delta, cmd, pos)
365
 
            lines.append(basis[offset:offset+length])
 
365
            last = offset + length
 
366
            if last > len(basis):
 
367
                raise ValueError('data would copy bytes past the'
 
368
                                 'end of source')
 
369
            lines.append(basis[offset:last])
366
370
        else: # Insert of 'cmd' bytes
367
371
            if cmd == 0:
368
372
                raise ValueError('Command == 0 not supported yet')
373
377
        raise ValueError('Delta claimed to be %d long, but ended up'
374
378
                         ' %d long' % (target_length, len(bytes)))
375
379
    return bytes
 
380
 
 
381
 
 
382
def apply_delta_to_source(source, delta_start, delta_end):
 
383
    """Extract a delta from source bytes, and apply it."""
 
384
    source_size = len(source)
 
385
    if delta_start >= source_size:
 
386
        raise ValueError('delta starts after source')
 
387
    if delta_end > source_size:
 
388
        raise ValueError('delta ends after source')
 
389
    if delta_start >= delta_end:
 
390
        raise ValueError('delta starts after it ends')
 
391
    delta_bytes = source[delta_start:delta_end]
 
392
    return apply_delta(source, delta_bytes)