def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoInterrupt"]) -> DiffIndex["Diff"]:
        """Create a new :class:`DiffIndex` from the given process output which must be
        in patch format.

        :param repo:
            The repository we are operating on.

        :param proc:
            :manpage:`git-diff(1)` process to read from
            (supports :class:`Git.AutoInterrupt <git.cmd.Git.AutoInterrupt>` wrapper).

        :return:
            :class:`DiffIndex`
        """

        # FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise.
        text_list: List[bytes] = []
        handle_process_output(proc, text_list.append, None, finalize_process, decode_streams=False)

        # For now, we have to bake the stream.
        text = b"".join(text_list)
        index: "DiffIndex" = DiffIndex()
        previous_header: Union[Match[bytes], None] = None
        header: Union[Match[bytes], None] = None
        a_path, b_path = None, None  # For mypy.
        a_mode, b_mode = None, None  # For mypy.
        for _header in cls.re_header.finditer(text):
            (
                a_path_fallback,
                b_path_fallback,
                old_mode,
                new_mode,
                rename_from,
                rename_to,
                new_file_mode,
                deleted_file_mode,
                copied_file_name,
                a_blob_id,
                b_blob_id,
                b_mode,
                a_path,
                b_path,
            ) = _header.groups()

            new_file, deleted_file, copied_file = (
                bool(new_file_mode),
                bool(deleted_file_mode),
                bool(copied_file_name),
            )

            a_path = cls._pick_best_path(a_path, rename_from, a_path_fallback)
            b_path = cls._pick_best_path(b_path, rename_to, b_path_fallback)

            # Our only means to find the actual text is to see what has not been matched
            # by our regex, and then retro-actively assign it to our index.
            if previous_header is not None:
                index[-1].diff = text[previous_header.end() : _header.start()]
            # END assign actual diff

            # Make sure the mode is set if the path is set. Otherwise the resulting blob
            # is invalid. We just use the one mode we should have parsed.
            a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode))
            b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode)
            index.append(
                Diff(
                    repo,
                    a_path,
                    b_path,
                    a_blob_id and a_blob_id.decode(defenc),
                    b_blob_id and b_blob_id.decode(defenc),
                    a_mode and a_mode.decode(defenc),
                    b_mode and b_mode.decode(defenc),
                    new_file,
                    deleted_file,
                    copied_file,
                    rename_from,
                    rename_to,
                    None,
                    None,
                    None,
                )
            )

            previous_header = _header
            header = _header
        # END for each header we parse
        if index and header:
            index[-1].diff = text[header.end() :]
        # END assign last diff

        return index
Create a new :class:`DiffIndex` from the given process output which must be
        in patch format.

        :param repo:
            The repository we are operating on.

        :param proc:
            :manpage:`git-diff(1)` process to read from
            (supports :class:`Git.AutoInterrupt <git.cmd.Git.AutoInterrupt>` wrapper).

        :return:
            :class:`DiffIndex`
        
git/diff.py