summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortedu <tedu>2017-05-26 20:27:02 +0000
committertedu <tedu>2017-05-26 20:27:02 +0000
commit320acd7b3c9e36ec2de9fb16bf17a62a047c94b7 (patch)
treec5e6ba7570c6c2765e6e01ec9df5c42f8e8b8d26
parent8136c931d5322d33d25b8bd7de5514b8b1c0d6b6 (diff)
downloadpatch-320acd7b3c9e36ec2de9fb16bf17a62a047c94b7.tar
patch-320acd7b3c9e36ec2de9fb16bf17a62a047c94b7.tar.gz
sometimes patches coming from other places have extra a/ and b/ directories
prepended to filenames. detect this condition and attempt to correct it. ok openbsd
-rw-r--r--pch.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/pch.c b/pch.c
index d443f42..2619b4e 100644
--- a/pch.c
+++ b/pch.c
@@ -254,6 +254,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;
@@ -298,14 +299,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)) {
@@ -320,7 +327,8 @@ intuit_diff_type(void)
free(revision);
revision = NULL;
}
- }
+ } else if (strnEQ(s, "diff --git ", 11))
+ piece_of_git = 1;
if ((!diff_type || diff_type == ED_DIFF) &&
first_command_line >= 0 &&
strEQ(s, ".\n")) {