From: Junio C Hamano <gitster@pobox.com>
To: Tanga Joris <tangajoris@gmail.com>
Cc: git@vger.kernel.org, siddharthasthana31@gmail.com,
phillip.wood@dunelm.org.uk, jackrawlings2011@gmail.com,
christian.couder@gmail.com, kaartic.sivaraam@gmail.com,
usmanakinyemi202@gmail.com
Subject: Re: [Outreachy PATCH v3 1/3] apply: free the old def_name in parse_git_diff_header()
Date: Thu, 19 Nov 2026 12:28:26 -0800 [thread overview]
Message-ID: <xmqq5wxswoph.fsf@gitster.g> (raw)
In-Reply-To: <CAKrRMNoB-4==1EPLAAXE4M1J6bUwuWj=p32CedDvOTi3tzO7=A@mail.gmail.com> (Tanga Joris's message of "Thu, 19 Nov 2026 02:32:26 +0300")
Tanga Joris <tangajoris@gmail.com> writes:
>> I do not think we should ignore such a bogus "diff --git" line;
>> shouldn't we diagnose it as a corrupt patch input? I do not think
>> we are there yet without making find_header() do more work when
>> punting, though.
>
> I agree. I think find_header() should just stop and report it as a
> corrupt patch when a "diff --git" line has nothing after it, instead
> of going on to the next line. That would make 1/3 unnecessary, and
> 2/3 a lot simpler.
A line "diff --git a/f b/f" would not be followed by another "diff
--git" line immediately after, I think. Patches without any ---/+++
lines are very much possible (e.g., 100% rename or mode change without
any other change), but even in those cases there are extended header
lines like "rename from ..." and "old mode ...".
> As far as I can tell, Git doesn't write such a line anymore.
Have we ever produced such a patch? That is what "anymore" implies,
and I am curious, as that may indicate that our above assumption is
incorrect.
> I tried
> a few things like "git diff -w" on a whitespace-only change, renames
> and merges, and every "diff --git" line had header lines after it.
> The apply and am tests also still pass with the change, apart from
> my own test in 1/3.
>
> Is that what you had in mind? If so, I'll send v4 with it.
We should be strict in detecting a malformed "diff --git" in our
input. Silently ignoring them is simply wrong. We do ignore
non-patch material after a patch to one path ends and before another
patch to another path begins, so that authors can add commentary to
e-mails they send their patches in, though. We shouldn't be
tightening the parser rules on them after the fact.
Patches that begin with "diff" that is not "diff --git" are a
different story. They are parsed in different code paths, and I
would prefer to keep parsing of these third-party diff outputs as is,
to let the sleeping dog lie peacefully and silently.
next prev parent reply other threads:[~2026-11-19 20:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 15:17 Git crashed on `git apply --check` Gingrspacecadet
2026-10-24 6:10 ` Tanga Joris
[not found] ` <CALdwsC11JHUBBTt3e_RFixLYSF0VU1C+mG7bQsO0vV=a68XHNw@mail.gmail.com>
2026-10-25 22:56 ` Tanga Joris
2026-11-07 19:54 ` [Outreachy PATCH 1/2] apply: do not keep names from an unused "diff --git" line Tanga Joris
2026-11-07 19:54 ` [Outreachy PATCH 2/2] apply: reject new and deleted files that have both names Tanga Joris
2026-11-09 10:52 ` [Outreachy PATCH 1/2] apply: do not keep names from an unused "diff --git" line Phillip Wood
2026-11-09 13:13 ` Tanga Joris
2026-11-09 14:31 ` Phillip Wood
2026-11-09 20:54 ` Tanga Joris
2026-11-09 21:06 ` Junio C Hamano
2026-11-09 23:03 ` Tanga Joris
2026-11-09 19:56 ` Junio C Hamano
2026-11-14 1:20 ` [Outreachy PATCH v2 1/2] apply: reject a patch after an empty " Tanga Joris
2026-11-14 1:20 ` [Outreachy PATCH v2 2/2] apply: reject new and deleted files that have both names Tanga Joris
2026-11-15 12:47 ` Siddharth Asthana
2026-11-16 18:06 ` Tanga Joris
2026-11-15 12:39 ` [Outreachy PATCH v2 1/2] apply: reject a patch after an empty "diff --git" line Siddharth Asthana
2026-11-16 17:54 ` Tanga Joris
2026-11-17 0:43 ` [Outreachy PATCH v3 0/3] apply: reject corrupt "diff --git" headers Tanga Joris
2026-11-17 0:43 ` [Outreachy PATCH v3 1/3] apply: free the old def_name in parse_git_diff_header() Tanga Joris
2026-11-18 20:51 ` Junio C Hamano
2026-11-18 23:32 ` Tanga Joris
2026-11-19 20:28 ` Junio C Hamano [this message]
2026-11-17 0:43 ` [Outreachy PATCH v3 2/3] apply: reject a patch after an empty "diff --git" line Tanga Joris
2026-11-17 0:43 ` [Outreachy PATCH v3 3/3] apply: reject new and deleted files that have both names Tanga Joris
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=xmqq5wxswoph.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=jackrawlings2011@gmail.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=siddharthasthana31@gmail.com \
--cc=tangajoris@gmail.com \
--cc=usmanakinyemi202@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