Re: bugreport: git apply -3 confusing "lacks the necessary blob"

3 messages, 2 authors, 2021-08-27 · open the first message on its own page

Re: bugreport: git apply -3 confusing "lacks the necessary blob"

From: Junio C Hamano <hidden>
Date: 2021-08-20 17:40:22

Bagas Sanjaya [off-list ref] writes:
On 19/08/21 01.17, Jan Kratochvil wrote:
quoted
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."));

Re: bugreport: git apply -3 confusing "lacks the necessary blob"

From: Jan Kratochvil <hidden>
Date: 2021-08-20 18:31:07

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

Re: bugreport: git apply -3 confusing "lacks the necessary blob"

From: Jan Kratochvil <hidden>
Date: 2021-08-27 15:15:34

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

quoted hunk
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."));
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help