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 | |
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')
-rw-r--r-- | usr.bin/cvs/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/cvs/checkout.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/cmd.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/commit.c | 25 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.h | 18 | ||||
-rw-r--r-- | usr.bin/cvs/history.c | 156 | ||||
-rw-r--r-- | usr.bin/cvs/tag.c | 3 | ||||
-rw-r--r-- | usr.bin/cvs/update.c | 7 |
8 files changed, 212 insertions, 11 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile index e47b522cfa9..a3e7ee6c623 100644 --- a/usr.bin/cvs/Makefile +++ b/usr.bin/cvs/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.38 2007/04/15 13:23:59 jmc Exp $ +# $OpenBSD: Makefile,v 1.39 2007/06/18 17:54:12 joris Exp $ PROG= opencvs MAN= cvs.1 cvs.5 cvsintro.7 @@ -6,8 +6,8 @@ CPPFLAGS+=-I${.CURDIR} SRCS= cvs.c add.c admin.c annotate.c commit.c config.c checkout.c client.c \ buf.c cmd.c date.y diff.c diff3.c diff_internals.c edit.c entries.c \ - fatal.c file.c getlog.c log.c logmsg.c import.c init.c remove.c \ - repository.c rcs.c rcsnum.c remote.c root.c server.c \ + fatal.c file.c getlog.c history.c log.c logmsg.c import.c init.c \ + remove.c repository.c rcs.c rcsnum.c remote.c root.c server.c \ status.c tag.c worklist.c util.c update.c version.c watch.c xmalloc.c CFLAGS+=-Wall diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index b044af1cbbb..b73dc53cda1 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.93 2007/06/01 17:47:47 niallo Exp $ */ +/* $OpenBSD: checkout.c,v 1.94 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -189,6 +189,8 @@ checkout_repository(const char *repobase, const char *wdbase) TAILQ_INIT(&fl); TAILQ_INIT(&dl); + cvs_history_add(CVS_HISTORY_CHECKOUT, NULL, wdbase); + build_dirs = 1; cr.enterdir = cvs_update_enterdir; cr.leavedir = cvs_update_leavedir; diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c index 67c602b73ce..3ffcd358706 100644 --- a/usr.bin/cvs/cmd.c +++ b/usr.bin/cvs/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.57 2007/02/22 06:42:09 otto Exp $ */ +/* $OpenBSD: cmd.c,v 1.58 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -40,6 +40,7 @@ struct cvs_cmd *cvs_cdt[] = { &cvs_cmd_checkout, &cvs_cmd_diff, &cvs_cmd_export, + &cvs_cmd_history, &cvs_cmd_import, &cvs_cmd_init, &cvs_cmd_log, @@ -53,7 +54,6 @@ struct cvs_cmd *cvs_cdt[] = { &cvs_cmd_checkout, &cvs_cmd_edit, &cvs_cmd_editors, - &cvs_cmd_history, #if 0 &cvs_cmd_login, &cvs_cmd_logout, diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c index 4c68519b07f..2d686047b7a 100644 --- a/usr.bin/cvs/commit.c +++ b/usr.bin/cvs/commit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commit.c,v 1.106 2007/06/01 17:47:47 niallo Exp $ */ +/* $OpenBSD: commit.c,v 1.107 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> @@ -207,7 +207,7 @@ void cvs_commit_local(struct cvs_file *cf) { BUF *b, *d; - int isnew; + int isnew, histtype; RCSNUM *head; int openflags, rcsflags; char rbuf[24], nbuf[24]; @@ -223,6 +223,13 @@ cvs_commit_local(struct cvs_file *cf) if (cf->file_type != CVS_FILE) fatal("cvs_commit_local: '%s' is not a file", cf->file_path); + if (cf->file_status != FILE_MODIFIED && + cf->file_status != FILE_ADDED && + cf->file_status != FILE_REMOVED) { + cvs_log(LP_ERR, "skipping bogus file `%s'", cf->file_path); + return; + } + if (cf->file_status == FILE_MODIFIED || cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1)) { @@ -379,6 +386,20 @@ cvs_commit_local(struct cvs_file *cf) cvs_log(LP_NOTICE, "checking in '%s'; revision %s -> %s", cf->file_path, rbuf, nbuf); } + + switch (cf->file_status) { + case FILE_MODIFIED: + histtype = CVS_HISTORY_COMMIT_MODIFIED; + break; + case FILE_ADDED: + histtype = CVS_HISTORY_COMMIT_ADDED; + break; + case FILE_REMOVED: + histtype = CVS_HISTORY_COMMIT_REMOVED; + break; + } + + cvs_history_add(histtype, cf, NULL); } static BUF * diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index f00e1464ff5..b444305bc7f 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.135 2007/03/22 17:18:19 xsa Exp $ */ +/* $OpenBSD: cvs.h,v 1.136 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -146,6 +146,21 @@ #define CVS_PATH_UPDATEPROG CVS_PATH_CVSDIR "/Update.prog" #define CVS_PATH_ATTIC "Attic" +/* history stuff */ +#define CVS_HISTORY_TAG 0 +#define CVS_HISTORY_CHECKOUT 1 +#define CVS_HISTORY_EXPORT 2 +#define CVS_HISTORY_RELEASE 3 +#define CVS_HISTORY_UPDATE_REMOVE 4 +#define CVS_HISTORY_UPDATE_CO 5 +#define CVS_HISTORY_UPDATE_MERGED 6 +#define CVS_HISTORY_UPDATE_MERGED_ERR 7 +#define CVS_HISTORY_COMMIT_MODIFIED 8 +#define CVS_HISTORY_COMMIT_ADDED 9 +#define CVS_HISTORY_COMMIT_REMOVED 10 + +void cvs_history_add(int, struct cvs_file *, const char *); + struct cvs_cmd { u_int cmd_op; u_int cmd_req; @@ -383,6 +398,7 @@ int cvs_edit(int, char **); int cvs_editors(int, char **); int cvs_export(int, char **); int cvs_getlog(int, char **); +int cvs_history(int, char **); int cvs_import(int, char **); int cvs_init(int, char **); int cvs_remove(int, char **); 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); +} diff --git a/usr.bin/cvs/tag.c b/usr.bin/cvs/tag.c index db79702d9f5..d59118b603b 100644 --- a/usr.bin/cvs/tag.c +++ b/usr.bin/cvs/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.55 2007/02/22 06:42:09 otto Exp $ */ +/* $OpenBSD: tag.c,v 1.56 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> * @@ -215,6 +215,7 @@ cvs_tag_local(struct cvs_file *cf) cvs_printf("T %s\n", cf->file_path); rcs_write(cf->file_rcs); + cvs_history_add(CVS_HISTORY_TAG, cf, tag_name); } break; default: diff --git a/usr.bin/cvs/update.c b/usr.bin/cvs/update.c index dce2818db7f..3af6f48fcae 100644 --- a/usr.bin/cvs/update.c +++ b/usr.bin/cvs/update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: update.c,v 1.99 2007/06/01 17:47:47 niallo Exp $ */ +/* $OpenBSD: update.c,v 1.100 2007/06/18 17:54:13 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -340,15 +340,19 @@ cvs_update_local(struct cvs_file *cf) cvs_checkout_file(cf, cf->file_rcsrev, flags); cvs_printf("U %s\n", cf->file_path); + cvs_history_add(CVS_HISTORY_UPDATE_CO, cf, NULL); break; case FILE_MERGE: cvs_checkout_file(cf, cf->file_rcsrev, CO_MERGE); if (diff3_conflicts != 0) { cvs_printf("C %s\n", cf->file_path); + cvs_history_add(CVS_HISTORY_UPDATE_MERGED_ERR, + cf, NULL); } else { update_clear_conflict(cf); cvs_printf("M %s\n", cf->file_path); + cvs_history_add(CVS_HISTORY_UPDATE_MERGED, cf, NULL); } break; case FILE_UNLINK: @@ -357,6 +361,7 @@ cvs_update_local(struct cvs_file *cf) entlist = cvs_ent_open(cf->file_wd); cvs_ent_remove(entlist, cf->file_name); cvs_ent_close(entlist, ENT_SYNC); + cvs_history_add(CVS_HISTORY_UPDATE_REMOVE, cf, NULL); break; default: break; |