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