~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

Merge serialize-transform into prepare-shelf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004 - 2006 Aaron Bentley, Canonical Ltd
 
1
# Copyright (C) 2004 - 2006, 2008 Aaron Bentley, Canonical Ltd
2
2
# <aaron.bentley@utoronto.ca>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
393
393
    """Iterate through a series of lines with a patch applied.
394
394
    This handles a single file, and does exact, not fuzzy patching.
395
395
    """
396
 
    if orig_lines is not None:
397
 
        orig_lines = orig_lines.__iter__()
 
396
    patch_lines = iter_lines_handle_nl(iter(patch_lines))
 
397
    get_patch_names(patch_lines)
 
398
    return iter_patched_from_hunks(orig_lines, iter_hunks(patch_lines))
 
399
 
 
400
 
 
401
def iter_patched_from_hunks(orig_lines, hunks):
 
402
    """Iterate through a series of lines with a patch applied.
 
403
    This handles a single file, and does exact, not fuzzy patching.
 
404
 
 
405
    :param orig_lines: The unpatched lines.
 
406
    :param hunks: An iterable of Hunk instances.
 
407
    """
398
408
    seen_patch = []
399
 
    patch_lines = iter_lines_handle_nl(patch_lines.__iter__())
400
 
    get_patch_names(patch_lines)
401
409
    line_no = 1
402
 
    for hunk in iter_hunks(patch_lines):
 
410
    if orig_lines is not None:
 
411
        orig_lines = iter(orig_lines)
 
412
    for hunk in hunks:
403
413
        while line_no < hunk.orig_pos:
404
414
            orig_line = orig_lines.next()
405
415
            yield orig_line