summaryrefslogtreecommitdiff
path: root/contrib/cvs/src/patch.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cvs/src/patch.c')
-rw-r--r--contrib/cvs/src/patch.c174
1 files changed, 95 insertions, 79 deletions
diff --git a/contrib/cvs/src/patch.c b/contrib/cvs/src/patch.c
index e6a25f5ccb302..cba6a8a02fa85 100644
--- a/contrib/cvs/src/patch.c
+++ b/contrib/cvs/src/patch.c
@@ -17,8 +17,8 @@
#include "getline.h"
static RETSIGTYPE patch_cleanup PROTO((void));
-static Dtype patch_dirproc PROTO ((void *callerdat, char *dir,
- char *repos, char *update_dir,
+static Dtype patch_dirproc PROTO ((void *callerdat, const char *dir,
+ const char *repos, const char *update_dir,
List *entries));
static int patch_fileproc PROTO ((void *callerdat, struct file_info *finfo));
static int patch_proc PROTO((int argc, char **argv, char *xwhere,
@@ -58,6 +58,8 @@ static const char *const patch_usage[] =
NULL
};
+
+
int
patch (argc, argv)
int argc;
@@ -86,7 +88,7 @@ patch (argc, argv)
#endif
error (1, 0,
"-q or -Q must be specified before \"%s\"",
- command_name);
+ cvs_cmd_name);
break;
case 'f':
force_tag_match = 0;
@@ -232,34 +234,36 @@ patch (argc, argv)
/* clean up if we get a signal */
#ifdef SIGABRT
- (void) SIG_register (SIGABRT, patch_cleanup);
+ (void)SIG_register (SIGABRT, patch_cleanup);
#endif
#ifdef SIGHUP
- (void) SIG_register (SIGHUP, patch_cleanup);
+ (void)SIG_register (SIGHUP, patch_cleanup);
#endif
#ifdef SIGINT
- (void) SIG_register (SIGINT, patch_cleanup);
+ (void)SIG_register (SIGINT, patch_cleanup);
#endif
#ifdef SIGQUIT
- (void) SIG_register (SIGQUIT, patch_cleanup);
+ (void)SIG_register (SIGQUIT, patch_cleanup);
#endif
#ifdef SIGPIPE
- (void) SIG_register (SIGPIPE, patch_cleanup);
+ (void)SIG_register (SIGPIPE, patch_cleanup);
#endif
#ifdef SIGTERM
- (void) SIG_register (SIGTERM, patch_cleanup);
+ (void)SIG_register (SIGTERM, patch_cleanup);
#endif
db = open_module ();
for (i = 0; i < argc; i++)
err += do_module (db, argv[i], PATCH, "Patching", patch_proc,
- (char *) NULL, 0, 0, 0, 0, (char *) NULL);
+ (char *)NULL, 0, local, 0, 0, (char *)NULL);
close_module (db);
free (options);
patch_cleanup ();
- return (err);
+ return err;
}
+
+
/*
* callback proc for doing the real work of patching
*/
@@ -283,12 +287,14 @@ patch_proc (argc, argv, xwhere, mwhere, mfile, shorten, local_specified,
char *repository;
char *where;
- repository = xmalloc (strlen (current_parsed_root->directory) + strlen (argv[0])
+ repository = xmalloc (strlen (current_parsed_root->directory)
+ + strlen (argv[0])
+ (mfile == NULL ? 0 : strlen (mfile) + 1) + 2);
- (void) sprintf (repository, "%s/%s", current_parsed_root->directory, argv[0]);
+ (void)sprintf (repository, "%s/%s",
+ current_parsed_root->directory, argv[0]);
where = xmalloc (strlen (argv[0]) + (mfile == NULL ? 0 : strlen (mfile) + 1)
+ 1);
- (void) strcpy (where, argv[0]);
+ (void)strcpy (where, argv[0]);
/* if mfile isn't null, we need to set up to do only part of the module */
if (mfile != NULL)
@@ -300,22 +306,22 @@ patch_proc (argc, argv, xwhere, mwhere, mfile, shorten, local_specified,
if ((cp = strrchr (mfile, '/')) != NULL)
{
*cp = '\0';
- (void) strcat (repository, "/");
- (void) strcat (repository, mfile);
- (void) strcat (where, "/");
- (void) strcat (where, mfile);
+ (void)strcat (repository, "/");
+ (void)strcat (repository, mfile);
+ (void)strcat (where, "/");
+ (void)strcat (where, mfile);
mfile = cp + 1;
}
/* take care of the rest */
path = xmalloc (strlen (repository) + strlen (mfile) + 2);
- (void) sprintf (path, "%s/%s", repository, mfile);
+ (void)sprintf (path, "%s/%s", repository, mfile);
if (isdir (path))
{
/* directory means repository gets the dir tacked on */
- (void) strcpy (repository, path);
- (void) strcat (where, "/");
- (void) strcat (where, mfile);
+ (void)strcpy (repository, path);
+ (void)strcat (where, "/");
+ (void)strcat (where, mfile);
}
else
{
@@ -332,9 +338,8 @@ patch_proc (argc, argv, xwhere, mwhere, mfile, shorten, local_specified,
{
error (0, errno, "cannot chdir to %s", repository);
free (repository);
- return (1);
+ return 1;
}
- free (repository);
if (force_tag_match)
which = W_REPOS | W_ATTIC;
@@ -343,25 +348,30 @@ patch_proc (argc, argv, xwhere, mwhere, mfile, shorten, local_specified,
if (rev1 != NULL && !rev1_validated)
{
- tag_check_valid (rev1, argc - 1, argv + 1, local_specified, 0, NULL);
+ tag_check_valid (rev1, argc - 1, argv + 1, local_specified, 0,
+ repository);
rev1_validated = 1;
}
if (rev2 != NULL && !rev2_validated)
{
- tag_check_valid (rev2, argc - 1, argv + 1, local_specified, 0, NULL);
+ tag_check_valid (rev2, argc - 1, argv + 1, local_specified, 0,
+ repository);
rev2_validated = 1;
}
/* start the recursion processor */
- err = start_recursion (patch_fileproc, (FILESDONEPROC) NULL, patch_dirproc,
- (DIRLEAVEPROC) NULL, NULL,
+ err = start_recursion (patch_fileproc, (FILESDONEPROC)NULL, patch_dirproc,
+ (DIRLEAVEPROC)NULL, NULL,
argc - 1, argv + 1, local_specified,
- which, 0, CVS_LOCK_READ, where, 1);
+ which, 0, CVS_LOCK_READ, where, 1, repository);
+ free (repository);
free (where);
- return (err);
+ return err;
}
+
+
/*
* Called to examine a particular RCS file, as appropriate with the options
* that were set above.
@@ -394,6 +404,7 @@ patch_fileproc (callerdat, finfo)
line1_chars_allocated = 0;
line2 = NULL;
line2_chars_allocated = 0;
+ vers_tag = vers_head = NULL;
/* find the parsed rcs file */
if ((rcsfile = finfo->rcs) == NULL)
@@ -449,53 +460,38 @@ patch_fileproc (callerdat, finfo)
vers_tag = NULL;
}
- if (vers_tag == NULL && vers_head == NULL)
+ if ((vers_tag == NULL && vers_head == NULL) ||
+ (vers_tag != NULL && vers_head != NULL &&
+ strcmp (vers_head, vers_tag) == 0))
{
- /* Nothing known about specified revs. */
+ /* Nothing known about specified revs or
+ * not changed between releases.
+ */
ret = 0;
goto out2;
}
- if (vers_tag && vers_head && strcmp (vers_head, vers_tag) == 0)
- {
- /* Not changed between releases. */
- ret = 0;
- goto out2;
- }
-
- if (patch_short)
+ if( patch_short && ( vers_tag == NULL || vers_head == NULL ) )
{
+ /* For adds & removes with a short patch requested, we can print our
+ * error message now and get out.
+ */
cvs_output ("File ", 0);
cvs_output (finfo->fullname, 0);
if (vers_tag == NULL)
{
- cvs_output (" is new; current revision ", 0);
+ cvs_output( " is new; ", 0 );
+ cvs_output( rev2 ? rev2 : date2 ? date2 : "current", 0 );
+ cvs_output( " revision ", 0 );
cvs_output (vers_head, 0);
cvs_output ("\n", 1);
}
- else if (vers_head == NULL)
- {
- cvs_output (" is removed; not included in ", 0);
- if (rev2 != NULL)
- {
- cvs_output ("release tag ", 0);
- cvs_output (rev2, 0);
- }
- else if (date2 != NULL)
- {
- cvs_output ("release date ", 0);
- cvs_output (date2, 0);
- }
- else
- cvs_output ("current release", 0);
- cvs_output ("\n", 1);
- }
else
{
- cvs_output (" changed from revision ", 0);
- cvs_output (vers_tag, 0);
- cvs_output (" to ", 0);
- cvs_output (vers_head, 0);
+ cvs_output( " is removed; ", 0 );
+ cvs_output( rev1 ? rev1 : date1, 0 );
+ cvs_output( " revision ", 0 );
+ cvs_output( vers_tag, 0 );
cvs_output ("\n", 1);
}
ret = 0;
@@ -541,9 +537,9 @@ patch_fileproc (callerdat, finfo)
if (vers_tag != NULL)
{
- retcode = RCS_checkout (rcsfile, (char *) NULL, vers_tag,
+ retcode = RCS_checkout (rcsfile, (char *)NULL, vers_tag,
rev1, options, tmpfile1,
- (RCSCHECKOUTPROC) NULL, (void *) NULL);
+ (RCSCHECKOUTPROC)NULL, (void *)NULL);
if (retcode != 0)
{
error (0, 0,
@@ -565,9 +561,9 @@ patch_fileproc (callerdat, finfo)
}
if (vers_head != NULL)
{
- retcode = RCS_checkout (rcsfile, (char *) NULL, vers_head,
+ retcode = RCS_checkout (rcsfile, (char *)NULL, vers_head,
rev2, options, tmpfile2,
- (RCSCHECKOUTPROC) NULL, (void *) NULL);
+ (RCSCHECKOUTPROC)NULL, (void *)NULL);
if (retcode != 0)
{
error (0, 0,
@@ -576,13 +572,14 @@ patch_fileproc (callerdat, finfo)
goto out;
}
if ((t.actime = t.modtime = RCS_getrevtime (rcsfile, vers_head,
- (char *) 0, 0)) != -1)
+ (char *)0, 0)) != -1)
/* I believe this timestamp only affects the dates in our diffs,
and therefore should be on the server, not the client. */
- (void) utime (tmpfile2, &t);
+ (void)utime (tmpfile2, &t);
}
- switch (diff_exec (tmpfile1, tmpfile2, NULL, NULL, unidiff ? "-u" : "-c", tmpfile3))
+ switch (diff_exec (tmpfile1, tmpfile2, NULL, NULL, unidiff ? "-u" : "-c",
+ tmpfile3))
{
case -1: /* fork/wait failure */
error (1, errno, "fork for diff failed on %s", rcs);
@@ -593,14 +590,29 @@ patch_fileproc (callerdat, finfo)
/*
* The two revisions are really different, so read the first two
* lines of the diff output file, and munge them to include more
- * reasonable file names that "patch" will understand.
+ * reasonable file names that "patch" will understand, unless the
+ * user wanted a short patch. In that case, just output the short
+ * message.
*/
+ if( patch_short )
+ {
+ cvs_output ("File ", 0);
+ cvs_output (finfo->fullname, 0);
+ cvs_output (" changed from revision ", 0);
+ cvs_output (vers_tag, 0);
+ cvs_output (" to ", 0);
+ cvs_output (vers_head, 0);
+ cvs_output ("\n", 1);
+ ret = 0;
+ goto out;
+ }
/* Output an "Index:" line for patch to use */
cvs_output ("Index: ", 0);
cvs_output (finfo->fullname, 0);
cvs_output ("\n", 1);
+ /* Now the munging. */
fp = open_file (tmpfile3, "r");
if (getline (&line1, &line1_chars_allocated, fp) < 0 ||
getline (&line2, &line2_chars_allocated, fp) < 0)
@@ -648,8 +660,10 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
assert (current_parsed_root != NULL);
assert (current_parsed_root->directory != NULL);
{
- strippath = xmalloc (strlen (current_parsed_root->directory) + 2);
- (void) sprintf (strippath, "%s/", current_parsed_root->directory);
+ strippath = xmalloc (strlen (current_parsed_root->directory)
+ + 2);
+ (void)sprintf (strippath, "%s/",
+ current_parsed_root->directory);
}
/*else
strippath = xstrdup (REPOS_STRIP); */
@@ -661,7 +675,7 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
file1 = xmalloc (strlen (finfo->fullname)
+ strlen (vers_tag)
+ 10);
- (void) sprintf (file1, "%s:%s", finfo->fullname, vers_tag);
+ (void)sprintf (file1, "%s:%s", finfo->fullname, vers_tag);
}
else
{
@@ -670,8 +684,8 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
file2 = xmalloc (strlen (finfo->fullname)
+ (vers_head != NULL ? strlen (vers_head) : 10)
+ 10);
- (void) sprintf (file2, "%s:%s", finfo->fullname,
- vers_head ? vers_head : "removed");
+ (void)sprintf (file2, "%s:%s", finfo->fullname,
+ vers_head ? vers_head : "removed");
/* Note that the string "diff" is specified by POSIX (for -c)
and is part of the diff output format, not the name of a
@@ -745,9 +759,11 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
free (vers_head);
if (rcs != NULL)
free (rcs);
- return (ret);
+ return ret;
}
+
+
/*
* Print a warm fuzzy message
*/
@@ -755,9 +771,9 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
static Dtype
patch_dirproc (callerdat, dir, repos, update_dir, entries)
void *callerdat;
- char *dir;
- char *repos;
- char *update_dir;
+ const char *dir;
+ const char *repos;
+ const char *update_dir;
List *entries;
{
if (!quiet)