--- patches-old.py 2010-11-02 16:17:07.000000000 -0700 +++ patches.py 2010-11-02 16:17:24.000000000 -0700 @@ -278,12 +278,15 @@ orig_size = 0 mod_size = 0 while orig_size < hunk.orig_range or mod_size < hunk.mod_range: - hunk_line = parse_line(iter_lines.next()) - hunk.lines.append(hunk_line) - if isinstance(hunk_line, (RemoveLine, ContextLine)): - orig_size += 1 - if isinstance(hunk_line, (InsertLine, ContextLine)): - mod_size += 1 + try: + hunk_line = parse_line(iter_lines.next()) + hunk.lines.append(hunk_line) + if isinstance(hunk_line, (RemoveLine, ContextLine)): + orig_size += 1 + if isinstance(hunk_line, (InsertLine, ContextLine)): + mod_size += 1 + except StopIteration, e: + break if hunk is not None: yield hunk