git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* bugreport: git apply -3 confusing "lacks the necessary blob"
@ 2021-08-18 18:17 Jan Kratochvil
  2021-08-20  9:19 ` Bagas Sanjaya
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2021-08-18 18:17 UTC (permalink / raw)
  To: git

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
git apply -3 b.diff

What did you expect to happen? (Expected behavior)
<<<<<<< ours
c
||||||| base
a
=======
b
>>>>>>> theirs

What happened instead? (Actual behavior)
error: patch failed: x:1
error: repository lacks the necessary blob to fall back on 3-way merge.
error: x: patch does not apply

What's different between what you expected and what actually happened?
The conflicting patch has not been applied to resolve it manually.

Anything else you want to add:
The problem is 'git apply -3' will print confusing "lacks the necessary blob"
message despite the real error message should be:
"b.diff is missing line starting with 'index', cannot apply by -3/--3way"

reproducer:
(set -ex;: rm -rf gitgit;mkdir gitgit;cd gitgit;git init;echo a >x;git add x;git commit -am.;git checkout -b b;echo b >x;git commit -am.;git checkout master;echo c >x;git commit -am.;git diff master^..b|grep -v ^index >b.diff;git apply -3 b.diff || cat b.diff)

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.31.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.12.11-300.fc34.x86_64 #1 SMP Wed Jun 16 15:47:58 UTC 2021 x86_64
compiler info: gnuc: 11.0
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
not run from a git repository - no hooks to show

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-18 18:17 bugreport: git apply -3 confusing "lacks the necessary blob" Jan Kratochvil
@ 2021-08-20  9:19 ` Bagas Sanjaya
  2021-08-20  9:26   ` Jan Kratochvil
  2021-08-20 17:40   ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Bagas Sanjaya @ 2021-08-20  9:19 UTC (permalink / raw)
  To: Jan Kratochvil, git

On 19/08/21 01.17, Jan Kratochvil wrote:
> reproducer:
> (set -ex;: rm -rf gitgit;mkdir gitgit;cd gitgit;git init;echo a >x;git add x;git commit -am.;git checkout -b b;echo b >x;git commit -am.;git checkout master;echo c >x;git commit -am.;git diff master^..b|grep -v ^index >b.diff;git apply -3 b.diff || cat b.diff)

I can reproduce your issue on latest Git (2.33.0).

It seems like you remove `index` line, which **may** contain blob hash 
information required for three-way merge with git apply -3.

But if you don't remove it when generating patch that way, you will get 
expected conflict when git applying.

-- 
An old man doll... just what I always wanted! - Clara

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-20  9:19 ` Bagas Sanjaya
@ 2021-08-20  9:26   ` Jan Kratochvil
  2021-08-20 17:40   ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Jan Kratochvil @ 2021-08-20  9:26 UTC (permalink / raw)
  To: Bagas Sanjaya; +Cc: git

On Fri, 20 Aug 2021 11:19:39 +0200, Bagas Sanjaya wrote:
> On 19/08/21 01.17, Jan Kratochvil wrote:
> > reproducer:
> > (set -ex;: rm -rf gitgit;mkdir gitgit;cd gitgit;git init;echo a >x;git add x;git commit -am.;git checkout -b b;echo b >x;git commit -am.;git checkout master;echo c >x;git commit -am.;git diff master^..b|grep -v ^index >b.diff;git apply -3 b.diff || cat b.diff)
> 
> I can reproduce your issue on latest Git (2.33.0).
> 
> It seems like you remove `index` line, which **may** contain blob hash
> information required for three-way merge with git apply -3.
> 
> But if you don't remove it when generating patch that way, you will get
> expected conflict when git applying.

Yes.

The problem is when the 'index' line is already removed (as it was always
being removed in my existing setup) it is difficult to find out that is the
reason of this confusing message. So the error message should be different
when the 'index' line is missing at all.


Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-20  9:19 ` Bagas Sanjaya
  2021-08-20  9:26   ` Jan Kratochvil
@ 2021-08-20 17:40   ` Junio C Hamano
  2021-08-20 18:30     ` Jan Kratochvil
  2021-08-27 15:15     ` Jan Kratochvil
  1 sibling, 2 replies; 7+ messages in thread
From: Junio C Hamano @ 2021-08-20 17:40 UTC (permalink / raw)
  To: Bagas Sanjaya; +Cc: Jan Kratochvil, git

Bagas Sanjaya <bagasdotme@gmail.com> writes:

> On 19/08/21 01.17, Jan Kratochvil wrote:
>> reproducer:
>> (set -ex;: rm -rf gitgit;mkdir gitgit;cd gitgit;git init;echo a >x;git add x;git commit -am.;git checkout -b b;echo b >x;git commit -am.;git checkout master;echo c >x;git commit -am.;git diff master^..b|grep -v ^index >b.diff;git apply -3 b.diff || cat b.diff)
>
> I can reproduce your issue on latest Git (2.33.0).
>
> It seems like you remove `index` line, which **may** contain blob hash
> information required for three-way merge with git apply -3.
>
> But if you don't remove it when generating patch that way, you will
> get expected conflict when git applying.

