* [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs
@ 2018-02-15 0:29 Johannes Schindelin
2018-02-15 0:29 ` [PATCH 1/2] apply: demonstrate a problem applying svn diffs Johannes Schindelin
2018-02-15 0:29 ` [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully Johannes Schindelin
0 siblings, 2 replies; 4+ messages in thread
From: Johannes Schindelin @ 2018-02-15 0:29 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] apply: demonstrate a problem applying svn diffs
2018-02-15 0:29 [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs Johannes Schindelin
@ 2018-02-15 0:29 ` Johannes Schindelin
2018-02-15 0:29 ` [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully Johannes Schindelin
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2018-02-15 0:29 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully
2018-02-15 0:29 [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs Johannes Schindelin
2018-02-15 0:29 ` [PATCH 1/2] apply: demonstrate a problem applying svn diffs Johannes Schindelin
@ 2018-02-15 0:29 ` Johannes Schindelin
2018-02-15 18:01 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2018-02-15 0:29 UTC (permalink / raw)
To: git; +Cc: Tatyana Krasnukha, Junio C Hamano
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully
2018-02-15 0:29 ` [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully Johannes Schindelin
@ 2018-02-15 18:01 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2018-02-15 18:01 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Tatyana Krasnukha
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-02-15 18:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 0:29 [PATCH 0/2] Teach `git apply` to accept Subversion-generated diffs Johannes Schindelin
2018-02-15 0:29 ` [PATCH 1/2] apply: demonstrate a problem applying svn diffs Johannes Schindelin
2018-02-15 0:29 ` [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully Johannes Schindelin
2018-02-15 18:01 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).