From: Junio C Hamano <gitster@pobox.com>
To: Jialong Wang <jerrywang183@yahoo.com>
Cc: git@vger.kernel.org, karthik.188@gmail.com
Subject: Re: [GSoC PATCH v2] apply: report the location of corrupt patches
Date: Mon, 16 Mar 2026 11:19:11 -0700 [thread overview]
Message-ID: <xmqqbjgnprhc.fsf@gitster.g> (raw)
In-Reply-To: <20260316113459.77794-1-jerrywang183@yahoo.com> (Jialong Wang's message of "Mon, 16 Mar 2026 07:34:59 -0400")
Jialong Wang <jerrywang183@yahoo.com> writes:
> When parsing a corrupt patch, git apply reports only the line number.
> That does not tell the user which input the line number refers to.
>
> Include the patch input path in the error message, and reset the line
> number for each patch input so the reported location remains useful
> when multiple patch files are provided.
>
> Add tests for file input, standard input, and multiple patch inputs.
>
> Signed-off-by: Jialong Wang <jerrywang183@yahoo.com>
> ---
> Changes since v1:
> - reset the line number for each patch input
> - add a test for multiple patch inputs where one input is corrupted
>
> apply.c | 4 +++-
> t/t4100-apply-stat.sh | 38 +++++++++++++++++++++++++++++++++++++-
> 2 files changed, 40 insertions(+), 2 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index b6dd1066a0..b7b0a201b3 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1875,7 +1875,8 @@ static int parse_single_patch(struct apply_state *state,
> len = parse_fragment(state, line, size, patch, fragment);
> if (len <= 0) {
> free(fragment);
> - return error(_("corrupt patch at line %d"), state->linenr);
> + return error(_("corrupt patch at %s:%d"),
> + state->patch_input_file, state->linenr);
> }
> fragment->patch = line;
> fragment->size = len;
> @@ -4825,6 +4826,7 @@ static int apply_patch(struct apply_state *state,
> int flush_attributes = 0;
>
> state->patch_input_file = filename;
> + state->linenr = 1;
> if (read_patch_file(&buf, fd) < 0)
> return -128;
> offset = 0;
This change is expecially interesting; it shows that practically
nobody feeds more than one patch to a single invocation of the
command ("git am" certainly does not) that this has gone undetected
ever since it was written by Linus 46979f56 (git-apply: improve
error detection and messages, 2005-05-23) ;-)
And all the changes contained in this patch look correctly done.
Having said that, there are places in apply.c that still report
errors only the line number, which we may want to address with a
follow-up patch, or in an updated version of this patch.
find_header() is one, parse_git_diff_header() is another. There
might be more.
Thanks, will queue.
next prev parent reply other threads:[~2026-03-16 18:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260315231538.68586-1-jerrywang183.ref@yahoo.com>
2026-03-15 23:15 ` [GSoC PATCH] apply: report the location of corrupt patches Jialong Wang
2026-03-16 11:14 ` Karthik Nayak
2026-03-16 11:34 ` Jialong Wang
2026-03-16 11:34 ` [GSoC PATCH v2] " Jialong Wang
2026-03-16 18:19 ` Junio C Hamano [this message]
2026-03-16 16:21 ` [GSoC PATCH v3] " Jialong Wang
2026-03-17 16:23 ` [PATCH v4 0/3] apply: report input file for more parse errors Jialong Wang
2026-03-17 16:23 ` [PATCH v4 1/3] apply: report the location of corrupt patches Jialong Wang
2026-03-17 16:23 ` [PATCH v4 2/3] apply: report input location in header parsing errors Jialong Wang
2026-03-17 16:23 ` [PATCH v4 3/3] apply: report input location in binary and garbage patch errors Jialong Wang
[not found] ` <xmqq8qq6y4ql.fsf@gitster.g>
2026-03-16 18:31 ` [GSoC PATCH v2] apply: report the location of corrupt patches Jialong Wang
2026-03-16 20:12 ` Junio C Hamano
2026-03-16 19:58 ` [GSoC PATCH] apply: report input location in header parsing errors Jialong Wang
2026-03-16 19:58 ` Jialong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbjgnprhc.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jerrywang183@yahoo.com \
--cc=karthik.188@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox