#NEWLINE# def _detect_type( self , p ) : #NEWLINE# #INDENT# ' detect and return type for the specified Patch object\n        analyzes header and filenames info\n\n        NOTE: must be run before filenames are normalized\n    ' #NEWLINE# if ( ( len ( p . header ) > 1 ) and p . header [ ( - 2 ) ] . startswith ( b'Index: ' ) and p . header [ ( - 1 ) ] . startswith ( ( b'=' * 67 ) ) ) : #NEWLINE# #INDENT# return SVN #NEWLINE# #UNINDENT# DVCS = ( ( p . source . startswith ( b'a/' ) or ( p . source == b'/dev/null' ) ) and ( p . target . startswith ( b'b/' ) or ( p . target == b'/dev/null' ) ) ) #NEWLINE# if ( len ( p . header ) > 1 ) : #NEWLINE# #INDENT# for idx in reversed ( range ( len ( p . header ) ) ) : #NEWLINE# #INDENT# if p . header [ idx ] . startswith ( b'diff --git' ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if p . header [ idx ] . startswith ( b'diff --git a/' ) : #NEWLINE# #INDENT# if ( ( ( idx + 1 ) < len ( p . header ) ) and re . match ( b'index \\w{7}..\\w{7} \\d{6}' , p . header [ ( idx + 1 ) ] ) ) : #NEWLINE# #INDENT# if DVCS : #NEWLINE# #INDENT# return GIT #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( p . header ) > 0 ) : #NEWLINE# #INDENT# if ( DVCS and re . match ( b'diff -r \\w{12} .*' , p . header [ ( - 1 ) ] ) ) : #NEWLINE# #INDENT# return HG #NEWLINE# #UNINDENT# if ( DVCS and p . header [ ( - 1 ) ] . startswith ( b'diff --git a/' ) ) : #NEWLINE# #INDENT# if ( len ( p . header ) == 1 ) : #NEWLINE# #INDENT# return HG #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if p . header [ 0 ] . startswith ( b'# HG changeset patch' ) : #NEWLINE# #INDENT# return HG #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return PLAIN