/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: Andrew Bennetts
  • Date: 2008-10-27 06:14:45 UTC
  • mfrom: (3793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3795.
  • Revision ID: andrew.bennetts@canonical.com-20081027061445-eqt9lz6uw1mbvq4g
Merge from bzr.dev.

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
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
import re
18
17
 
19
18
 
20
19
class PatchSyntax(Exception):
95
94
 
96
95
 
97
96
def hunk_from_header(line):
 
97
    import re
98
98
    matches = re.match(r'\@\@ ([^@]*) \@\@( (.*))?\n', line)
99
99
    if matches is None:
100
100
        raise MalformedHunkHeader("Does not match format.", line)
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