Our patch was modified a while ago to cope a bit better with git diffs
containing a/ and b/.  There is still a common case where things don't
work as they should. Consider this simple patch:

        diff --git a/afile b/afile
        new file mode 100644
        index 00000000000..9daeafb9864
        --- /dev/null
        +++ b/afile
        @@ -0,0 +1 @@
        +test

Doing 'patch < addfile' will create 'null' and 'null.orig' files with
the null file containing the string 'test', which is obviously not what
we want.

The diff below only skips 6 letters if they actually are '--- a/' or
'+++ b/' and seems to do the trick for me in various scenarios.

Index: usr.bin/patch/pch.c
===================================================================
RCS file: /var/cvs/src/usr.bin/patch/pch.c,v
retrieving revision 1.58
diff -u -p -r1.58 pch.c
--- usr.bin/patch/pch.c 30 May 2017 06:55:40 -0000      1.58
+++ usr.bin/patch/pch.c 20 Dec 2017 12:16:15 -0000
@@ -301,14 +301,16 @@ intuit_diff_type(void)
                            &names[OLD_FILE].exists, strippath);
                else if (strnEQ(s, "--- ", 4)) {
                        size_t off = 4;
-                       if (piece_of_git && strippath == 957)
+                       if (piece_of_git && strippath == 957 &&
+                           strnEQ(s, "--- a/", 6))
                                off = 6;
                        names[NEW_FILE].path = fetchname(s + off,
                            &names[NEW_FILE].exists, strippath);
                } else if (strnEQ(s, "+++ ", 4)) {
                        /* pretend it is the old name */
                        size_t off = 4;
-                       if (piece_of_git && strippath == 957)
+                       if (piece_of_git && strippath == 957 &&
+                           strnEQ(s, "+++ b/", 6))
                                off = 6;
                        names[OLD_FILE].path = fetchname(s + off,
                            &names[OLD_FILE].exists, strippath);

Reply via email to