~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: Benoît Pierre
  • Date: 2008-12-02 21:18:01 UTC
  • mto: (4056.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 4058.
  • Revision ID: benoit.pierre@gmail.com-20081202211801-s5p2rr6k8t0v5dl0
OK, so now patches should handle '\ No newline at end of file' in both
original and patched contents... Resurrect iter_lines_handle_nl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
236
236
 
237
237
 
238
238
def iter_hunks(iter_lines):
 
239
    iter_lines = iter_lines_handle_nl(iter_lines)
239
240
    hunk = None
240
241
    for line in iter_lines:
241
 
        if line == NO_NL:
242
 
            last_line = hunk.lines[-1]
243
 
            if not last_line.contents.endswith('\n'):
244
 
                raise AssertionError()
245
 
            last_line.contents = last_line.contents[:-1]
246
 
            continue
247
242
        if line == "\n":
248
243
            if hunk is not None:
249
244
                yield hunk
348
343
        yield saved_lines
349
344
 
350
345
 
 
346
def iter_lines_handle_nl(iter_lines):
 
347
    """
 
348
    Iterates through lines, ensuring that lines that originally had no
 
349
    terminating \n are produced without one.  This transformation may be
 
350
    applied at any point up until hunk line parsing, and is safe to apply
 
351
    repeatedly.
 
352
    """
 
353
    last_line = None
 
354
    for line in iter_lines:
 
355
        if line == NO_NL:
 
356
            if not last_line.endswith('\n'):
 
357
                raise AssertionError()
 
358
            last_line = last_line[:-1]
 
359
            line = None
 
360
        if last_line is not None:
 
361
            yield last_line
 
362
        last_line = line
 
363
    if last_line is not None:
 
364
        yield last_line
 
365
 
 
366
 
351
367
def parse_patches(iter_lines):
352
368
    return [parse_patch(f.__iter__()) for f in iter_file_patch(iter_lines)]
353
369