Annotation of src/usr.bin/cvs/getlog.c, Revision 1.50
1.50 ! xsa 1: /* $OpenBSD: getlog.c,v 1.49 2005/12/30 02:03:28 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:
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) {
1.50 ! xsa 137: if (log_honly == 1)
1.49 joris 138: cvs_sendarg(root, "-h", 0);
1.50 ! xsa 139: if (log_notags == 1)
1.49 joris 140: cvs_sendarg(root, "-N", 0);
1.50 ! xsa 141: if (log_rfonly == 1)
1.49 joris 142: cvs_sendarg(root, "-R", 0);
1.50 ! xsa 143: if (log_lhonly == 1)
1.49 joris 144: cvs_sendarg(root, "-t", 0);
1.33 xsa 145: }
1.25 xsa 146: return (0);
147: }
1.1 jfb 148:
1.6 jfb 149: /*
1.21 jfb 150: * cvs_getlog_remote()
1.6 jfb 151: *
152: */
153: static int
1.21 jfb 154: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6 jfb 155: {
1.46 xsa 156: char fpath[MAXPATHLEN];
1.6 jfb 157: struct cvsroot *root;
158:
1.12 jfb 159: root = CVS_DIR_ROOT(cf);
1.7 jfb 160:
1.13 jfb 161: if (cf->cf_type == DT_DIR) {
1.20 jfb 162: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
1.49 joris 163: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20 jfb 164: else
1.49 joris 165: cvs_senddir(root, cf);
166: return (0);
1.6 jfb 167: }
168:
1.12 jfb 169: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6 jfb 170:
1.49 joris 171: cvs_sendentry(root, cf);
1.12 jfb 172:
1.20 jfb 173: switch (cf->cf_cvstat) {
174: case CVS_FST_UNKNOWN:
1.49 joris 175: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20 jfb 176: break;
177: case CVS_FST_UPTODATE:
1.49 joris 178: cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20 jfb 179: break;
180: case CVS_FST_ADDED:
181: case CVS_FST_MODIFIED:
1.49 joris 182: cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20 jfb 183: break;
184: default:
185: break;
1.6 jfb 186: }
1.5 jfb 187:
1.49 joris 188: return (0);
1.6 jfb 189: }
1.5 jfb 190:
1.20 jfb 191:
192:
193: static int
194: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1 jfb 195: {
1.38 xsa 196: int nrev;
1.21 jfb 197: char rcspath[MAXPATHLEN], numbuf[64];
1.20 jfb 198: RCSFILE *rf;
199: struct rcs_sym *sym;
1.1 jfb 200: struct rcs_delta *rdp;
1.21 jfb 201: struct rcs_access *acp;
1.20 jfb 202:
1.39 xsa 203: nrev = 0;
204:
205: if (cf->cf_cvstat == CVS_FST_ADDED) {
206: if (verbosity > 0)
207: cvs_log(LP_WARN, "%s has been added, but not committed",
208: cf->cf_name);
209: return (0);
210: }
211:
1.20 jfb 212: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.37 xsa 213: if (verbosity > 0)
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) {
1.36 xsa 219: if (verbosity > 1)
1.44 xsa 220: cvs_log(LP_NOTICE, "Logging %s", cf->cf_name);
1.20 jfb 221: return (0);
1.21 jfb 222: }
1.20 jfb 223:
1.48 xsa 224: cvs_rcs_getpath(cf, rcspath, sizeof(rcspath));
1.20 jfb 225:
1.50 ! xsa 226: if (log_rfonly == 1) {
1.21 jfb 227: cvs_printf("%s\n", rcspath);
228: return (0);
229: }
230:
1.20 jfb 231: rf = rcs_open(rcspath, RCS_READ);
232: if (rf == NULL)
1.28 joris 233: return (CVS_EX_DATA);
1.20 jfb 234:
1.32 xsa 235: cvs_printf("\nRCS file: %s", rcspath);
236: cvs_printf("\nWorking file: %s", cf->cf_name);
237: cvs_printf("\nhead:");
238: if (rcs_head_get(rf) != NULL) {
239: cvs_printf(" %s",
240: rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
241: }
242: cvs_printf("\nbranch:");
243: if (rcs_branch_get(rf) != NULL) {
244: cvs_printf(" %s",
245: rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
246: }
247: cvs_printf("\nlocks:%s", (rf->rf_flags & RCS_SLOCK) ? " strict" : "");
1.20 jfb 248:
1.32 xsa 249: cvs_printf("\naccess list:\n");
1.21 jfb 250: TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
251: cvs_printf("\t%s\n", acp->ra_name);
252:
1.45 xsa 253: if (log_notags == 0) {
1.21 jfb 254: cvs_printf("symbolic names:\n");
255: TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
256: cvs_printf("\t%s: %s\n", sym->rs_name,
257: rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20 jfb 258: }
1.21 jfb 259:
1.32 xsa 260: cvs_printf("keyword substitution: %s\n",
261: rf->rf_expand == NULL ? "kv" : rf->rf_expand);
1.1 jfb 262:
1.47 xsa 263: cvs_printf("total revisions: %u", rf->rf_ndelta);
1.33 xsa 264:
1.45 xsa 265: if ((log_honly == 0) && (log_lhonly == 0))
1.47 xsa 266: cvs_printf(";\tselected revisions: %u", nrev);
1.35 joris 267:
1.33 xsa 268: cvs_printf("\n");
1.26 xsa 269:
1.45 xsa 270: if ((log_honly == 0) || (log_lhonly == 1))
1.33 xsa 271: cvs_printf("description:\n%s", rf->rf_desc);
1.26 xsa 272:
1.45 xsa 273: if ((log_honly == 0) && (log_lhonly == 0)) {
1.21 jfb 274: TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
275: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
276: cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
277: cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
1.35 joris 278: " author: %s; state: %s;\n",
1.21 jfb 279: rdp->rd_date.tm_year + 1900,
280: rdp->rd_date.tm_mon + 1,
281: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
282: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
283: rdp->rd_author, rdp->rd_state);
284: cvs_printf("%s", rdp->rd_log);
285: }
1.1 jfb 286: }
287:
1.6 jfb 288: cvs_printf(CVS_GETLOG_REVEND "\n");
1.20 jfb 289:
290: rcs_close(rf);
291:
292: return (0);
1.1 jfb 293: }