git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jerry Zhang <jerry@skydio.com>
Cc: "lilinchao@oschina.cn" <lilinchao@oschina.cn>, git <git@vger.kernel.org>
Subject: Re: git apply --3way behaves abnormally when the patch contains binary changes.
Date: Tue, 27 Jul 2021 18:08:13 -0700	[thread overview]
Message-ID: <xmqqv94vb5z6.fsf@gitster.g> (raw)
In-Reply-To: <CAMKO5Cs1HP7JNmJLYKti0kajGmD4XK+Boc3WRV2Dpph5a3b5Xw@mail.gmail.com> (Jerry Zhang's message of "Tue, 27 Jul 2021 15:44:08 -0700")

Jerry Zhang <jerry@skydio.com> writes:

>>         # 2. based on left_bin branch, make any change, and commit
>>         git checkout -b right &&
>>         cat bin.png bin.png > bin.png &&
>>         git add bin.png &&
>>         git commit -m "update binary file" &&
>>
>>         # 3. make patch
>>         git diff --binary left..right >bin.diff &&
>>         # apply --3way, and it will fail
>>         test_must_fail git apply --index --3way bin.diff
>> '
>> "
>>
>> But  "git apply --index --3way bin.diff" will not faill on Git version 2.31.0.
> Are you sure? I checked out to "commit
> a5828ae6b52137b913b978e16cd2334482eb4c1f (HEAD, tag: v2.31.0)" and
> rebuilt and ran your test snippet and it still failed.

Isn't it just because the reproduction recipe is simply wrong?

It says

    * be on left branch and have a binary file
    * be on right branch and have a modified binary file
    * create a patch to take left to right

Notice that we have a patch and we are still on the right branch.
Of course, applying the patch to take us from left to right would
fail from that state, but I _think_ the intent of the reproduction
recipe was, after all of the above, do this here:

    * switch to left branch and attempt to apply the patch.

And the patch is meant to take us from left to right, and we are on
pristine left, the application ought to cleanly succeed, no?

"git apply bin.diff" would probably work correctly but I do not know
offhand what the code after your change does with --3way enabled.

We refuse to merge binary files, so I would not be surprised if we
failed the 3way in this case (even though we _could_ fast-forward,
it may not be worth complicating the --3way logic---nobody sane
would say --3way when it is unnecessary) but after 3way fails, do we
still correctly fall back to "straight application" like we do for
text patches with your change?  Before your change, we would have
first attempted the "straight application", which would succeed and
wouldn't have hit "3way will refuse to merge binaries" at all.

So, I do not think it is implausible that we are seeing a legit
regression report.

Thanks.

  reply	other threads:[~2021-07-28  1:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 14:07 git apply --3way behaves abnormally when the patch contains binary changes lilinchao
2021-07-27 22:44 ` Jerry Zhang
2021-07-28  1:08   ` Junio C Hamano [this message]
2021-07-28  1:37     ` Jerry Zhang
     [not found]   ` <4eb90a4eef4011ebab68d4ae5272fd1139378@pobox.com>
2021-07-28  4:45     ` lilinchao

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=xmqqv94vb5z6.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jerry@skydio.com \
    --cc=lilinchao@oschina.cn \
    /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;
as well as URLs for NNTP newsgroup(s).