How to use the unidiff.PatchSet.from_filename 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 Eloston / ungoogled-chromium / devutils / validate_patches.py View on Github external
def _load_all_patches(series_iter, patches_dir):
    """
    Returns a tuple of the following:
    - boolean indicating success or failure of reading files
    - dict of relative UNIX path strings to unidiff.PatchSet
    """
    had_failure = False
    unidiff_dict = dict()
    for relative_path in series_iter:
        if relative_path in unidiff_dict:
            continue
        unidiff_dict[relative_path] = unidiff.PatchSet.from_filename(
            str(patches_dir / relative_path), encoding=ENCODING)
        if not (patches_dir / relative_path).read_text(encoding=ENCODING).endswith('\n'):
            had_failure = True
            get_logger().warning('Patch file does not end with newline: %s',
                                 str(patches_dir / relative_path))
    return had_failure, unidiff_dict
github gcc-mirror / gcc / contrib / gcc-changelog / git_email.py View on Github external
def __init__(self, filename, strict=False):
        self.filename = filename
        diff = PatchSet.from_filename(filename)
        date = None
        author = None

        with open(self.filename, 'r') as f:
            lines = f.read().splitlines()
        lines = list(takewhile(lambda line: line != '---', lines))
        for line in lines:
            if line.startswith(DATE_PREFIX):
                date = parse(line[len(DATE_PREFIX):])
            elif line.startswith(FROM_PREFIX):
                author = GitCommit.format_git_author(line[len(FROM_PREFIX):])
        header = list(takewhile(lambda line: line != '', lines))
        body = lines[len(header) + 1:]

        modified_files = []
        for f in diff: