Remove automatic checkout feature.

Obtained from:	DragonFly via OpenBSD
Relnotes:	yes
MFC:		never
This commit is contained in:
Xin LI 2015-08-15 00:42:33 +00:00
parent 1558258bc4
commit e678759c30
6 changed files with 19 additions and 167 deletions

View File

@ -42,12 +42,6 @@
#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"

View File

@ -137,13 +137,12 @@ reallocate_lines(size_t *lines_allocated)
static bool
plan_a(const char *filename)
{
int ifd, statfailed, pstat;
char *p, *s, lbuf[INITLINELEN];
int ifd, statfailed;
char *p, *s;
struct stat filestat;
ptrdiff_t sz;
size_t i;
size_t iline, lines_allocated;
pid_t pid;
#ifdef DEBUGGING
if (debug & 8)
@ -169,96 +168,8 @@ plan_a(const char *filename)
close(creat(filename, 0666));
statfailed = stat(filename, &filestat);
}
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);
}
if (statfailed)
fatal("can't find %s\n", filename);
filemode = filestat.st_mode;
if (!S_ISREG(filemode))
fatal("%s is not a normal file--can't patch\n", filename);

View File

@ -21,7 +21,7 @@
.\"
.\" $OpenBSD: patch.1,v 1.27 2014/04/15 06:26:54 jmc Exp $
.\" $FreeBSD$
.Dd July 21, 2015
.Dd August 15, 2015
.Dt PATCH 1
.Os
.Sh NAME
@ -175,7 +175,7 @@ for that.
.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 +245,7 @@ option.
Tells
.Nm
that this patch was created with the old and new files swapped.
(Yes, I'm afraid that does happen occasionally, human nature being what it
(Yes, I am afraid that does happen occasionally, human nature being what it
is.)
.Nm
will attempt to swap each hunk around before applying it.
@ -263,7 +263,7 @@ If it can, you will be asked if you want to have the
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
@ -387,7 +387,7 @@ given in the hunk.
First
.Nm
looks for a place where all lines of the context match.
If no such place is found, and it's a context diff, and the maximum fuzz factor
If no such place is found, and it is 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,15 +483,6 @@ file names or, for a non-context diff, the
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.

View File

@ -1501,17 +1501,8 @@ posix_name(const struct file_name *names, bool assume_exists)
}
if (path == NULL && !assume_exists) {
/*
* 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.
* No files found, check to see if the diff could be
* creating a new file.
*/
if (path == NULL && ok_to_create_file &&
names[NEW_FILE].path != NULL)
@ -1522,7 +1513,7 @@ posix_name(const struct file_name *names, bool assume_exists)
}
static char *
compare_names(const struct file_name *names, bool assume_exists, int phase)
compare_names(const struct file_name *names, bool assume_exists)
{
size_t min_components, min_baselen, min_len, tmp;
char *best = NULL;
@ -1539,9 +1530,7 @@ compare_names(const struct file_name *names, bool assume_exists, int phase)
min_components = min_baselen = min_len = SIZE_MAX;
for (i = INDEX_FILE; i >= OLD_FILE; i--) {
path = names[i].path;
if (path == NULL ||
(phase == 1 && !names[i].exists && !assume_exists) ||
(phase == 2 && checked_in(path) == NULL))
if (path == NULL || (!names[i].exists && !assume_exists))
continue;
if ((tmp = num_components(path)) > min_components)
continue;
@ -1572,17 +1561,11 @@ best_name(const struct file_name *names, bool assume_exists)
{
char *best;
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;
}
best = compare_names(names, assume_exists);
/* 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;
}

View File

@ -399,36 +399,10 @@ fetchname(const char *at, bool *exists, int strip_leading)
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-12u10 FreeBSD\n");
printf("patch 2.0-12u11 FreeBSD\n");
my_exit(EXIT_SUCCESS);
}

View File

@ -28,7 +28,6 @@
*/
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 *);