How to use the unidiff.constants.RE_RENAME_TARGET_FILENAME.match function in unidiff

To help you get started, we’ve selected a few unidiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matiasb / python-unidiff / unidiff / patch.py View on Github external
line = line.decode(encoding)

            # check for a git rename, source file
            is_rename_source_filename = RE_RENAME_SOURCE_FILENAME.match(line)
            if is_rename_source_filename:
                # prefix with 'a/' to match expected git source format
                source_file = (
                    'a/' + is_rename_source_filename.group('filename'))
                # keep line as patch_info
                patch_info.append(line)
                # reset current file
                current_file = None
                continue

            # check for a git rename, target file
            is_rename_target_filename = RE_RENAME_TARGET_FILENAME.match(line)
            if is_rename_target_filename:
                if current_file is not None:
                    raise UnidiffParseError('Target without source: %s' % line)
                # prefix with 'b/' to match expected git source format
                target_file = (
                    'b/' + is_rename_target_filename.group('filename'))
                # keep line as patch_info
                patch_info.append(line)
                # add current file to PatchSet
                current_file = PatchedFile(
                    patch_info, source_file, target_file, None, None,
                    is_rename=True)
                self.append(current_file)
                continue

            # check for source file header