Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Mar 2018 05:29:31 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331047 - stable/11/usr.bin/patch
Message-ID:  <201803160529.w2G5TVgh066709@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Fri Mar 16 05:29:30 2018
New Revision: 331047
URL: https://svnweb.freebsd.org/changeset/base/331047

Log:
  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.

Modified:
  stable/11/usr.bin/patch/patch.c
  stable/11/usr.bin/patch/pch.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/patch/patch.c
==============================================================================
--- stable/11/usr.bin/patch/patch.c	Fri Mar 16 05:23:48 2018	(r331046)
+++ stable/11/usr.bin/patch/patch.c	Fri Mar 16 05:29:30 2018	(r331047)
@@ -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

Modified: stable/11/usr.bin/patch/pch.c
==============================================================================
--- stable/11/usr.bin/patch/pch.c	Fri Mar 16 05:23:48 2018	(r331046)
+++ stable/11/usr.bin/patch/pch.c	Fri Mar 16 05:29:30 2018	(r331047)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803160529.w2G5TVgh066709>