#NEWLINE# def ParsePatchToLines( lines ) : #NEWLINE# #INDENT# "Parses a patch from a list of lines.\n\n  Returns None on error, otherwise a list of 3-tuples:\n    (old_line_no, new_line_no, line)\n\n    A line number can be 0 if it doesn't exist in the old/new file.\n  " #NEWLINE# result = [ ] #NEWLINE# in_prelude = True #NEWLINE# for line in lines : #NEWLINE# #INDENT# if in_prelude : #NEWLINE# #INDENT# result . append ( ( 0 , 0 , line ) ) #NEWLINE# if line . startswith ( '+++' ) : #NEWLINE# #INDENT# in_prelude = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if line . startswith ( '@' ) : #NEWLINE# #INDENT# result . append ( ( 0 , 0 , line ) ) #NEWLINE# match = _CHUNK_RE . match ( line ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# logging . warn ( 'ParsePatchToLines match failed on %s' , line ) #NEWLINE# return None #NEWLINE# #UNINDENT# old_ln = int ( match . groups ( ) [ 0 ] ) #NEWLINE# new_ln = int ( match . groups ( ) [ 2 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] == '-' ) : #NEWLINE# #INDENT# result . append ( ( old_ln , 0 , line ) ) #NEWLINE# old_ln += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] == '+' ) : #NEWLINE# #INDENT# result . append ( ( 0 , new_ln , line ) ) #NEWLINE# new_ln += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] == ' ' ) : #NEWLINE# #INDENT# result . append ( ( old_ln , new_ln , line ) ) #NEWLINE# old_ln += 1 #NEWLINE# new_ln += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if line . startswith ( _NO_NEWLINE_MESSAGE ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result . append ( ( 0 , 0 , line ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return result