# [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs

4 messages from 2018-02-15 to 2018-02-15. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/47851

## Johannes Schindelin, 2018-02-15 00:29

Subject: [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs
Message-ID: <cover.1518654532.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/cover.1518654532.git.johannes.schindelin%40gmx.de

```
They are accepted already, almost. With one exception: the ---/+++ lines
contain not only the file names, but continue with a TAB and then the
revision (or "working copy" or "nonexistent") in parenthesis.

We already handle these lines, except in the case of /dev/null. Let's handle
the case gracefully where the diff contains a "--- /dev/null" line with a
trailing comment.

This contribution came in via Pull Request to Git for Windows, from a first
time contributor! Yes!


Johannes Schindelin (1):
  apply: demonstrate a problem applying svn diffs

Tatyana Krasnukha (1):
  apply: handle Subversion diffs with /dev/null gracefully

 apply.c                          |  2 +-
 t/t4135-apply-weird-filenames.sh | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)


base-commit: b2e45c695d09f6a31ce09347ae0a5d2cdfe9dd4e
Published-As: https://github.com/dscho/git/releases/tag/apply-svn-diff-v1
Fetch-It-Via: git fetch https://github.com/dscho/git apply-svn-diff-v1
-- 
2.16.1.windows.1


```

## Johannes Schindelin, 2018-02-15 00:29

Subject: [PATCH 1/2] apply: demonstrate a problem applying svn diffs
Message-ID: <24000fd64887994bfc5b70b5e4bd3d8c92661f81.1518654532.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/24000fd64887994bfc5b70b5e4bd3d8c92661f81.1518654532.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1518654532.git.johannes.schindelin@gmx.de>

```
Subversion generates diffs that contain funny ---/+++ lines containing
more than just the file names. Example:

	--- a/trunk/README	(revision 4711)
	+++ /dev/null	(nonexistent)

Let's add a test case demonstrating that apply cannot handle the
/dev/null line (although it can handle the trunk/README line just fine).

Reported in https://github.com/git-for-windows/git/issues/1489

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t4135-apply-weird-filenames.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh
index 27cb0009fb1..b14b8085786 100755
--- a/t/t4135-apply-weird-filenames.sh
+++ b/t/t4135-apply-weird-filenames.sh
@@ -89,4 +89,21 @@ test_expect_success 'traditional, whitespace-damaged, colon in timezone' '
 	test_cmp expected "post image.txt"
 '
 
+cat >diff-from-svn <<\EOF
+Index: Makefile
+===================================================================
+diff --git a/branches/Makefile
+deleted file mode 100644
+--- a/branches/Makefile	(revision 13)
++++ /dev/null	(nonexistent)
+@@ +1 0,0 @@
+-
+EOF
+
+test_expect_failure 'apply handles a diff generated by Subversion' '
+	>Makefile &&
+	git apply -p2 diff-from-svn &&
+	test_path_is_missing Makefile
+'
+
 test_done
-- 
2.16.1.windows.1



```

## Johannes Schindelin, 2018-02-15 00:29

Subject: [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully
Message-ID: <7858c01a2c92a55f86611335bbdcc93c94bc69d2.1518654532.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/7858c01a2c92a55f86611335bbdcc93c94bc69d2.1518654532.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1518654532.git.johannes.schindelin@gmx.de>

```
From: Tatyana Krasnukha <tatyana@synopsys.com>

Subversion generates diffs that can contain lines like this one:

	--- /dev/null  (nonexistent)

Let's teach Git's apply machinery to handle such a line gracefully.

This fixes https://github.com/git-for-windows/git/isues/1489

Signed-off-by: Tatyana Krasnukha <tatyana@synopsys.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 apply.c                          | 2 +-
 t/t4135-apply-weird-filenames.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/apply.c b/apply.c
index f8b67bfee2c..107aa4c216e 100644
--- a/apply.c
+++ b/apply.c
@@ -950,7 +950,7 @@ static int gitdiff_verify_name(struct apply_state *state,
 		}
 		free(another);
 	} else {
-		if (!starts_with(line, "/dev/null\n"))
+		if (!is_dev_null(line))
 			return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr);
 	}
 
diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh
index b14b8085786..c7c688fcc4b 100755
--- a/t/t4135-apply-weird-filenames.sh
+++ b/t/t4135-apply-weird-filenames.sh
@@ -100,7 +100,7 @@ deleted file mode 100644
 -
 EOF
 
-test_expect_failure 'apply handles a diff generated by Subversion' '
+test_expect_success 'apply handles a diff generated by Subversion' '
 	>Makefile &&
 	git apply -p2 diff-from-svn &&
 	test_path_is_missing Makefile
-- 
2.16.1.windows.1

```

## Junio C Hamano, 2018-02-15 18:01

Subject: Re: [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully
Message-ID: <xmqqsha29lnt.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqsha29lnt.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <7858c01a2c92a55f86611335bbdcc93c94bc69d2.1518654532.git.johannes.schindelin@gmx.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

>  	} else {
> -		if (!starts_with(line, "/dev/null\n"))
> +		if (!is_dev_null(line))
>  			return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr);
>  	}

Yup.  This seems to be the last explicit/manual check with the
string "/dev/null" (instead of using is_dev_null(), which is how it
should be and already is done in codepaths that guesses -p value and
decides if it is a creation or a deletion patch).

Looks good.  Will queue.

> diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh
> index b14b8085786..c7c688fcc4b 100755
> --- a/t/t4135-apply-weird-filenames.sh
> +++ b/t/t4135-apply-weird-filenames.sh
> @@ -100,7 +100,7 @@ deleted file mode 100644
>  -
>  EOF
>  
> -test_expect_failure 'apply handles a diff generated by Subversion' '
> +test_expect_success 'apply handles a diff generated by Subversion' '
>  	>Makefile &&
>  	git apply -p2 diff-from-svn &&
>  	test_path_is_missing Makefile

```
