mdpage/diffpatch.py
def detect_type(self):
        """detect and set type for the Patch object"""
        # NOTE: must be run before file_names are normalized
        # common checks for git and plain
        if not (
            (self.source.startswith('a/') or self.source == '/dev/null') and
            (self.target.startswith('b/') or self.target == '/dev/null')
        ):
            return self.set_type(self.PLAIN)

        # GIT type check
        #  - header[-2] is like "diff --git a/oldname b/newname"
        #  - header[-1] is like "index <hash>..<hash> <mode>"
        # Git patch header len is 2 min
        if len(self.header) > 1:
            # detect the start of diff header - there might be some comments before
            for idx in range(len(self.header) - 1, -1, -1):
                if self.header[idx].startswith("diff --git"):
                    break

            if (
                self.header[idx].startswith('diff --git a/') and
                idx + 1 < len(self.header) and
                re.match(r'index \w{7}..\w{7} \d{6}', self.header[idx + 1])
            ):
                return self.set_type(self.GIT)

        return self.set_type(self.PLAIN)
detect and set type for the Patch object
detect and set type for the Patch object
detect and set type for the Patch object
def detect_type(self):
        if not (
            (self.source.startswith('a/') or self.source == '/dev/null') and
            (self.target.startswith('b/') or self.target == '/dev/null')
        ):
            return self.set_type(self.PLAIN)
        if len(self.header) > 1:
            for idx in range(len(self.header) - 1, -1, -1):
                if self.header[idx].startswith("diff --git"):
                    break
            if (
                self.header[idx].startswith('diff --git a/') and
                idx + 1 < len(self.header) and
                re.match(r'index \w{7}..\w{7} \d{6}', self.header[idx + 1])
            ):
                return self.set_type(self.GIT)
        return self.set_type(self.PLAIN)
def detect_type ( self ) : if not ( ( self . source . startswith ( 'a/' ) or self . source == '/dev/null' ) and ( self . target . startswith ( 'b/' ) or self . target == '/dev/null' ) ) : return self . set_type ( self . PLAIN ) if len ( self . header ) > 1 : for idx in range ( len ( self . header ) - 1 , - 1 , - 1 ) : if self . header [ idx ] . startswith ( "diff --git" ) : break if ( self . header [ idx ] . startswith ( 'diff --git a/' ) and idx + 1 < len ( self . header ) and re . match ( r'index \w{7}..\w{7} \d{6}' , self . header [ idx + 1 ] ) ) : return self . set_type ( self . GIT ) return self . set_type ( self . PLAIN )
detect and set type for the Patch object
detect and set type for the Patch object
"""detect and set type for the Patch object""" # NOTE: must be run before file_names are normalized # common checks for git and plain # GIT type check #  - header[-2] is like "diff --git a/oldname b/newname" #  - header[-1] is like "index <hash>..<hash> <mode>" # Git patch header len is 2 min # detect the start of diff header - there might be some comments before
self