Annotation of src/usr.bin/cvs/getlog.c, Revision 1.46
1.46 ! xsa 1: /* $OpenBSD: getlog.c,v 1.45 2005/08/05 10:17:14 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.31 xsa 27: #include <errno.h>
28: #include <paths.h>
29: #include <stdio.h>
1.1 jfb 30: #include <stdlib.h>
1.31 xsa 31: #include <string.h>
1.1 jfb 32: #include <unistd.h>
33:
34: #include "cvs.h"
35: #include "log.h"
1.3 jfb 36: #include "proto.h"
1.1 jfb 37:
38:
1.43 xsa 39: #define CVS_GLOG_RFONLY 0x01
40: #define CVS_GLOG_HDONLY 0x02
1.1 jfb 41:
42:
1.43 xsa 43: #define CVS_GETLOG_REVSEP "----------------------------"
1.1 jfb 44: #define CVS_GETLOG_REVEND \
45: "============================================================================="
46:
1.43 xsa 47: static int cvs_getlog_init(struct cvs_cmd *, int, char **, int *);
48: static int cvs_getlog_remote(CVSFILE *, void *);
49: static int cvs_getlog_local(CVSFILE *, void *);
50: static int cvs_getlog_pre_exec(struct cvsroot *);
1.1 jfb 51:
1.29 jfb 52: struct cvs_cmd cvs_cmd_log = {
53: CVS_OP_LOG, CVS_REQ_LOG, "log",
54: { "lo" },
55: "Print out history information for files",
56: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.30 xsa 57: "bd:hlNRr:s:tw:",
1.29 jfb 58: NULL,
1.40 joris 59: CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33 xsa 60: cvs_getlog_init,
61: cvs_getlog_pre_exec,
1.29 jfb 62: cvs_getlog_remote,
63: cvs_getlog_local,
64: NULL,
65: NULL,
66: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
67: };
68:
69:
70: struct cvs_cmd cvs_cmd_rlog = {
71: CVS_OP_LOG, CVS_REQ_LOG, "log",
72: { "lo" },
73: "Print out history information for files",
74: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
75: "d:hlRr:",
76: NULL,
1.40 joris 77: CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33 xsa 78: cvs_getlog_init,
79: cvs_getlog_pre_exec,
1.21 jfb 80: cvs_getlog_remote,
1.29 jfb 81: cvs_getlog_local,
82: NULL,
83: NULL,
1.16 joris 84: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
85: };
86:
1.21 jfb 87: static int log_rfonly = 0;
88: static int log_honly = 0;
1.25 xsa 89: static int log_lhonly = 0;
1.21 jfb 90: static int log_notags = 0;
1.1 jfb 91:
1.25 xsa 92: static int
1.33 xsa 93: cvs_getlog_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 94: {
1.16 joris 95: int ch;
1.1 jfb 96:
1.29 jfb 97: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.16 joris 98: switch (ch) {
1.25 xsa 99: case 'b':
100: break;
1.1 jfb 101: case 'd':
102: break;
103: case 'h':
1.21 jfb 104: log_honly = 1;
1.1 jfb 105: break;
106: case 'l':
1.29 jfb 107: cmd->file_flags &= ~CF_RECURSE;
1.1 jfb 108: break;
1.21 jfb 109: case 'N':
110: log_notags = 1;
111: break;
1.1 jfb 112: case 'R':
1.21 jfb 113: log_rfonly = 1;
1.1 jfb 114: break;
115: case 'r':
116: break;
1.25 xsa 117: case 's':
118: break;
119: case 't':
120: log_lhonly = 1;
121: break;
122: case 'w':
123: break;
1.1 jfb 124: default:
1.19 joris 125: return (CVS_EX_USAGE);
1.1 jfb 126: }
127: }
128:
1.16 joris 129: *arg = optind;
1.1 jfb 130: return (0);
131: }
132:
1.25 xsa 133: static int
1.33 xsa 134: cvs_getlog_pre_exec(struct cvsroot *root)
1.25 xsa 135: {
1.33 xsa 136: if (root->cr_method != CVS_METHOD_LOCAL) {
137: if (log_honly && (cvs_sendarg(root, "-h", 0) < 0))
138: return (CVS_EX_PROTO);
139: if (log_notags && (cvs_sendarg(root, "-N", 0) < 0))
140: return (CVS_EX_PROTO);
141: if (log_rfonly && (cvs_sendarg(root, "-R", 0) < 0))
142: return (CVS_EX_PROTO);
143: if (log_lhonly && (cvs_sendarg(root, "-t", 0) < 0))
144: return (CVS_EX_PROTO);
145: }
1.25 xsa 146:
147: return (0);
148: }
1.1 jfb 149:
1.6 jfb 150: /*
1.21 jfb 151: * cvs_getlog_remote()
1.6 jfb 152: *
153: */
154: static int
1.21 jfb 155: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6 jfb 156: {
1.12 jfb 157: int ret;
1.46 ! xsa 158: char fpath[MAXPATHLEN];
1.6 jfb 159: struct cvsroot *root;
160:
1.12 jfb 161: ret = 0;
162: root = CVS_DIR_ROOT(cf);
1.7 jfb 163:
1.13 jfb 164: if (cf->cf_type == DT_DIR) {
1.20 jfb 165: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
166: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
1.42 joris 167: cf->cf_name);
1.20 jfb 168: else
169: ret = cvs_senddir(root, cf);
1.12 jfb 170: return (ret);
1.6 jfb 171: }
172:
1.12 jfb 173: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6 jfb 174:
1.27 jfb 175: if (cvs_sendentry(root, cf) < 0)
176: return (CVS_EX_PROTO);
1.12 jfb 177:
1.20 jfb 178: switch (cf->cf_cvstat) {
179: case CVS_FST_UNKNOWN:
1.21 jfb 180: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20 jfb 181: break;
182: case CVS_FST_UPTODATE:
1.21 jfb 183: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20 jfb 184: break;
185: case CVS_FST_ADDED:
186: case CVS_FST_MODIFIED:
1.21 jfb 187: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20 jfb 188: break;
189: default:
190: break;
1.6 jfb 191: }
1.5 jfb 192:
1.27 jfb 193: if (ret == -1)
194: ret = CVS_EX_PROTO;
1.12 jfb 195: return (ret);
1.6 jfb 196: }
1.5 jfb 197:
1.20 jfb 198:
199:
200: static int
201: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1 jfb 202: {
1.38 xsa 203: int nrev;
1.21 jfb 204: char rcspath[MAXPATHLEN], numbuf[64];
1.20 jfb 205: RCSFILE *rf;
206: struct rcs_sym *sym;
1.1 jfb 207: struct rcs_delta *rdp;
1.21 jfb 208: struct rcs_access *acp;
1.20 jfb 209:
1.39 xsa 210: nrev = 0;
211:
212: if (cf->cf_cvstat == CVS_FST_ADDED) {
213: if (verbosity > 0)
214: cvs_log(LP_WARN, "%s has been added, but not committed",
215: cf->cf_name);
216: return (0);
217: }
218:
1.20 jfb 219: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.37 xsa 220: if (verbosity > 0)
221: cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20 jfb 222: return (0);
223: }
1.1 jfb 224:
1.21 jfb 225: if (cf->cf_type == DT_DIR) {
1.36 xsa 226: if (verbosity > 1)
1.44 xsa 227: cvs_log(LP_NOTICE, "Logging %s", cf->cf_name);
1.20 jfb 228: return (0);
1.21 jfb 229: }
1.20 jfb 230:
1.38 xsa 231: if (cvs_rcs_getpath(cf, rcspath, sizeof(rcspath)) == NULL)
1.28 joris 232: return (CVS_EX_DATA);
1.20 jfb 233:
1.21 jfb 234: if (log_rfonly) {
235: cvs_printf("%s\n", rcspath);
236: return (0);
237: }
238:
1.20 jfb 239: rf = rcs_open(rcspath, RCS_READ);
240: if (rf == NULL)
1.28 joris 241: return (CVS_EX_DATA);
1.20 jfb 242:
1.32 xsa 243: cvs_printf("\nRCS file: %s", rcspath);
244: cvs_printf("\nWorking file: %s", cf->cf_name);
245: cvs_printf("\nhead:");
246: if (rcs_head_get(rf) != NULL) {
247: cvs_printf(" %s",
248: rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
249: }
250: cvs_printf("\nbranch:");
251: if (rcs_branch_get(rf) != NULL) {
252: cvs_printf(" %s",
253: rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
254: }
255: cvs_printf("\nlocks:%s", (rf->rf_flags & RCS_SLOCK) ? " strict" : "");
1.20 jfb 256:
1.32 xsa 257: cvs_printf("\naccess list:\n");
1.21 jfb 258: TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
259: cvs_printf("\t%s\n", acp->ra_name);
260:
1.45 xsa 261: if (log_notags == 0) {
1.21 jfb 262: cvs_printf("symbolic names:\n");
263: TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
264: cvs_printf("\t%s: %s\n", sym->rs_name,
265: rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20 jfb 266: }
1.21 jfb 267:
1.32 xsa 268: cvs_printf("keyword substitution: %s\n",
269: rf->rf_expand == NULL ? "kv" : rf->rf_expand);
1.1 jfb 270:
1.33 xsa 271: cvs_printf("total revisions: %u;", rf->rf_ndelta);
272:
1.45 xsa 273: if ((log_honly == 0) && (log_lhonly == 0))
1.33 xsa 274: cvs_printf("\tselected revisions: %u", nrev);
1.35 joris 275:
1.33 xsa 276: cvs_printf("\n");
1.26 xsa 277:
1.45 xsa 278: if ((log_honly == 0) || (log_lhonly == 1))
1.33 xsa 279: cvs_printf("description:\n%s", rf->rf_desc);
1.26 xsa 280:
1.45 xsa 281: if ((log_honly == 0) && (log_lhonly == 0)) {
1.21 jfb 282: TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
283: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
284: cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
285: cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
1.35 joris 286: " author: %s; state: %s;\n",
1.21 jfb 287: rdp->rd_date.tm_year + 1900,
288: rdp->rd_date.tm_mon + 1,
289: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
290: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
291: rdp->rd_author, rdp->rd_state);
292: cvs_printf("%s", rdp->rd_log);
293: }
1.1 jfb 294: }
295:
1.6 jfb 296: cvs_printf(CVS_GETLOG_REVEND "\n");
1.20 jfb 297:
298: rcs_close(rf);
299:
300: return (0);
1.1 jfb 301: }