#NEWLINE# def parse( diff_text ) : #NEWLINE# #INDENT# print ( diff_text ) #NEWLINE# files = [ ] #NEWLINE# for file_diff in re . split ( 'diff --git a/.* b/.*\n' , diff_text ) [ 1 : ] : #NEWLINE# #INDENT# f = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# lines = file_diff . split ( '\n' ) #NEWLINE# if ( len ( lines ) is 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# while ( 'index ' not in lines [ 0 ] ) : #NEWLINE# #INDENT# lines = lines [ 1 : ] #NEWLINE# #UNINDENT# if ( '/dev/null' not in lines [ 1 ] ) : #NEWLINE# #INDENT# f [ 'name' ] = lines [ 1 ] [ 5 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f [ 'name' ] = lines [ 2 ] [ 5 : ] #NEWLINE# #UNINDENT# f [ 'chunks' ] = [ ] #NEWLINE# for file_chunk_diff in file_diff . split ( '\n@@' ) [ 1 : ] : #NEWLINE# #INDENT# lines = file_chunk_diff . split ( '\n' ) #NEWLINE# try : #NEWLINE# #INDENT# ( old_line_numbers , new_line_numbers ) = ( ( int ( s ) , int ( e ) ) for ( s , e ) in re . findall ( '[-+](\\d*),(\\d*) ' , lines [ 0 ] ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# lines [ 0 ] = lines [ 0 ] [ re . search ( ' .* @@' , lines [ 0 ] ) . end ( ) : ] #NEWLINE# old_line_number = old_line_numbers [ 0 ] #NEWLINE# new_line_number = new_line_numbers [ 0 ] #NEWLINE# chunk_lines = [ ] #NEWLINE# for line in lines : #NEWLINE# #INDENT# def get_whitespace( l ) : #NEWLINE# #INDENT# return re . match ( '\\s*' , l ) . group ( ) . replace ( ' ' , '&nbsp;' ) . replace ( '\t' , '&#09;' ) #NEWLINE# #UNINDENT# if ( ( len ( line ) < 1 ) or ( line [ 0 ] is ' ' ) ) : #NEWLINE# #INDENT# chunk_lines . append ( { #NEWLINE# #INDENT# 'old_number' : old_line_number , #NEWLINE# 'new_number' : new_line_number , #NEWLINE# 'content' : ( '' if ( len ( line ) is 0 ) else line [ 1 : ] . strip ( ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# old_line_number += 1 #NEWLINE# new_line_number += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] is '-' ) : #NEWLINE# #INDENT# chunk_lines . append ( { #NEWLINE# #INDENT# 'old_number' : old_line_number , #NEWLINE# 'content' : line [ 1 : ] . strip ( ) , #NEWLINE# 'whitespace' : get_whitespace ( line [ 1 : ] ) , #NEWLINE# 'deletion' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# old_line_number += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] is '+' ) : #NEWLINE# #INDENT# chunk_lines . append ( { #NEWLINE# #INDENT# 'new_number' : new_line_number , #NEWLINE# 'content' : line [ 1 : ] . strip ( ) , #NEWLINE# 'whitespace' : get_whitespace ( line [ 1 : ] ) , #NEWLINE# 'addition' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# new_line_number += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# f [ 'chunks' ] . append ( chunk_lines ) #NEWLINE# #UNINDENT# files . append ( f ) #NEWLINE# #UNINDENT# return files