~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-05 04:05:05 UTC
  • mfrom: (3473.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080605040505-i9kqxg2fps2qjdi0
Add the 'alias' command (Tim Penhey)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004 - 2006, 2008 Aaron Bentley, Canonical Ltd
 
1
# Copyright (C) 2004 - 2006 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
17
18
 
18
19
 
19
20
class PatchSyntax(Exception):
94
95
 
95
96
 
96
97
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
 
    patch_lines = iter_lines_handle_nl(iter(patch_lines))
 
396
    if orig_lines is not None:
 
397
        orig_lines = orig_lines.__iter__()
 
398
    seen_patch = []
 
399
    patch_lines = iter_lines_handle_nl(patch_lines.__iter__())
397
400
    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
 
    """
408
 
    seen_patch = []
409
401
    line_no = 1
410
 
    if orig_lines is not None:
411
 
        orig_lines = iter(orig_lines)
412
 
    for hunk in hunks:
 
402
    for hunk in iter_hunks(patch_lines):
413
403
        while line_no < hunk.orig_pos:
414
404
            orig_line = orig_lines.next()
415
405
            yield orig_line