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