From 8f0fa46a51c4e203af1cda3f6a4669748518d523 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 May 1997 05:15:29 +0000 Subject: [PATCH] One of the new cvs's features is to be able to run a checker on the log messages after they've been entered. This is more flexible than using the editinfo script since it works for all log message types and doesn't have to deal with trying to run the editor for the user. The problem is that the verifymsg script can't modify the file like editinfo can, which makes it useless for cleaning up the message (as is needed for remote commits etc). This change causes the verifymsg handler to read back the message after the verify script has run and returned an "OK" exit code. --- contrib/cvs/src/commit.c | 6 ++-- contrib/cvs/src/cvs.h | 2 +- contrib/cvs/src/import.c | 2 +- contrib/cvs/src/logmsg.c | 67 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/contrib/cvs/src/commit.c b/contrib/cvs/src/commit.c index c43e35f35383..7ae1ce7bbeab 100644 --- a/contrib/cvs/src/commit.c +++ b/contrib/cvs/src/commit.c @@ -486,7 +486,7 @@ commit (argc, argv) /* Run the user-defined script to verify/check information in *the log message */ - do_verify (message, (char *)NULL); + do_verify (&message, (char *)NULL); /* We always send some sort of message, even if empty. */ option_with_arg ("-m", message); @@ -1110,7 +1110,7 @@ commit_fileproc (callerdat, finfo) got_message = 1; if (use_editor) do_editor (finfo->update_dir, &message, finfo->repository, ulist); - do_verify (message, finfo->repository); + do_verify (&message, finfo->repository); } p = findnode (cilist, finfo->file); @@ -1400,7 +1400,7 @@ commit_direntproc (callerdat, dir, repos, update_dir, entries) got_message = 1; if (use_editor) do_editor (update_dir, &message, real_repos, ulist); - do_verify (message, real_repos); + do_verify (&message, real_repos); free (real_repos); return (R_PROCESS); } diff --git a/contrib/cvs/src/cvs.h b/contrib/cvs/src/cvs.h index 8079e30b72a3..4596d0fa9282 100644 --- a/contrib/cvs/src/cvs.h +++ b/contrib/cvs/src/cvs.h @@ -539,7 +539,7 @@ void Update_Logfile PROTO((char *repository, char *xmessage, FILE * xlogfp, void do_editor PROTO((char *dir, char **messagep, char *repository, List * changes)); -void do_verify PROTO((char *message, char *repository)); +void do_verify PROTO((char **messagep, char *repository)); typedef int (*CALLBACKPROC) PROTO((int *pargc, char *argv[], char *where, char *mwhere, char *mfile, int horten, int local_specified, diff --git a/contrib/cvs/src/import.c b/contrib/cvs/src/import.c index c05fa0df5153..933e38caefc2 100644 --- a/contrib/cvs/src/import.c +++ b/contrib/cvs/src/import.c @@ -195,7 +195,7 @@ import (argc, argv) do_editor ((char *) NULL, &message, repository, (List *) NULL); } - do_verify (message, repository); + do_verify (&message, repository); msglen = message == NULL ? 0 : strlen (message); if (msglen == 0 || message[msglen - 1] != '\n') { diff --git a/contrib/cvs/src/logmsg.c b/contrib/cvs/src/logmsg.c index 2655fd9214d2..7f83183c1549 100644 --- a/contrib/cvs/src/logmsg.c +++ b/contrib/cvs/src/logmsg.c @@ -377,14 +377,20 @@ do_editor (dir, messagep, repository, changes) independant of the running of an editor for getting a message. */ void -do_verify (message, repository) - char *message; +do_verify (messagep, repository) + char **messagep; char *repository; { FILE *fp; char *fname; int retcode = 0; + char *line; + int line_length; + size_t line_chars_allocated; + char *p; + struct stat stbuf; + #ifdef CLIENT_SUPPORT if (client_active) /* The verification will happen on the server. */ @@ -398,7 +404,7 @@ do_verify (message, repository) /* If there's no message, then we have nothing to verify. Can this case happen? And if so why would we print a message? */ - if (message == NULL) + if (*messagep == NULL) { cvs_output ("No message to verify\n", 0); return; @@ -417,9 +423,9 @@ do_verify (message, repository) } else { - fprintf (fp, "%s", message); - if ((message)[0] == '\0' || - (message)[strlen (message) - 1] != '\n') + fprintf (fp, "%s", *messagep); + if ((*messagep)[0] == '\0' || + (*messagep)[strlen (*messagep) - 1] != '\n') (void) fprintf (fp, "%s", "\n"); if (fclose (fp) == EOF) error (1, errno, "%s", fname); @@ -442,6 +448,55 @@ do_verify (message, repository) "Message verification failed"); } + /* put the entire message back into the *messagep variable */ + + fp = open_file (fname, "r"); + if (fp == NULL) + { + error (1, errno, "cannot open temporary file %s", fname); + return; + } + + if (*messagep) + free (*messagep); + + if ( CVS_STAT (fname, &stbuf) != 0) + error (1, errno, "cannot find size of temp file %s", fname); + + if (stbuf.st_size == 0) + *messagep = NULL; + else + { + /* On NT, we might read less than st_size bytes, but we won't + read more. So this works. */ + *messagep = (char *) xmalloc (stbuf.st_size + 1); + *messagep[0] = '\0'; + } + + line = NULL; + line_chars_allocated = 0; + + if (*messagep) + { + p = *messagep; + while (1) + { + line_length = getline (&line, &line_chars_allocated, fp); + if (line_length == -1) + { + if (ferror (fp)) + error (0, errno, "warning: cannot read %s", fname); + break; + } + if (strncmp (line, CVSEDITPREFIX, CVSEDITPREFIXLEN) == 0) + continue; + (void) strcpy (p, line); + p += line_length; + } + } + if (fclose (fp) < 0) + error (0, errno, "warning: cannot close %s", fname); + /* Close and delete the temp file */ unlink_file (fname);