From: Junio C Hamano <gitster@pobox.com>
To: Remi LESPINET <remi.lespinet@ensimag.grenoble-inp.fr>
Cc: git@vger.kernel.org
Subject: Re: [RFC] solving a bug with hunks starting at line 1 in git apply
Date: Mon, 01 Jun 2015 10:30:30 -0700 [thread overview]
Message-ID: <xmqqeglv72vd.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqqiob773iy.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Mon, 01 Jun 2015 10:16:21 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> Remi LESPINET <remi.lespinet@ensimag.grenoble-inp.fr> writes:
>
>> first original file:
>>
>> 10
>> 20
>> 30
>> 40
>>
>> for the following diff file:
>>
>> @@ -1,2 +1,2 @@
>> 20
>> -30
>> +35
>> 40
>>
>> The patch will not be applied with a git apply command, but it will
>> with a basic patch command.
>
> Doesn't that merely indicate a bug in "patch", though?
This needs a bit gentler explanation. Imagine you are doing a usual
"git diff" with two lines of context, with a longer original. A
change to do s/30/35/ would look like this:
@@ -1,5 +1,5 @@
10
20
-30
+35
40
50
And an attempt to apply this patch to an original that does not have
10, 20, 30, 40 and 50 in this order must fail.
On the other hand, if the change were instead s/20/35/, then the
diff output would look like this instead:
@@ -1,4 +1,4 @@
10
-20
+25
30
40
Notice that the pre-context lines in this second example is only one
line. Is it giving the same degree of safety if we rejected an
attempt to apply this patch only when the original does not have 10,
20, 30 and 40 in this order?
No. Because we are doing two-line context patch, the patch is not
just saying "this change applies to a place where the first line is
10". It also is saying "there is no line before that line".
To answer my own question in the previous message, we cannot tell
only from that example which of "git apply" and "patch" is wrong.
If you generated the patch with "git diff -U1", then "git apply"
that insists that there must be no line before that "20" is wrong.
If you generated the patch with "git diff" with the default two-line
context, then "patch" is wrong if it does not make sure "20" is the
first line.
next prev parent reply other threads:[~2015-06-01 17:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 17:07 [RFC] solving a bug with hunks starting at line 1 in git apply Remi LESPINET
2015-06-01 17:16 ` Junio C Hamano
2015-06-01 17:30 ` Junio C Hamano [this message]
2015-06-01 18:00 ` Matthieu Moy
2015-06-01 18:37 ` Junio C Hamano
2015-06-01 18:47 ` Matthieu Moy
2015-06-01 18:53 ` Junio C Hamano
2015-06-01 21:37 ` Remi Lespinet
2015-06-01 18:20 ` Matthieu Moy
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=xmqqeglv72vd.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=remi.lespinet@ensimag.grenoble-inp.fr \
/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