#NEWLINE# def parse_commit_message( args ) : #NEWLINE# #INDENT# ' Find the commit message in the commit command.\n        Messages may be formatted like:\n        * `-m "some message"`\n        * `--message "some message"`\n        * `--message="some message"`\n        Single quotes are allowed too.\n        `args` is a list that should be formatted exactly as sys.argv\n    ' #NEWLINE# reg = re . compile ( '(\\-\\w*m\\w*|\\-\\-message)(\\s*|(=\'(?:\\\\.|[^\'])*\'|\\"(?:\\\\.|[^\\"])*\\"))' ) #NEWLINE# scan = [ index for ( index , val ) in enumerate ( args ) for mat in [ reg . search ( val ) ] if mat ] #NEWLINE# if ( not scan ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# if ( len ( scan ) > 1 ) : #NEWLINE# #INDENT# fprintf ( 'GITIME ERROR: Your commit contains more than one message. Your commit was NOT made. Try again.' , file = sys . stderr ) #NEWLINE# sys . exit ( ) #NEWLINE# #UNINDENT# index = scan [ 0 ] #NEWLINE# format_reg = re . search ( '=\'((\\\\.|[^\'])*?)\'|\\"((\\\\.|[^\\"])*?)\\"' , args [ index ] ) #NEWLINE# if ( format_reg is not None ) : #NEWLINE# #INDENT# return format_reg . group ( ) . strip ( '=' ) . strip ( '"' ) . strip ( "'" ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) < ( index + 2 ) ) : #NEWLINE# #INDENT# fprintf ( "GITIME ERROR: Your commit doesn't contain a message. Your commit was NOT made. Try again." , file = sys . stderr ) #NEWLINE# sys . exit ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret = args [ ( index + 1 ) ] #NEWLINE# args [ ( index + 1 ) ] = re . sub ( '(?<!\\\\)(?:\\\\\\\\)*"' , '\\"' , args [ ( index + 1 ) ] ) #NEWLINE# args [ ( index + 1 ) ] = '' . join ( [ '"' , args [ ( index + 1 ) ] , '"' ] ) #NEWLINE# return ret