You make it sound like an "it hurts when I do this, doctor. ---do
not do it, then" exchange ;-).

But I think Jan is talking about the case where users get a patch
that lacks the "index" information out of other people's "diff"
implementation and try to "apply -3" without realizing that it is
not Git's "diff" output.

Perhaps something like the attached patch would be a good start.

There is another place that relies on the index line (application of
binary patch), but the code rejects any patch that does not have the
full-length object name with "... without full index line".  This
message was originally meant to reject patches with abbreviated
object names on the index line, but it would equally apply to one
without the index line (perhaps by accident), so there is no need to
touch that one.


 apply.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git i/apply.c w/apply.c
index 44bc31d6eb..9972ada57e 100644
--- i/apply.c
+++ w/apply.c
@@ -3566,6 +3566,8 @@ static int try_threeway(struct apply_state *state,
 	/* Preimage the patch was prepared for */
 	if (patch->is_new)
 		write_object_file("", 0, blob_type, &pre_oid);
+	else if (!*patch->old_oid_prefix && !*patch->new_oid_prefix)
+		return error(_("cannot 'apply -3' a patch without the index line"));
 	else if (get_oid(patch->old_oid_prefix, &pre_oid) ||
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-20 17:40   ` Junio C Hamano
@ 2021-08-20 18:30     ` Jan Kratochvil
  2021-08-27 15:15     ` Jan Kratochvil
  1 sibling, 0 replies; 7+ messages in thread
From: Jan Kratochvil @ 2021-08-20 18:30 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Bagas Sanjaya, git

On Fri, 20 Aug 2021 19:40:12 +0200, Junio C Hamano wrote:
> But I think Jan is talking about the case where users get a patch
> that lacks the "index" information out of other people's "diff"
> implementation and try to "apply -3" without realizing that it is
> not Git's "diff" output.

Yes.


> Perhaps something like the attached patch would be a good start.

It does fix the problem for me, thanks!


Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-20 17:40   ` Junio C Hamano
  2021-08-20 18:30     ` Jan Kratochvil
@ 2021-08-27 15:15     ` Jan Kratochvil
  2021-08-27 17:14       ` Junio C Hamano
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2021-08-27 15:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Bagas Sanjaya, git

On Fri, 20 Aug 2021 19:40:12 +0200, Junio C Hamano wrote:
> But I think Jan is talking about the case where users get a patch
> that lacks the "index" information out of other people's "diff"
> implementation and try to "apply -3" without realizing that it is
> not Git's "diff" output.

For example from Phabricator:
	https://reviews.llvm.org/file/data/3ceoc32b3yv43vk3nw4q/PHID-FILE-lfeeh2qu4vrngdcwwudo/D107456.diff


> Perhaps something like the attached patch would be a good start.

Do you plan to check it in?


Thanks,
Jan Kratochvil


> diff --git i/apply.c w/apply.c
> index 44bc31d6eb..9972ada57e 100644
> --- i/apply.c
> +++ w/apply.c
> @@ -3566,6 +3566,8 @@ static int try_threeway(struct apply_state *state,
>  	/* Preimage the patch was prepared for */
>  	if (patch->is_new)
>  		write_object_file("", 0, blob_type, &pre_oid);
> +	else if (!*patch->old_oid_prefix && !*patch->new_oid_prefix)
> +		return error(_("cannot 'apply -3' a patch without the index line"));
>  	else if (get_oid(patch->old_oid_prefix, &pre_oid) ||
>  		 read_blob_object(&buf, &pre_oid, patch->old_mode))
>  		return error(_("repository lacks the necessary blob to perform 3-way merge."));

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bugreport: git apply -3 confusing "lacks the necessary blob"
  2021-08-27 15:15     ` Jan Kratochvil
@ 2021-08-27 17:14       ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2021-08-27 17:14 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Bagas Sanjaya, git

Jan Kratochvil <jan@jankratochvil.net> writes:

> On Fri, 20 Aug 2021 19:40:12 +0200, Junio C Hamano wrote:
>> But I think Jan is talking about the case where users get a patch
>> that lacks the "index" information out of other people's "diff"
>> implementation and try to "apply -3" without realizing that it is
>> not Git's "diff" output.
>
> For example from Phabricator:
> 	https://reviews.llvm.org/file/data/3ceoc32b3yv43vk3nw4q/PHID-FILE-lfeeh2qu4vrngdcwwudo/D107456.diff
>
>
>> Perhaps something like the attached patch would be a good start.
>
> Do you plan to check it in?

Maybe eventually but not yet.  When I say "a good start", it is
because it is known to be insufficient.  I haven't had a chance to
revisit the issue.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-27 17:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 18:17 bugreport: git apply -3 confusing "lacks the necessary blob" Jan Kratochvil
2021-08-20  9:19 ` Bagas Sanjaya
2021-08-20  9:26   ` Jan Kratochvil
2021-08-20 17:40   ` Junio C Hamano
2021-08-20 18:30     ` Jan Kratochvil
2021-08-27 15:15     ` Jan Kratochvil
2021-08-27 17:14       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).