On Wed, Jul 08, 2015 at 01:31:25AM +0200, Stefan Fritsch wrote:
> Hi,
>
> patch's handling of diffs that change the beginning of a file is broken.
> The moste severe breakage is this, where the diff says to remove a line
> "aa" but patch removes a line "XX":
Yeah, known issue. Checking of context is not reliable at the start
and end of a file. There are logic erors in the way patch checks the
existing contents in those cases, but I never got around to fixing
them.
-Otto
>
> # cat diff
> --- a Wed Jul 8 00:53:09 2015
> +++ b Wed Jul 8 00:53:29 2015
> @@ -1,3 +1,3 @@
> -aa
> +aa 1
> bb
> cc
> # cat a
> XX
> bb
> cc
> # patch < diff
> Hmm... Looks like a unified diff to me...
> The text leading up to this was:
> --------------------------
> |--- a Wed Jul 8 00:53:09 2015
> |+++ b Wed Jul 8 00:53:29 2015
> --------------------------
> Patching file a using Plan A...
> Hunk #1 succeeded at 1 with fuzz 1.
> done
> # cat a
> aa 1
> bb
> cc
>
>
> Other broken behavior involves diffs that only add at the beginning of a
> file. This diff can be applied many times without patch noticing:
>
> # cat diff
> --- a Wed Jul 8 00:49:22 2015
> +++ b Wed Jul 8 00:49:37 2015
> @@ -1,3 +1,4 @@
> +00
> aa
> bb
> cc
> # cat a
> aa
> bb
> cc
> # patch < diff
> Hmm... Looks like a unified diff to me...
> The text leading up to this was:
> --------------------------
> |--- a Wed Jul 8 00:49:22 2015
> |+++ b Wed Jul 8 00:49:37 2015
> --------------------------
> Patching file a using Plan A...
> Hunk #1 succeeded at 1.
> done
> # patch < diff
> Hmm... Looks like a unified diff to me...
> The text leading up to this was:
> --------------------------
> |--- a Wed Jul 8 00:49:22 2015
> |+++ b Wed Jul 8 00:49:37 2015
> --------------------------
> Patching file a using Plan A...
> Hunk #1 succeeded at 2 (offset 1 line).
> done
> # patch < diff
> Hmm... Looks like a unified diff to me...
> The text leading up to this was:
> --------------------------
> |--- a Wed Jul 8 00:49:22 2015
> |+++ b Wed Jul 8 00:49:37 2015
> --------------------------
> Patching file a using Plan A...
> Hunk #1 succeeded at 3 (offset 2 lines).
> done
> # cat a
> 00
> 00
> 00
> aa
> bb
> cc
>
>
> The same goes for diffs that create a file. These can be applied many
> times without patch complaining. patch says 'Empty context always
> matches', which seems to indicate that this is a known issue, though the
> message is misleading. There used to be a second message 'Detection of
> previously applied patch not possible.' but that message has been removed
> 12 years ago.
>
> # cat diff
> --- /dev/null Wed Jul 8 00:59:58 2015
> +++ b Wed Jul 8 01:00:05 2015
> @@ -0,0 +1,3 @@
> +aa
> +bb
> +cc
>
>
> Cheers,
> Stefan