Annotation of src/usr.bin/cvs/getlog.c, Revision 1.41
1.41 ! xsa 1: /* $OpenBSD: getlog.c,v 1.40 2005/07/19 02:18:05 joris 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:
39: #define CVS_GLOG_RFONLY 0x01
40: #define CVS_GLOG_HDONLY 0x02
41:
42:
43: #define CVS_GETLOG_REVSEP "----------------------------"
44: #define CVS_GETLOG_REVEND \
45: "============================================================================="
46:
1.33 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.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.38 xsa 204: int nrev;
1.21 jfb 205: char rcspath[MAXPATHLEN], numbuf[64];
1.20 jfb 206: RCSFILE *rf;
207: struct rcs_sym *sym;
1.1 jfb 208: struct rcs_delta *rdp;
1.21 jfb 209: struct rcs_access *acp;
1.20 jfb 210:
1.39 xsa 211: nrev = 0;
212:
213: if (cf->cf_cvstat == CVS_FST_ADDED) {
214: if (verbosity > 0)
215: cvs_log(LP_WARN, "%s has been added, but not committed",
216: cf->cf_name);
217: return (0);
218: }
219:
1.20 jfb 220: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.37 xsa 221: if (verbosity > 0)
222: cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20 jfb 223: return (0);
224: }
1.1 jfb 225:
1.21 jfb 226: if (cf->cf_type == DT_DIR) {
1.36 xsa 227: if (verbosity > 1)
228: cvs_log(LP_INFO, "Logging %s", cf->cf_name);
1.20 jfb 229: return (0);
1.21 jfb 230: }
1.20 jfb 231:
1.38 xsa 232: if (cvs_rcs_getpath(cf, rcspath, sizeof(rcspath)) == NULL)
1.28 joris 233: return (CVS_EX_DATA);
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.33 xsa 272: cvs_printf("total revisions: %u;", rf->rf_ndelta);
273:
1.34 xsa 274: if (!log_honly && !log_lhonly)
1.33 xsa 275: cvs_printf("\tselected revisions: %u", nrev);
1.35 joris 276:
1.33 xsa 277: cvs_printf("\n");
1.26 xsa 278:
1.33 xsa 279: if (!log_honly || log_lhonly)
280: cvs_printf("description:\n%s", rf->rf_desc);
1.26 xsa 281:
1.33 xsa 282: if (!log_honly && !log_lhonly) {
1.21 jfb 283: TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
284: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
285: cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
286: cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
1.35 joris 287: " author: %s; state: %s;\n",
1.21 jfb 288: rdp->rd_date.tm_year + 1900,
289: rdp->rd_date.tm_mon + 1,
290: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
291: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
292: rdp->rd_author, rdp->rd_state);
293: cvs_printf("%s", rdp->rd_log);
294: }
1.1 jfb 295: }
296:
1.6 jfb 297: cvs_printf(CVS_GETLOG_REVEND "\n");
1.20 jfb 298:
299: rcs_close(rf);
300:
301: return (0);
1.1 jfb 302: }