From 9b87f93448fdfd5ec12156b7bcdb288c675ed0b8 Mon Sep 17 00:00:00 2001 From: Jean-Francois Brousseau Date: Wed, 8 Dec 2004 17:22:49 +0000 Subject: embrace and extend (!) cvs_logmsg_get() so we can now display information based on its availability and have separate sections for the Added, Modified and Removed file lists. this will allow us to use the same call for add, commit, import and possibly others Original patch by Joris Vink, some rework from me for the other sections --- usr.bin/cvs/commit.c | 16 ++++++------- usr.bin/cvs/cvs.h | 4 ++-- usr.bin/cvs/logmsg.c | 66 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 52 insertions(+), 34 deletions(-) (limited to 'usr.bin/cvs') diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c index 3e45dfc6d05..1528ddde12f 100644 --- a/usr.bin/cvs/commit.c +++ b/usr.bin/cvs/commit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commit.c,v 1.9 2004/12/07 17:10:56 tedu Exp $ */ +/* $OpenBSD: commit.c,v 1.10 2004/12/08 17:22:48 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -56,33 +56,33 @@ int cvs_commit_file (CVSFILE *, void *); int cvs_commit(int argc, char **argv) { - int i, ch, recurse, flags; + int i, ch, flags; char *msg, *mfile; struct cvs_flist cl; struct cvsroot *root; flags = CF_RECURSE|CF_IGNORE|CF_SORT; - recurse = 1; mfile = NULL; msg = NULL; TAILQ_INIT(&cl); - while ((ch = getopt(argc, argv, "F:flm:R")) != -1) { + while ((ch = getopt(argc, argv, "F:flm:Rr:")) != -1) { switch (ch) { case 'F': mfile = optarg; break; case 'f': - recurse = 0; + /* XXX half-implemented */ + flags &= ~CF_RECURSE; break; case 'l': - recurse = 0; + flags &= ~CF_RECURSE; break; case 'm': msg = optarg; break; case 'R': - recurse = 1; + flags |= CF_RECURSE; break; default: return (EX_USAGE); @@ -111,7 +111,7 @@ cvs_commit(int argc, char **argv) cvs_file_examine(cvs_files, cvs_commit_prepare, &cl); if (msg == NULL) { - msg = cvs_logmsg_get(CVS_FILE_NAME(cvs_files), &cl); + msg = cvs_logmsg_get(CVS_FILE_NAME(cvs_files), NULL, &cl, NULL); if (msg == NULL) return (1); } diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index 1c6d8370ecf..54c09dc980a 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.36 2004/12/08 16:07:43 jfb Exp $ */ +/* $OpenBSD: cvs.h,v 1.37 2004/12/08 17:22:48 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -282,7 +282,7 @@ int cvs_hist_append (CVSHIST *, struct cvs_hent *); /* from logmsg.c */ char* cvs_logmsg_open (const char *); -char* cvs_logmsg_get (const char *, struct cvs_flist *); +char* cvs_logmsg_get (const char *, struct cvs_flist *, struct cvs_flist *, struct cvs_flist *); int cvs_logmsg_send (struct cvsroot *, const char *); /* from util.c */ diff --git a/usr.bin/cvs/logmsg.c b/usr.bin/cvs/logmsg.c index 625ecd110af..ced24f38d52 100644 --- a/usr.bin/cvs/logmsg.c +++ b/usr.bin/cvs/logmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logmsg.c,v 1.7 2004/12/07 17:10:56 tedu Exp $ */ +/* $OpenBSD: logmsg.c,v 1.8 2004/12/08 17:22:48 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -42,10 +42,15 @@ #define CVS_LOGMSG_BIGMSG 32000 #define CVS_LOGMSG_FTMPL "/tmp/cvsXXXXXXXXXX" #define CVS_LOGMSG_PREFIX "CVS:" -#define CVS_LOGMSG_LOGLINE \ +#define CVS_LOGMSG_LINE \ "----------------------------------------------------------------------" +static const char *cvs_logmsg_ops[3] = { + "Added", "Modified", "Removed", +}; + + /* * cvs_logmsg_open() * @@ -140,19 +145,29 @@ cvs_logmsg_open(const char *path) /* * cvs_logmsg_get() * - * Get a log message by forking and executing the user's editor. + * Get a log message by forking and executing the user's editor. The + * argument is a relative path to the directory for which the log message + * applies, and the 3 tail queue arguemnts contains all the files for which the + * log message will apply. Any of these arguments can be set to NULL in the + * case where there is no information to display. * Returns the message in a dynamically allocated string on success, NULL on * failure. */ char* -cvs_logmsg_get(const char *dir, struct cvs_flist *files) +cvs_logmsg_get(const char *dir, struct cvs_flist *added, + struct cvs_flist *modified, struct cvs_flist *removed) { - int ret, fd, argc, fds[3], nl; + int i, fd, argc, fds[3], nl; size_t len, tlen; char *argv[4], buf[16], path[MAXPATHLEN], fpath[MAXPATHLEN], *msg; FILE *fp; CVSFILE *cvsfp; struct stat st1, st2; + struct cvs_flist *files[3]; + + files[0] = added; + files[1] = modified; + files[2] = removed; msg = NULL; fds[0] = -1; @@ -176,20 +191,24 @@ cvs_logmsg_get(const char *dir, struct cvs_flist *files) if (unlink(path) == -1) cvs_log(LP_ERRNO, "failed to unlink temporary file"); return (NULL); - } else { - fprintf(fp, - "\n%s %s\n%s Enter Log. Lines beginning with `%s' are " - "removed automatically\n%s\n%s Commiting in %s\n" - "%s\n", - CVS_LOGMSG_PREFIX, CVS_LOGMSG_LOGLINE, - CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX, - CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX, - dir, CVS_LOGMSG_PREFIX); - - /* XXX list files here */ - fprintf(fp, "%s Modified Files:", CVS_LOGMSG_PREFIX); + } + + fprintf(fp, "\n%s %s\n%s Enter Log. Lines beginning with `%s' are " + "removed automatically\n%s\n", CVS_LOGMSG_PREFIX, CVS_LOGMSG_LINE, + CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX); + + if (dir != NULL) + fprintf(fp, "%s Commiting in %s\n%s\n", CVS_LOGMSG_PREFIX, dir, + CVS_LOGMSG_PREFIX); + + for (i = 0; i < 3; i++) { + if (files[i] == NULL) + continue; + + fprintf(fp, "%s %s Files:", CVS_LOGMSG_PREFIX, + cvs_logmsg_ops[i]); nl = 1; - TAILQ_FOREACH(cvsfp, files, cf_list) { + TAILQ_FOREACH(cvsfp, files[i], cf_list) { /* take the space into account */ cvs_file_getpath(cvsfp, fpath, sizeof(fpath)); len = strlen(fpath) + 1; @@ -206,8 +225,7 @@ cvs_logmsg_get(const char *dir, struct cvs_flist *files) tlen += len; } - fprintf(fp, "\n%s %s\n", CVS_LOGMSG_PREFIX, - CVS_LOGMSG_LOGLINE); + fprintf(fp, "\n%s %s\n", CVS_LOGMSG_PREFIX, CVS_LOGMSG_LINE); } (void)fflush(fp); @@ -221,9 +239,9 @@ cvs_logmsg_get(const char *dir, struct cvs_flist *files) } for (;;) { - ret = cvs_exec(argc, argv, fds); - if (ret == -1) + if (cvs_exec(argc, argv, fds) < 0) break; + if (fstat(fd, &st2) == -1) { cvs_log(LP_ERRNO, "failed to stat log message file"); break; @@ -256,9 +274,9 @@ cvs_logmsg_get(const char *dir, struct cvs_flist *files) /* empty message */ msg = strdup(""); break; - } else if (ret == 'e') + } else if (buf[0] == 'e') continue; - else if (ret == '!') { + else if (buf[0] == '!') { /* XXX do something */ } } -- cgit v1.2.3