threads / patch / 47851

patch, 2 partsTeach `git apply` to accept Subversion-generated diffs

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

## tl;dr

4 messages between Feb 15, 2018 and Feb 15, 2018. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Johannes Schindelin· Feb 15, 2018, 00:29 UTC · lore

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· Feb 15, 2018, 00:29 UTC · re: Johannes Schindelin · lore

[PATCH 1/2] apply: demonstrate a problem applying svn diffs

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(+)
Show changes to t/t4135-apply-weird-filenames.sh +16 −0
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· Feb 15, 2018, 00:29 UTC · re: Johannes Schindelin · lore

[PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully

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(-)
Show changes to 2 files +2 −2

apply.c, t/t4135-apply-weird-filenames.sh

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· Feb 15, 2018, 18:01 UTC · re: Johannes Schindelin · lore

Re: [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully

Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 5 quoted lines
>  	} 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.
Show 13 quoted lines
> 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

← back to recent threads