diff options
author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2017-07-02 21:00:30 +0000 |
---|---|---|
committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2017-07-02 21:00:30 +0000 |
commit | 85823a601c1ede44a844edde4f1d18643903ce54 (patch) | |
tree | ec3eeeaffdf1d8b7e9443891070e3fce7abdb3f4 | |
parent | 3d851dbe07a7712f57da949c54ce4005470e5bc8 (diff) | |
download | src-85823a601c1ede44a844edde4f1d18643903ce54.tar.gz src-85823a601c1ede44a844edde4f1d18643903ce54.zip |
patch(1): add support for git generated diffs.
Sometimes patches coming from other places have extra a/ and b/
directories prepended to filenames.
Obtained from: OpenBSD (CVS rev. 1.57, 1.58)
Notes
Notes:
svn path=/head/; revision=320579
-rw-r--r-- | usr.bin/patch/pch.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 95853b507ee2..563c539b5686 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -264,6 +264,7 @@ intuit_diff_type(void) char *s, *t; int indent, retval; struct file_name names[MAX_FILE]; + int piece_of_git = 0; memset(names, 0, sizeof(names)); ok_to_create_file = false; @@ -308,14 +309,20 @@ intuit_diff_type(void) if (!stars_last_line && strnEQ(s, "*** ", 4)) names[OLD_FILE].path = fetchname(s + 4, &names[OLD_FILE].exists, strippath); - else if (strnEQ(s, "--- ", 4)) - names[NEW_FILE].path = fetchname(s + 4, + else if (strnEQ(s, "--- ", 4)) { + size_t off = 4; + if (piece_of_git && strippath == 957) + off = 6; + names[NEW_FILE].path = fetchname(s + off, &names[NEW_FILE].exists, strippath); - else if (strnEQ(s, "+++ ", 4)) + } else if (strnEQ(s, "+++ ", 4)) { /* pretend it is the old name */ - names[OLD_FILE].path = fetchname(s + 4, + size_t off = 4; + if (piece_of_git && strippath == 957) + off = 6; + names[OLD_FILE].path = fetchname(s + off, &names[OLD_FILE].exists, strippath); - else if (strnEQ(s, "Index:", 6)) + } else if (strnEQ(s, "Index:", 6)) names[INDEX_FILE].path = fetchname(s + 6, &names[INDEX_FILE].exists, strippath); else if (strnEQ(s, "Prereq:", 7)) { @@ -330,6 +337,9 @@ intuit_diff_type(void) free(revision); revision = NULL; } + } else if (strnEQ(s, "diff --git a/", 13)) { + /* Git-style diffs. */ + piece_of_git = 1; } else if (strnEQ(s, "==== ", 5)) { /* Perforce-style diffs. */ if ((t = strstr(s + 5, " - ")) != NULL) |