[Midnightbsd-cvs] src [11459] trunk/usr.bin/patch: sync patch with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 7 12:51:18 EDT 2018
Revision: 11459
http://svnweb.midnightbsd.org/src/?rev=11459
Author: laffer1
Date: 2018-07-07 12:51:18 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync patch with freebsd
Modified Paths:
--------------
trunk/usr.bin/patch/Makefile
trunk/usr.bin/patch/backupfile.c
trunk/usr.bin/patch/backupfile.h
trunk/usr.bin/patch/common.h
trunk/usr.bin/patch/inp.c
trunk/usr.bin/patch/inp.h
trunk/usr.bin/patch/mkpath.c
trunk/usr.bin/patch/patch.1
trunk/usr.bin/patch/patch.c
trunk/usr.bin/patch/pathnames.h
trunk/usr.bin/patch/pch.c
trunk/usr.bin/patch/pch.h
trunk/usr.bin/patch/util.c
trunk/usr.bin/patch/util.h
Modified: trunk/usr.bin/patch/Makefile
===================================================================
--- trunk/usr.bin/patch/Makefile 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/Makefile 2018-07-07 16:51:18 UTC (rev 11459)
@@ -1,6 +1,6 @@
# $MidnightBSD$
# $OpenBSD: Makefile,v 1.4 2005/05/16 15:22:46 espie Exp $
-# $FreeBSD: stable/11/usr.bin/patch/Makefile 255014 2013-08-29 00:38:24Z pfg $
+# $FreeBSD: stable/10/usr.bin/patch/Makefile 255014 2013-08-29 00:38:24Z pfg $
PROG= patch
Modified: trunk/usr.bin/patch/backupfile.c
===================================================================
--- trunk/usr.bin/patch/backupfile.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/backupfile.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -14,7 +14,7 @@
* David MacKenzie <djm at ai.mit.edu>. Some algorithms adapted from GNU Emacs.
*
* $OpenBSD: backupfile.c,v 1.20 2009/10/27 23:59:41 deraadt Exp $
- * $FreeBSD: stable/11/usr.bin/patch/backupfile.c 285772 2015-07-21 22:57:27Z cem $
+ * $FreeBSD: stable/10/usr.bin/patch/backupfile.c 246091 2013-01-29 20:05:16Z delphij $
*/
#include <ctype.h>
@@ -220,11 +220,11 @@
}
static const char *backup_args[] = {
- "none", "never", "simple", "nil", "existing", "t", "numbered", 0
+ "never", "simple", "nil", "existing", "t", "numbered", 0
};
static enum backup_type backup_types[] = {
- none, simple, simple, numbered_existing,
+ simple, simple, numbered_existing,
numbered_existing, numbered, numbered
};
Modified: trunk/usr.bin/patch/backupfile.h
===================================================================
--- trunk/usr.bin/patch/backupfile.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/backupfile.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -12,7 +12,7 @@
* backupfile.h -- declarations for making Emacs style backup file names
*
* $OpenBSD: backupfile.h,v 1.6 2003/07/28 18:35:36 otto Exp $
- * $FreeBSD: stable/11/usr.bin/patch/backupfile.h 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/backupfile.h 246091 2013-01-29 20:05:16Z delphij $
*/
/* When to make backup files. */
Modified: trunk/usr.bin/patch/common.h
===================================================================
--- trunk/usr.bin/patch/common.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/common.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
- * $FreeBSD: stable/11/usr.bin/patch/common.h 286795 2015-08-15 00:42:33Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/common.h 306914 2016-10-09 20:13:53Z pfg $
*/
#include <sys/types.h>
@@ -43,15 +43,20 @@
#define BUFFERSIZE 4096
#define LINENUM_MAX LONG_MAX
+#define SCCSPREFIX "s."
+
+#define RCSSUFFIX ",v"
+#define CHECKOUT "/usr/bin/co"
+#define RCSDIFF "/usr/bin/rcsdiff"
+
#define ORIGEXT ".orig"
#define REJEXT ".rej"
/* handy definitions */
-#define strNE(s1,s2) (strcmp(s1, s2))
-#define strEQ(s1,s2) (!strcmp(s1, s2))
-#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
-#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
+#define strEQ(s1,s2) (strcmp(s1, s2) == 0)
+#define strnNE(s1,s2,l) (strncmp(s1, s2, l) != 0)
+#define strnEQ(s1,s2,l) (strncmp(s1, s2, l) == 0)
/* typedefs */
Modified: trunk/usr.bin/patch/inp.c
===================================================================
--- trunk/usr.bin/patch/inp.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/inp.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $
- * $FreeBSD: stable/11/usr.bin/patch/inp.c 286795 2015-08-15 00:42:33Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/inp.c 287223 2015-08-27 21:52:09Z delphij $
*/
#include <sys/types.h>
@@ -62,9 +62,8 @@
static int tifd = -1; /* plan b virtual string array */
static char *tibuf[2]; /* plan b buffers */
static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */
-static size_t lines_per_buf; /* how many lines per buffer */
-static size_t tibuflen; /* plan b buffer length */
-static size_t tireclen; /* length of records in tmp file */
+static LINENUM lines_per_buf; /* how many lines per buffer */
+static int tireclen; /* length of records in tmp file */
static bool rev_in_string(const char *);
static bool reallocate_lines(size_t *);
@@ -138,12 +137,13 @@
static bool
plan_a(const char *filename)
{
- int ifd, statfailed;
- char *p, *s;
+ int ifd, statfailed, pstat;
+ char *p, *s, lbuf[INITLINELEN];
struct stat filestat;
ptrdiff_t sz;
size_t i;
size_t iline, lines_allocated;
+ pid_t pid;
#ifdef DEBUGGING
if (debug & 8)
@@ -169,8 +169,96 @@
close(creat(filename, 0666));
statfailed = stat(filename, &filestat);
}
- if (statfailed)
- fatal("can't find %s\n", filename);
+ if (statfailed && check_only)
+ fatal("%s not found, -C mode, can't probe further\n", filename);
+ /* For nonexistent or read-only files, look for RCS versions. */
+
+ if (statfailed ||
+ /* No one can write to it. */
+ (filestat.st_mode & 0222) == 0 ||
+ /* I can't write to it. */
+ ((filestat.st_mode & 0022) == 0 && filestat.st_uid != getuid())) {
+ char *filebase, *filedir;
+ struct stat cstat;
+ char *tmp_filename1, *tmp_filename2;
+ char *argp[4] = { NULL };
+ posix_spawn_file_actions_t file_actions;
+
+ tmp_filename1 = strdup(filename);
+ tmp_filename2 = strdup(filename);
+ if (tmp_filename1 == NULL || tmp_filename2 == NULL)
+ fatal("strdupping filename");
+
+ filebase = basename(tmp_filename1);
+ filedir = dirname(tmp_filename2);
+
+ memset(argp, 0, sizeof(argp));
+
+#define try(f, a1, a2, a3) \
+ (snprintf(lbuf, sizeof(lbuf), f, a1, a2, a3), stat(lbuf, &cstat) == 0)
+
+ /*
+ * else we can't write to it but it's not under a version
+ * control system, so just proceed.
+ */
+ if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) ||
+ try("%s/RCS/%s%s", filedir, filebase, "") ||
+ try("%s/%s%s", filedir, filebase, RCSSUFFIX)) {
+ if (!statfailed) {
+ if ((filestat.st_mode & 0222) != 0)
+ /* The owner can write to it. */
+ fatal("file %s seems to be locked "
+ "by somebody else under RCS\n",
+ filename);
+ /*
+ * It might be checked out unlocked. See if
+ * it's safe to check out the default version
+ * locked.
+ */
+ if (verbose)
+ say("Comparing file %s to default "
+ "RCS version...\n", filename);
+
+ argp[0] = __DECONST(char *, RCSDIFF);
+ argp[1] = __DECONST(char *, filename);
+ posix_spawn_file_actions_init(&file_actions);
+ posix_spawn_file_actions_addopen(&file_actions,
+ STDOUT_FILENO, _PATH_DEVNULL, O_WRONLY, 0);
+ if (posix_spawn(&pid, RCSDIFF, &file_actions,
+ NULL, argp, NULL) == 0) {
+ pid = waitpid(pid, &pstat, 0);
+ if (pid == -1 || WEXITSTATUS(pstat) != 0)
+ fatal("can't check out file %s: "
+ "differs from default RCS version\n",
+ filename);
+ } else
+ fatal("posix_spawn: %s\n", strerror(errno));
+ posix_spawn_file_actions_destroy(&file_actions);
+ }
+
+ if (verbose)
+ say("Checking out file %s from RCS...\n",
+ filename);
+
+ argp[0] = __DECONST(char *, CHECKOUT);
+ argp[1] = __DECONST(char *, "-l");
+ argp[2] = __DECONST(char *, filename);
+ if (posix_spawn(&pid, CHECKOUT, NULL, NULL, argp,
+ NULL) == 0) {
+ pid = waitpid(pid, &pstat, 0);
+ if (pid == -1 || WEXITSTATUS(pstat) != 0 ||
+ stat(filename, &filestat))
+ fatal("can't check out file %s from RCS\n",
+ filename);
+ } else
+ fatal("posix_spawn: %s\n", strerror(errno));
+ } else if (statfailed) {
+ fatal("can't find %s\n", filename);
+ }
+ free(tmp_filename1);
+ free(tmp_filename2);
+ }
+
filemode = filestat.st_mode;
if (!S_ISREG(filemode))
fatal("%s is not a normal file--can't patch\n", filename);
@@ -252,7 +340,7 @@
/* now check for revision, if any */
if (revision != NULL) {
- if (i_womp == NULL || !rev_in_string(i_womp)) {
+ if (!rev_in_string(i_womp)) {
if (force) {
if (verbose)
say("Warning: this file doesn't appear "
@@ -282,8 +370,8 @@
plan_b(const char *filename)
{
FILE *ifp;
- size_t i = 0, j, len, maxlen = 1;
- char *lbuf = NULL, *p;
+ size_t i = 0, j, maxlen = 1;
+ char *p;
bool found_revision = (revision == NULL);
using_plan_a = false;
@@ -292,28 +380,15 @@
unlink(TMPINNAME);
if ((tifd = open(TMPINNAME, O_EXCL | O_CREAT | O_WRONLY, 0666)) < 0)
pfatal("can't open file %s", TMPINNAME);
- while ((p = fgetln(ifp, &len)) != NULL) {
- if (p[len - 1] == '\n')
- p[len - 1] = '\0';
- else {
- /* EOF without EOL, copy and add the NUL */
- if ((lbuf = malloc(len + 1)) == NULL)
- fatal("out of memory\n");
- memcpy(lbuf, p, len);
- lbuf[len] = '\0';
- p = lbuf;
-
- last_line_missing_eol = true;
- len++;
- }
- if (revision != NULL && !found_revision && rev_in_string(p))
+ while (fgets(buf, buf_size, ifp) != NULL) {
+ if (revision != NULL && !found_revision && rev_in_string(buf))
found_revision = true;
- if (len > maxlen)
- maxlen = len; /* find longest line */
+ if ((i = strlen(buf)) > maxlen)
+ maxlen = i; /* find longest line */
}
- free(lbuf);
- if (ferror(ifp))
- pfatal("can't read file %s", filename);
+ last_line_missing_eol = i > 0 && buf[i - 1] != '\n';
+ if (last_line_missing_eol && maxlen == i)
+ maxlen++;
if (revision != NULL) {
if (!found_revision) {
@@ -338,26 +413,23 @@
revision);
}
fseek(ifp, 0L, SEEK_SET); /* rewind file */
+ lines_per_buf = BUFFERSIZE / maxlen;
tireclen = maxlen;
- tibuflen = maxlen > BUFFERSIZE ? maxlen : BUFFERSIZE;
- lines_per_buf = tibuflen / maxlen;
- tibuf[0] = malloc(tibuflen + 1);
+ tibuf[0] = malloc(BUFFERSIZE + 1);
if (tibuf[0] == NULL)
fatal("out of memory\n");
- tibuf[1] = malloc(tibuflen + 1);
+ tibuf[1] = malloc(BUFFERSIZE + 1);
if (tibuf[1] == NULL)
fatal("out of memory\n");
for (i = 1;; i++) {
p = tibuf[0] + maxlen * (i % lines_per_buf);
if (i % lines_per_buf == 0) /* new block */
- if (write(tifd, tibuf[0], tibuflen) !=
- (ssize_t) tibuflen)
+ if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
pfatal("can't write temp file");
if (fgets(p, maxlen + 1, ifp) == NULL) {
input_lines = i - 1;
if (i % lines_per_buf != 0)
- if (write(tifd, tibuf[0], tibuflen) !=
- (ssize_t) tibuflen)
+ if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
pfatal("can't write temp file");
break;
}
@@ -399,11 +471,10 @@
tiline[whichbuf] = baseline;
if (lseek(tifd, (off_t) (baseline / lines_per_buf *
- tibuflen), SEEK_SET) < 0)
+ BUFFERSIZE), SEEK_SET) < 0)
pfatal("cannot seek in the temporary input file");
- if (read(tifd, tibuf[whichbuf], tibuflen) !=
- (ssize_t) tibuflen)
+ if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
pfatal("error reading tmp file %s", TMPINNAME);
}
return tibuf[whichbuf] + (tireclen * offline);
Modified: trunk/usr.bin/patch/inp.h
===================================================================
--- trunk/usr.bin/patch/inp.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/inp.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: inp.h,v 1.8 2003/08/15 08:00:51 otto Exp $
- * $FreeBSD: stable/11/usr.bin/patch/inp.h 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/inp.h 246091 2013-01-29 20:05:16Z delphij $
*/
void re_input(void);
Modified: trunk/usr.bin/patch/mkpath.c
===================================================================
--- trunk/usr.bin/patch/mkpath.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/mkpath.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -28,7 +28,7 @@
* SUCH DAMAGE.
*
* $OpenBSD: mkpath.c,v 1.2 2005/06/20 07:14:06 otto Exp $
- * $FreeBSD: stable/11/usr.bin/patch/mkpath.c 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/mkpath.c 246091 2013-01-29 20:05:16Z delphij $
*/
#include <sys/types.h>
Modified: trunk/usr.bin/patch/patch.1
===================================================================
--- trunk/usr.bin/patch/patch.1 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/patch.1 2018-07-07 16:51:18 UTC (rev 11459)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"-
.\" Copyright 1986, Larry Wall
.\"
@@ -20,8 +21,8 @@
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: patch.1,v 1.27 2014/04/15 06:26:54 jmc Exp $
-.\" $FreeBSD: stable/11/usr.bin/patch/patch.1 286795 2015-08-15 00:42:33Z delphij $
-.Dd August 15, 2015
+.\" $FreeBSD: stable/10/usr.bin/patch/patch.1 267747 2014-06-22 20:29:51Z pfg $
+.Dd June 15, 2014
.Dt PATCH 1
.Os
.Sh NAME
@@ -39,7 +40,7 @@
.Op Fl o Ar out-file
.Op Fl p Ar strip-count
.Op Fl r Ar rej-name
-.Op Fl V Cm t | nil | never | none
+.Op Fl V Cm t | nil | never
.Op Fl x Ar number
.Op Fl z Ar backup-ext
.Op Fl Fl posix
@@ -175,7 +176,7 @@
.Fl Fl input Ar patchfile
.Xc
Causes the next argument to be interpreted as the input file name
-(i.e., a patchfile).
+(i.e. a patchfile).
This option may be specified multiple times.
.It Fl l , Fl Fl ignore-whitespace
Causes the pattern matching to be done loosely, in case the tabs and
@@ -245,7 +246,7 @@
Tells
.Nm
that this patch was created with the old and new files swapped.
-(Yes, I am afraid that does happen occasionally, human nature being what it
+(Yes, I'm afraid that does happen occasionally, human nature being what it
is.)
.Nm
will attempt to swap each hunk around before applying it.
@@ -263,7 +264,7 @@
option set.
If it cannot, the patch will continue to be applied normally.
(Note: this method cannot detect a reversed patch if it is a normal diff
-and if the first command is an append (i.e., it should have been a delete)
+and if the first command is an append (i.e. it should have been a delete)
since appends always succeed, due to the fact that a null context will match
anywhere.
Luckily, most patches add or change lines rather than delete them, so most
@@ -296,8 +297,8 @@
.Nm
to interpret the patch file as a unified context diff (a unidiff).
.It Xo
-.Fl V Cm t | nil | never | none ,
-.Fl Fl version-control Cm t | nil | never | none
+.Fl V Cm t | nil | never ,
+.Fl Fl version-control Cm t | nil | never
.Xc
Causes the next argument to be interpreted as a method for creating
backup file names.
@@ -328,8 +329,6 @@
simple backups of the others.
.It Cm never , simple
Always make simple backups.
-.It Cm none
-Do not make backups.
.El
.It Fl v , Fl Fl version
Causes
@@ -387,7 +386,7 @@
First
.Nm
looks for a place where all lines of the context match.
-If no such place is found, and it is a context diff, and the maximum fuzz factor
+If no such place is found, and it's a context diff, and the maximum fuzz factor
is set to 1 or more, then another scan takes place ignoring the first and last
line of context.
If that fails, and the maximum fuzz factor is set to 2 or more,
@@ -483,6 +482,15 @@
file name, and choose the file name with the fewest path components,
the shortest basename, and the shortest total file name length (in that order).
.It
+If no file exists,
+.Nm
+checks for the existence of the files in an SCCS or RCS directory
+(using the appropriate prefix or suffix) using the criteria specified
+above.
+If found,
+.Nm
+will attempt to get or check out the file.
+.It
If no suitable file was found to patch, the patch file is a context or
unified diff, and the old file was zero length, the new file name is
created and used.
Modified: trunk/usr.bin/patch/patch.c
===================================================================
--- trunk/usr.bin/patch/patch.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/patch.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $
- * $FreeBSD: stable/11/usr.bin/patch/patch.c 298531 2016-04-24 04:28:04Z pfg $
+ * $FreeBSD: stable/10/usr.bin/patch/patch.c 276807 2015-01-08 03:44:54Z pfg $
*
*/
@@ -110,8 +110,6 @@
/* true if -R was specified on command line. */
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];
@@ -204,7 +202,7 @@
Argv = argv;
get_some_switches();
- if (!Vflag) {
+ if (backup_type == none) {
if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
v = getenv("VERSION_CONTROL");
if (v != NULL || !posix)
@@ -598,7 +596,6 @@
break;
case 'V':
backup_type = get_version(optarg);
- Vflag = true;
break;
#ifdef DEBUGGING
case 'x':
@@ -635,8 +632,8 @@
fprintf(stderr,
"usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]\n"
" [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n"
-" [-r rej-name] [-V t | nil | never | none] [-x number]\n"
-" [-z backup-ext] [--posix] [origfile [patchfile]]\n"
+" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
+" [--posix] [origfile [patchfile]]\n"
" patch <patchfile\n");
my_exit(EXIT_FAILURE);
}
@@ -747,7 +744,7 @@
static void
rej_line(int ch, LINENUM i)
{
- size_t len;
+ unsigned short len;
const char *line = pfetch(i);
len = strnlen(line, USHRT_MAX);
Modified: trunk/usr.bin/patch/pathnames.h
===================================================================
--- trunk/usr.bin/patch/pathnames.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/pathnames.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -4,7 +4,7 @@
* on July 29, 2003.
*
* $OpenBSD: pathnames.h,v 1.1 2003/07/29 20:10:17 millert Exp $
- * $FreeBSD: stable/11/usr.bin/patch/pathnames.h 286346 2015-08-05 22:04:54Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/pathnames.h 286348 2015-08-05 22:05:02Z delphij $
*/
Modified: trunk/usr.bin/patch/pch.c
===================================================================
--- trunk/usr.bin/patch/pch.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/pch.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: pch.c,v 1.43 2014/11/18 17:03:35 tobias Exp $
- * $FreeBSD: stable/11/usr.bin/patch/pch.c 298530 2016-04-24 04:08:36Z pfg $
+ * $FreeBSD: stable/10/usr.bin/patch/pch.c 320086 2017-06-18 21:48:33Z pfg $
*/
#include <sys/types.h>
@@ -217,8 +217,10 @@
filearg[0] = fetchname(buf, &exists, 0);
}
if (!exists) {
- ask("No file found--skip this patch? [n] ");
- if (*buf != 'y')
+ int def_skip = *bestguess == '\0';
+ ask("No file found--skip this patch? [%c] ",
+ def_skip ? 'y' : 'n');
+ if (*buf == 'n' || (!def_skip && *buf != 'y'))
continue;
if (verbose)
say("Skipping patch...\n");
@@ -1502,9 +1504,18 @@
}
if (path == NULL && !assume_exists) {
/*
- * No files found, check to see if the diff could be
- * creating a new file.
+ * No files found, look for something we can checkout from
+ * RCS/SCCS dirs. Same order as above.
*/
+ for (i = 0; i < MAX_FILE; i++) {
+ if (names[i].path != NULL &&
+ (path = checked_in(names[i].path)) != NULL)
+ break;
+ }
+ /*
+ * Still no match? Check to see if the diff could be creating
+ * a new file.
+ */
if (path == NULL && ok_to_create_file &&
names[NEW_FILE].path != NULL)
path = names[NEW_FILE].path;
@@ -1514,7 +1525,7 @@
}
static char *
-compare_names(const struct file_name *names, bool assume_exists)
+compare_names(const struct file_name *names, bool assume_exists, int phase)
{
size_t min_components, min_baselen, min_len, tmp;
char *best = NULL;
@@ -1531,7 +1542,9 @@
min_components = min_baselen = min_len = SIZE_MAX;
for (i = INDEX_FILE; i >= OLD_FILE; i--) {
path = names[i].path;
- if (path == NULL || (!names[i].exists && !assume_exists))
+ if (path == NULL ||
+ (phase == 1 && !names[i].exists && !assume_exists) ||
+ (phase == 2 && checked_in(path) == NULL))
continue;
if ((tmp = num_components(path)) > min_components)
continue;
@@ -1562,12 +1575,18 @@
{
char *best;
- best = compare_names(names, assume_exists);
+ best = compare_names(names, assume_exists, 1);
+ if (best == NULL) {
+ best = compare_names(names, assume_exists, 2);
+ /*
+ * Still no match? Check to see if the diff could be creating
+ * a new file.
+ */
+ if (best == NULL && ok_to_create_file &&
+ names[NEW_FILE].path != NULL)
+ best = names[NEW_FILE].path;
+ }
- /* No match? Check to see if the diff could be creating a new file. */
- if (best == NULL && ok_to_create_file)
- best = names[NEW_FILE].path;
-
return best ? xstrdup(best) : NULL;
}
Modified: trunk/usr.bin/patch/pch.h
===================================================================
--- trunk/usr.bin/patch/pch.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/pch.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: pch.h,v 1.9 2003/10/31 20:20:45 millert Exp $
- * $FreeBSD: stable/11/usr.bin/patch/pch.h 267490 2014-06-15 03:54:23Z pfg $
+ * $FreeBSD: stable/10/usr.bin/patch/pch.h 267746 2014-06-22 20:24:17Z pfg $
*/
#define OLD_FILE 0
Modified: trunk/usr.bin/patch/util.c
===================================================================
--- trunk/usr.bin/patch/util.c 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/util.c 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,7 +25,7 @@
* behaviour
*
* $OpenBSD: util.c,v 1.35 2010/07/24 01:10:12 ray Exp $
- * $FreeBSD: stable/11/usr.bin/patch/util.c 286795 2015-08-15 00:42:33Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/util.c 287223 2015-08-27 21:52:09Z delphij $
*/
#include <sys/stat.h>
@@ -400,10 +400,36 @@
return name;
}
+/*
+ * Takes the name returned by fetchname and looks in RCS/SCCS directories
+ * for a checked in version.
+ */
+char *
+checked_in(char *file)
+{
+ char *filebase, *filedir, tmpbuf[PATH_MAX];
+ struct stat filestat;
+
+ filebase = basename(file);
+ filedir = dirname(file);
+
+#define try(f, a1, a2, a3) \
+(snprintf(tmpbuf, sizeof tmpbuf, f, a1, a2, a3), stat(tmpbuf, &filestat) == 0)
+
+ if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) ||
+ try("%s/RCS/%s%s", filedir, filebase, "") ||
+ try("%s/%s%s", filedir, filebase, RCSSUFFIX) ||
+ try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) ||
+ try("%s/%s%s", filedir, SCCSPREFIX, filebase))
+ return file;
+
+ return NULL;
+}
+
void
version(void)
{
- printf("patch 2.0-12u11 MidnightBSD\n");
+ printf("patch 2.0-12u10 FreeBSD\n");
my_exit(EXIT_SUCCESS);
}
Modified: trunk/usr.bin/patch/util.h
===================================================================
--- trunk/usr.bin/patch/util.h 2018-07-07 16:51:00 UTC (rev 11458)
+++ trunk/usr.bin/patch/util.h 2018-07-07 16:51:18 UTC (rev 11459)
@@ -25,10 +25,11 @@
* behaviour
*
* $OpenBSD: util.h,v 1.16 2014/12/13 10:31:07 tobias Exp $
- * $FreeBSD: stable/11/usr.bin/patch/util.h 286795 2015-08-15 00:42:33Z delphij $
+ * $FreeBSD: stable/10/usr.bin/patch/util.h 276807 2015-01-08 03:44:54Z pfg $
*/
char *fetchname(const char *, bool *, int);
+char *checked_in(char *);
int backup_file(const char *);
int move_file(const char *, const char *);
int copy_file(const char *, const char *);
More information about the Midnightbsd-cvs
mailing list