Annotation of src/usr.bin/cvs/getlog.c, Revision 1.54
1.54 ! xsa 1: /* $OpenBSD: getlog.c,v 1.53 2006/01/29 11:09:45 xsa Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.10 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.10 tedu 6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
1.1 jfb 9: *
1.10 tedu 10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
1.1 jfb 12: * 2. The name of the author may not be used to endorse or promote products
1.10 tedu 13: * derived from this software without specific prior written permission.
1.1 jfb 14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
1.10 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
1.51 xsa 27: #include "includes.h"
1.1 jfb 28:
29: #include "cvs.h"
30: #include "log.h"
1.3 jfb 31: #include "proto.h"
1.1 jfb 32:
33:
1.43 xsa 34: #define CVS_GLOG_RFONLY 0x01
35: #define CVS_GLOG_HDONLY 0x02
1.1 jfb 36:
37:
1.43 xsa 38: #define CVS_GETLOG_REVSEP "----------------------------"
1.1 jfb 39: #define CVS_GETLOG_REVEND \
40: "============================================================================="
41:
1.43 xsa 42: static int cvs_getlog_init(struct cvs_cmd *, int, char **, int *);
43: static int cvs_getlog_remote(CVSFILE *, void *);
44: static int cvs_getlog_local(CVSFILE *, void *);
45: static int cvs_getlog_pre_exec(struct cvsroot *);
1.1 jfb 46:
1.29 jfb 47: struct cvs_cmd cvs_cmd_log = {
48: CVS_OP_LOG, CVS_REQ_LOG, "log",
49: { "lo" },
50: "Print out history information for files",
51: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.30 xsa 52: "bd:hlNRr:s:tw:",
1.29 jfb 53: NULL,
1.40 joris 54: CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33 xsa 55: cvs_getlog_init,
56: cvs_getlog_pre_exec,
1.29 jfb 57: cvs_getlog_remote,
58: cvs_getlog_local,
59: NULL,
60: NULL,
61: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
62: };
63:
64:
65: struct cvs_cmd cvs_cmd_rlog = {
66: CVS_OP_LOG, CVS_REQ_LOG, "log",
67: { "lo" },
68: "Print out history information for files",
69: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
70: "d:hlRr:",
71: NULL,
1.40 joris 72: CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33 xsa 73: cvs_getlog_init,
74: cvs_getlog_pre_exec,
1.21 jfb 75: cvs_getlog_remote,
1.29 jfb 76: cvs_getlog_local,
77: NULL,
78: NULL,
1.16 joris 79: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
80: };
81:
1.21 jfb 82: static int log_rfonly = 0;
83: static int log_honly = 0;
1.25 xsa 84: static int log_lhonly = 0;
1.21 jfb 85: static int log_notags = 0;
1.1 jfb 86:
1.25 xsa 87: static int
1.33 xsa 88: cvs_getlog_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 89: {
1.16 joris 90: int ch;
1.1 jfb 91:
1.29 jfb 92: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.16 joris 93: switch (ch) {
1.25 xsa 94: case 'b':
95: break;
1.1 jfb 96: case 'd':
97: break;
98: case 'h':
1.21 jfb 99: log_honly = 1;
1.1 jfb 100: break;
101: case 'l':
1.29 jfb 102: cmd->file_flags &= ~CF_RECURSE;
1.1 jfb 103: break;
1.21 jfb 104: case 'N':
105: log_notags = 1;
106: break;
1.1 jfb 107: case 'R':
1.21 jfb 108: log_rfonly = 1;
1.1 jfb 109: break;
110: case 'r':
111: break;
1.25 xsa 112: case 's':
113: break;
114: case 't':
115: log_lhonly = 1;
116: break;
117: case 'w':
118: break;
1.1 jfb 119: default:
1.19 joris 120: return (CVS_EX_USAGE);
1.1 jfb 121: }
122: }
123:
1.16 joris 124: *arg = optind;
1.1 jfb 125: return (0);
126: }
127:
1.25 xsa 128: static int
1.33 xsa 129: cvs_getlog_pre_exec(struct cvsroot *root)
1.25 xsa 130: {
1.33 xsa 131: if (root->cr_method != CVS_METHOD_LOCAL) {
1.50 xsa 132: if (log_honly == 1)
1.49 joris 133: cvs_sendarg(root, "-h", 0);
1.50 xsa 134: if (log_notags == 1)
1.49 joris 135: cvs_sendarg(root, "-N", 0);
1.50 xsa 136: if (log_rfonly == 1)
1.49 joris 137: cvs_sendarg(root, "-R", 0);
1.50 xsa 138: if (log_lhonly == 1)
1.49 joris 139: cvs_sendarg(root, "-t", 0);
1.33 xsa 140: }
1.25 xsa 141: return (0);
142: }
1.1 jfb 143:
1.6 jfb 144: /*
1.21 jfb 145: * cvs_getlog_remote()
1.6 jfb 146: *
147: */
148: static int
1.21 jfb 149: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6 jfb 150: {
1.46 xsa 151: char fpath[MAXPATHLEN];
1.6 jfb 152: struct cvsroot *root;
153:
1.12 jfb 154: root = CVS_DIR_ROOT(cf);
1.7 jfb 155:
1.13 jfb 156: if (cf->cf_type == DT_DIR) {
1.20 jfb 157: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
1.49 joris 158: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20 jfb 159: else
1.49 joris 160: cvs_senddir(root, cf);
161: return (0);
1.6 jfb 162: }
163:
1.12 jfb 164: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6 jfb 165:
1.49 joris 166: cvs_sendentry(root, cf);
1.12 jfb 167:
1.20 jfb 168: switch (cf->cf_cvstat) {
169: case CVS_FST_UNKNOWN:
1.49 joris 170: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20 jfb 171: break;
172: case CVS_FST_UPTODATE:
1.49 joris 173: cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20 jfb 174: break;
175: case CVS_FST_ADDED:
176: case CVS_FST_MODIFIED:
1.49 joris 177: cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20 jfb 178: break;
179: default:
180: break;
1.6 jfb 181: }
1.5 jfb 182:
1.49 joris 183: return (0);
1.6 jfb 184: }
1.5 jfb 185:
1.20 jfb 186:
187:
188: static int
189: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1 jfb 190: {
1.38 xsa 191: int nrev;
1.21 jfb 192: char rcspath[MAXPATHLEN], numbuf[64];
1.20 jfb 193: RCSFILE *rf;
194: struct rcs_sym *sym;
1.1 jfb 195: struct rcs_delta *rdp;
1.21 jfb 196: struct rcs_access *acp;
1.20 jfb 197:
1.39 xsa 198: nrev = 0;
199:
200: if (cf->cf_cvstat == CVS_FST_ADDED) {
201: if (verbosity > 0)
202: cvs_log(LP_WARN, "%s has been added, but not committed",
203: cf->cf_name);
204: return (0);
205: }
206:
1.20 jfb 207: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.37 xsa 208: if (verbosity > 0)
209: cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20 jfb 210: return (0);
211: }
1.1 jfb 212:
1.21 jfb 213: if (cf->cf_type == DT_DIR) {
1.36 xsa 214: if (verbosity > 1)
1.44 xsa 215: cvs_log(LP_NOTICE, "Logging %s", cf->cf_name);
1.20 jfb 216: return (0);
1.21 jfb 217: }
1.20 jfb 218:
1.48 xsa 219: cvs_rcs_getpath(cf, rcspath, sizeof(rcspath));
1.20 jfb 220:
1.50 xsa 221: if (log_rfonly == 1) {
1.21 jfb 222: cvs_printf("%s\n", rcspath);
223: return (0);
224: }
225:
1.53 xsa 226: if ((rf = rcs_open(rcspath, RCS_READ|RCS_PARSE_FULLY)) == NULL)
1.52 xsa 227: fatal("cvs_getlog_local: rcs_open `%s': %s", rcspath,
1.54 ! xsa 228: rcs_errstr(rcs_errno));
1.20 jfb 229:
1.32 xsa 230: cvs_printf("\nRCS file: %s", rcspath);
231: cvs_printf("\nWorking file: %s", cf->cf_name);
232: cvs_printf("\nhead:");
233: if (rcs_head_get(rf) != NULL) {
234: cvs_printf(" %s",
235: rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
236: }
237: cvs_printf("\nbranch:");
238: if (rcs_branch_get(rf) != NULL) {
239: cvs_printf(" %s",
240: rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
241: }
242: cvs_printf("\nlocks:%s", (rf->rf_flags & RCS_SLOCK) ? " strict" : "");
1.20 jfb 243:
1.32 xsa 244: cvs_printf("\naccess list:\n");
1.21 jfb 245: TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
246: cvs_printf("\t%s\n", acp->ra_name);
247:
1.45 xsa 248: if (log_notags == 0) {
1.21 jfb 249: cvs_printf("symbolic names:\n");
250: TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
251: cvs_printf("\t%s: %s\n", sym->rs_name,
252: rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20 jfb 253: }
1.21 jfb 254:
1.32 xsa 255: cvs_printf("keyword substitution: %s\n",
256: rf->rf_expand == NULL ? "kv" : rf->rf_expand);
1.1 jfb 257:
1.47 xsa 258: cvs_printf("total revisions: %u", rf->rf_ndelta);
1.33 xsa 259:
1.45 xsa 260: if ((log_honly == 0) && (log_lhonly == 0))
1.47 xsa 261: cvs_printf(";\tselected revisions: %u", nrev);
1.35 joris 262:
1.33 xsa 263: cvs_printf("\n");
1.26 xsa 264:
1.45 xsa 265: if ((log_honly == 0) || (log_lhonly == 1))
1.33 xsa 266: cvs_printf("description:\n%s", rf->rf_desc);
1.26 xsa 267:
1.45 xsa 268: if ((log_honly == 0) && (log_lhonly == 0)) {
1.21 jfb 269: TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
270: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
271: cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
272: cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
1.35 joris 273: " author: %s; state: %s;\n",
1.21 jfb 274: rdp->rd_date.tm_year + 1900,
275: rdp->rd_date.tm_mon + 1,
276: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
277: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
278: rdp->rd_author, rdp->rd_state);
279: cvs_printf("%s", rdp->rd_log);
280: }
1.1 jfb 281: }
282:
1.6 jfb 283: cvs_printf(CVS_GETLOG_REVEND "\n");
1.20 jfb 284:
285: rcs_close(rf);
286:
287: return (0);
1.1 jfb 288: }