/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 bzrlib/patches.py

  • Committer: Kit Randel
  • Date: 2014-12-12 03:59:25 UTC
  • mto: This revision was merged to the branch mainline in revision 6602.
  • Revision ID: kit.randel@canonical.com-20141212035925-5nwyz5det0wtecce
fixed dirty_head logic in iter_file_patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
355
355
    dirty_head = []
356
356
    orig_range = 0
357
357
    beginning = True
 
358
 
358
359
    for line in iter_lines:
359
360
        if line.startswith('=== '):
360
361
            dirty_head.append(line)
373
374
                # parse the patch
374
375
                beginning = False
375
376
            elif len(saved_lines) > 0:
376
 
                yield saved_lines
 
377
                if keep_dirty and len(dirty_head) > 0:
 
378
                    yield {'saved_lines': saved_lines,
 
379
                           'dirty_head': dirty_head}
 
380
                    dirty_head = []
 
381
                else:
 
382
                    yield saved_lines
377
383
            saved_lines = []
378
384
        elif line.startswith('@@'):
379
385
            hunk = hunk_from_header(line)
380
386
            orig_range = hunk.orig_range
381
387
        saved_lines.append(line)
382
388
    if len(saved_lines) > 0:
383
 
        if keep_dirty:
384
 
            yield (saved_lines, dirty_head)
 
389
        if keep_dirty and len(dirty_head) > 0:
 
390
            yield {'saved_lines': saved_lines,
 
391
                   'dirty_head': dirty_head}
385
392
        else:
386
393
            yield saved_lines
387
394
 
416
423
    :kwarg keep_dirty: If True, returns a dict of patches with dirty headers.
417
424
        Default False.
418
425
    '''
419
 
    if keep_dirty:
420
 
        patches = []
421
 
        for lines, dirty in iter_file_patch(
422
 
                iter_lines, allow_dirty, keep_dirty):
423
 
            patches.append({'patch': parse_patch(lines, allow_dirty),
424
 
                            'dirty_head': dirty})
425
 
        return patches
426
 
    return [parse_patch(f.__iter__(), allow_dirty) for f in
427
 
            iter_file_patch(iter_lines, allow_dirty, keep_dirty)]
 
426
    patches = []
 
427
    for patch_lines in iter_file_patch(iter_lines, allow_dirty, keep_dirty):
 
428
        if 'dirty_head' in patch_lines:
 
429
            patches.append({'patch': parse_patch(
 
430
                patch_lines['saved_lines'], allow_dirty),
 
431
                            'dirty_head': patch_lines['dirty_head']})
 
432
        else:
 
433
            patches.append(parse_patch(patch_lines, allow_dirty))
 
434
    return patches
428
435
 
429
436
 
430
437
def difference_index(atext, btext):