diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2007-06-18 17:54:14 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2007-06-18 17:54:14 +0000 |
commit | 357cd6706be35fc84900218b72b77a745a95ea3f (patch) | |
tree | f961aff0c604d664734c59d0ba52d2dd4d46938c /usr.bin/cvs/history.c | |
parent | 9ad5361739bdd9774873986561736d7d4c62130d (diff) |
first stab at history stuff for opencvs, currently only writes
to CVSROOT/history but cannot parse it yet with the 'history' command.
"Commit it." ray@
Diffstat (limited to 'usr.bin/cvs/history.c')
-rw-r--r-- | usr.bin/cvs/history.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/usr.bin/cvs/history.c b/usr.bin/cvs/history.c new file mode 100644 index 00000000000..79c6e8b5674 --- /dev/null +++ b/usr.bin/cvs/history.c @@ -0,0 +1,156 @@ +/* $OpenBSD: history.c,v 1.28 2007/06/18 17:54:13 joris Exp $ */ +/* + * Copyright (c) 2007 Joris Vink <joris@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/stat.h> + +#include <ctype.h> +#include <errno.h> +#include <pwd.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "cvs.h" +#include "remote.h" + +void cvs_history_local(struct cvs_file *); + +struct cvs_cmd cvs_cmd_history = { + CVS_OP_HISTORY, 0, "history", + { "hi" }, /* omghi2you */ + "Display the history of actions done in the base repository", + "[-ac]", + "ac", + NULL, + cvs_history +}; + +/* keep in sync with the defines for history stuff in cvs.h */ +const char historytab[] = { + 'T', + 'O', + 'E', + 'F', + 'W', + 'U', + 'G', + 'C', + 'M', + 'A', + 'R', + NULL +}; + +#define HISTORY_ALL_USERS 0x01 +#define HISTORY_DISPLAY_ARCHIVED 0x02 + +void +cvs_history_add(int type, struct cvs_file *cf, const char *argument) +{ + FILE *fp; + char *cwd; + char revbuf[64], repo[MAXPATHLEN], fpath[MAXPATHLEN]; + + if (cvs_nolog == 1) + return; + + if (cvs_cmdop == CVS_OP_CHECKOUT || cvs_cmdop == CVS_OP_EXPORT) { + if (type != CVS_HISTORY_CHECKOUT && + type != CVS_HISTORY_EXPORT) + return; + } + + cvs_log(LP_TRACE, "cvs_history_add(`%c', `%s', `%s')", + historytab[type], (cf != NULL) ? cf->file_name : "", argument); + + if ((cwd = getcwd(NULL, MAXPATHLEN)) == NULL) + fatal("cvs_history_add: getcwd: %s", strerror(errno)); + + /* construct repository field */ + if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) { + cvs_get_repository_name(".", repo, sizeof(repo)); + + if (strlen(repo) > strlen(cwd)) + fatal("bad repository `%s'", repo); + } else { + strlcpy(repo, argument, sizeof(repo)); + } + + /* construct revision field */ + revbuf[0] = '\0'; + if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) { + switch (type) { + case CVS_HISTORY_TAG: + strlcpy(revbuf, argument, sizeof(revbuf)); + break; + case CVS_HISTORY_CHECKOUT: + case CVS_HISTORY_EXPORT: + /* copy TAG or DATE to revbuf */ + break; + case CVS_HISTORY_UPDATE_MERGED: + case CVS_HISTORY_UPDATE_MERGED_ERR: + case CVS_HISTORY_COMMIT_MODIFIED: + case CVS_HISTORY_COMMIT_ADDED: + case CVS_HISTORY_COMMIT_REMOVED: + case CVS_HISTORY_UPDATE_CO: + rcsnum_tostr(cf->file_rcs->rf_head, + revbuf, sizeof(revbuf)); + break; + } + } + + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", + current_cvsroot->cr_dir, CVS_PATH_HISTORY); + + if ((fp = fopen(fpath, "a")) != NULL) { + fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n", + historytab[type], time(NULL), getlogin(), cwd, repo, + revbuf, (cf != NULL) ? cf->file_name : argument); + + (void)fclose(fp); + } else { + cvs_log(LP_ERR, "failed to add entry to history file"); + } + + xfree(cwd); +} + +int +cvs_history(int argc, char **argv) +{ + int ch, flags; + + flags = 0; + + while ((ch = getopt(argc, argv, cvs_cmd_history.cmd_opts)) != -1) { + switch (ch) { + case 'a': + flags |= HISTORY_ALL_USERS; + break; + case 'c': + flags |= HISTORY_DISPLAY_ARCHIVED; + break; + default: + fatal("%s", cvs_cmd_history.cmd_synopsis); + } + } + + argc -= optind; + argv += optind; + + return (0); +} |