* Kernel bug caused by 'git apply' misapplying a patch with ambiguous chunk
@ 2015-04-02 15:25 Mikko Perttunen
2015-04-02 15:59 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Mikko Perttunen @ 2015-04-02 15:25 UTC (permalink / raw)
To: git; +Cc: Tuomas Tynkkynen, Tomeu Vizoso
Hello everyone,
we recently ran into a kernel bug caused by git misapplying this patch:
https://lkml.org/lkml/2014/7/3/896 .
The chunk '@@ -653,6 +655,7 @@' in tegra124.dtsi (the second file in the
patch) has ambiguous context (there are several almost identical PHY
nodes in the file). Git applied the chunk to the second PHY node when it
should have been applied to the first node.
You can reproduce this by checking out, for example, version 3.16 of the
Linux kernel and applying the patch from the above link and then looking at
arch/arm/boot/dts/tegra124.dtsi
and verifying that git has added the 'nvidia,has-utmi-pad-registers'
property to the second, instead of the first 'phy' node.
Of course this is probably rather hard to fix on the applying end; but
perhaps format-patch could check for ambiguous chunks and either warn
the user or increase the context size automatically, or apply could warn
about the chunk being ambiguous?
Thanks,
Mikko Perttunen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Kernel bug caused by 'git apply' misapplying a patch with ambiguous chunk
2015-04-02 15:25 Kernel bug caused by 'git apply' misapplying a patch with ambiguous chunk Mikko Perttunen
@ 2015-04-02 15:59 ` Junio C Hamano
2015-04-02 16:13 ` Mikko Perttunen
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2015-04-02 15:59 UTC (permalink / raw)
To: Mikko Perttunen; +Cc: git, Tuomas Tynkkynen, Tomeu Vizoso
Mikko Perttunen <mikko.perttunen@kapsi.fi> writes:
> Of course this is probably rather hard to fix on the applying end; but
> perhaps format-patch could check for ambiguous chunks and either warn
> the user or increase the context size automatically, or apply could
> warn about the chunk being ambiguous?
Interesting thought. Let me rephrase to make sure I got your
thought process correctly.
Imagine you started from an original that had two cut-and-pasted
codeblocks A and B in the same file and updated one of them, say A,
and then sent out the patch that turns A into A1.
Meanwhile, somebody started from the same original and updated the
same codeblock A in the upstream already to A2. Your patch applies
cleanly to codeblock B and turns it to A1, which is a mispatch. And
you cannot even detect the problem while applying.
But if you are starting from the original with idential A and B,
format-patch can see that the resulting patch to turn A to A1 can be
misunderstood to be a patch to change B to A1 instead. So in that
case, you _could_ detect.
But imagine if you started from an original that had A and C, that
are clearly different. Your change turns A into A1. In the
meantime, the upstream started from the same original, and changed C
into B that looks identical to A.
The same thing would happen to your patch when you try to apply it.
"git apply" could try to diagnose this situation and warn. But you
cannot check when your format-patch produces a patch that turns <A,C>
into <A1,C>, as there is no ambiguity in the original.
So,
- format-patch could try to help, but it won't be a complete
solution.
- apply could try to help, but it won't be a complete solution.
I am not sure if having "both" would make it complete, but I doubt
it.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Kernel bug caused by 'git apply' misapplying a patch with ambiguous chunk
2015-04-02 15:59 ` Junio C Hamano
@ 2015-04-02 16:13 ` Mikko Perttunen
0 siblings, 0 replies; 3+ messages in thread
From: Mikko Perttunen @ 2015-04-02 16:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Tuomas Tynkkynen, Tomeu Vizoso
On 04/02/2015 06:59 PM, Junio C Hamano wrote:
> Mikko Perttunen <mikko.perttunen@kapsi.fi> writes:
>
>> Of course this is probably rather hard to fix on the applying end; but
>> perhaps format-patch could check for ambiguous chunks and either warn
>> the user or increase the context size automatically, or apply could
>> warn about the chunk being ambiguous?
>
> Interesting thought. Let me rephrase to make sure I got your
> thought process correctly.
>
> Imagine you started from an original that had two cut-and-pasted
> codeblocks A and B in the same file and updated one of them, say A,
> and then sent out the patch that turns A into A1.
>
> Meanwhile, somebody started from the same original and updated the
> same codeblock A in the upstream already to A2. Your patch applies
> cleanly to codeblock B and turns it to A1, which is a mispatch. And
> you cannot even detect the problem while applying.
>
> But if you are starting from the original with idential A and B,
> format-patch can see that the resulting patch to turn A to A1 can be
> misunderstood to be a patch to change B to A1 instead. So in that
> case, you _could_ detect.
>
> But imagine if you started from an original that had A and C, that
> are clearly different. Your change turns A into A1. In the
> meantime, the upstream started from the same original, and changed C
> into B that looks identical to A.
>
> The same thing would happen to your patch when you try to apply it.
> "git apply" could try to diagnose this situation and warn. But you
> cannot check when your format-patch produces a patch that turns <A,C>
> into <A1,C>, as there is no ambiguity in the original.
>
> So,
>
> - format-patch could try to help, but it won't be a complete
> solution.
>
> - apply could try to help, but it won't be a complete solution.
>
> I am not sure if having "both" would make it complete, but I doubt
> it.
>
>
I agree. I think you can also create a situation where neither would
detect the problem, if the upstream changes C such that A->A1 can be
applied on it and at the same time changes A such that A->A1 no longer
applies. However, such a situation should be rare, so I think these
checks would be useful.
In this case, the ambiguity existed the whole time both on the
submitter's end and in upstream. Upstream just added more stuff into the
file causing the line numbers to shift. So in this case a check in
either subcommand would have caught it.
Mikko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-02 16:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-02 15:25 Kernel bug caused by 'git apply' misapplying a patch with ambiguous chunk Mikko Perttunen
2015-04-02 15:59 ` Junio C Hamano
2015-04-02 16:13 ` Mikko Perttunen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.