summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2018-03-16 05:29:30 +0000
committereadler <eadler@FreeBSD.org>2018-03-16 05:29:30 +0000
commit4403e7c797e638540df826975f43cee7232c2ae3 (patch)
treee19fa9d6801fac3af8eec03803f075a11cec99a5 /usr.bin
parent732967a201a0e3b6cbdc317be99f01113f207881 (diff)
downloadFreeBSD-src-4403e7c797e638540df826975f43cee7232c2ae3.zip
FreeBSD-src-4403e7c797e638540df826975f43cee7232c2ae3.tar.gz
MFC r311106,r311109,r311110,r320579,r327063,r327064,:
patch(1): replace strnlen() with a simpler strlen(). patch(1): add support for git generated diffs. patch: rejname[] is also -r option buffer, and should be PATH_MAX. patch: further cleanup to git-style diffs.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/patch/patch.c6
-rw-r--r--usr.bin/patch/pch.c22
2 files changed, 20 insertions, 8 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 0780b30..b52919f 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -112,7 +112,7 @@ static bool reverse_flag_specified = false;
static bool Vflag = false;
/* buffer holding the name of the rejected patch file. */
-static char rejname[NAME_MAX + 1];
+static char rejname[PATH_MAX];
/* how many input lines have been irretractibly output */
static LINENUM last_frozen_line = 0;
@@ -749,10 +749,10 @@ rej_line(int ch, LINENUM i)
size_t len;
const char *line = pfetch(i);
- len = strnlen(line, USHRT_MAX);
+ len = strlen(line);
fprintf(rejfp, "%c%s", ch, line);
- if (len == 0 || line[len-1] != '\n') {
+ if (len == 0 || line[len - 1] != '\n') {
if (len >= USHRT_MAX)
fprintf(rejfp, "\n\\ Line too long\n");
else
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index eb6285c..0b583ea 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,22 @@ 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 &&
+ strnEQ(s, "--- a/", 6))
+ 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 &&
+ strnEQ(s, "+++ b/", 6))
+ 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 +339,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)
OpenPOWER on IntegriCloud