Annotation of src/usr.bin/rcs/rlog.c, Revision 1.46
1.46 ! xsa 1: /* $OpenBSD: rlog.c,v 1.45 2006/04/14 23:29:01 joris Exp $ */
1.1 joris 2: /*
3: * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
1.20 xsa 4: * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1 joris 5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: *
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. The name of the author may not be used to endorse or promote products
14: * derived from this software without specific prior written permission.
15: *
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27:
1.18 xsa 28: #include "includes.h"
1.1 joris 29:
1.19 xsa 30: #include "rcsprog.h"
1.3 niallo 31: #include "diff.h"
1.1 joris 32:
1.44 ray 33: static void rlog_file(const char *, RCSFILE *);
1.32 xsa 34: static void rlog_rev_print(struct rcs_delta *);
1.1 joris 35:
1.38 xsa 36: #define RLOG_OPTSTRING "hLl::NqRr::s:TtVw::x::z::"
1.1 joris 37: #define REVSEP "----------------------------"
38: #define REVEND \
1.6 xsa 39: "============================================================================="
1.1 joris 40:
1.36 ray 41: static int hflag, Lflag, lflag, rflag, tflag, Nflag, wflag;
1.23 xsa 42: static char *llist = NULL;
1.20 xsa 43: static char *slist = NULL;
44: static char *wlist = NULL;
1.36 ray 45: static char *revisions = NULL;
1.1 joris 46:
1.21 xsa 47: void
48: rlog_usage(void)
49: {
50: fprintf(stderr,
1.25 jmc 51: "usage: rlog [-bhLNqRtV] [-ddates] [-l[lockers]] [-r[revs]]\n"
1.28 xsa 52: " [-sstates] [-w[logins]] [-xsuffixes]\n"
53: " [-ztz] file ...\n");
1.21 xsa 54: }
55:
1.1 joris 56: int
57: rlog_main(int argc, char **argv)
58: {
1.44 ray 59: RCSFILE *file;
1.1 joris 60: int Rflag;
61: int i, ch;
62: char fpath[MAXPATHLEN];
63:
1.45 joris 64: rcsnum_flags |= RCSNUM_NO_MAGIC;
1.36 ray 65: hflag = Rflag = rflag = 0;
66: while ((ch = rcs_getopt(argc, argv, RLOG_OPTSTRING)) != -1) {
1.1 joris 67: switch (ch) {
68: case 'h':
69: hflag = 1;
70: break;
1.11 xsa 71: case 'L':
72: Lflag = 1;
73: break;
1.23 xsa 74: case 'l':
75: lflag = 1;
76: llist = rcs_optarg;
77: break;
1.1 joris 78: case 'N':
79: Nflag = 1;
80: break;
81: case 'q':
82: verbose = 0;
83: break;
1.37 xsa 84: case 'R':
85: Rflag = 1;
86: break;
1.36 ray 87: case 'r':
88: rflag = 1;
89: revisions = rcs_optarg;
90: break;
1.20 xsa 91: case 's':
92: slist = rcs_optarg;
93: break;
1.8 xsa 94: case 'T':
95: /*
96: * kept for compatibility
97: */
98: break;
1.1 joris 99: case 't':
100: tflag = 1;
101: break;
102: case 'V':
103: printf("%s\n", rcs_version);
104: exit(0);
1.29 ray 105: /* NOTREACHED */
1.20 xsa 106: case 'w':
107: wflag = 1;
108: wlist = rcs_optarg;
109: break;
1.14 xsa 110: case 'x':
1.33 ray 111: /* Use blank extension if none given. */
112: rcs_suffixes = rcs_optarg ? rcs_optarg : "";
1.14 xsa 113: break;
1.26 joris 114: case 'z':
115: timezone_flag = rcs_optarg;
1.27 xsa 116: break;
1.1 joris 117: default:
1.21 xsa 118: (usage());
119: exit(1);
1.1 joris 120: }
121: }
122:
1.5 joris 123: argc -= rcs_optind;
124: argv += rcs_optind;
1.1 joris 125:
126: if (argc == 0) {
127: cvs_log(LP_ERR, "no input file");
128: (usage)();
129: exit(1);
130: }
131:
1.41 deraadt 132: if (hflag == 1 && tflag == 1) {
1.6 xsa 133: cvs_log(LP_WARN, "warning: -t overrides -h.");
1.7 xsa 134: hflag = 0;
135: }
1.6 xsa 136:
1.1 joris 137: for (i = 0; i < argc; i++) {
138: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
139: continue;
140:
1.17 niallo 141: if ((file = rcs_open(fpath, RCS_READ|RCS_PARSE_FULLY)) == NULL)
1.11 xsa 142: continue;
143:
1.41 deraadt 144: if (Lflag == 1 && TAILQ_EMPTY(&(file->rf_locks))) {
1.11 xsa 145: rcs_close(file);
146: continue;
147: }
148:
1.9 xsa 149: if (Rflag == 1) {
150: printf("%s\n", fpath);
1.11 xsa 151: rcs_close(file);
1.9 xsa 152: continue;
153: }
154:
1.44 ray 155: rlog_file(argv[i], file);
1.9 xsa 156:
1.1 joris 157: rcs_close(file);
158: }
159:
160: return (0);
161: }
162:
1.32 xsa 163: static void
1.44 ray 164: rlog_file(const char *fname, RCSFILE *file)
1.1 joris 165: {
166: char numb[64];
1.36 ray 167: u_int nrev;
1.1 joris 168: struct rcs_sym *sym;
169: struct rcs_access *acp;
1.20 xsa 170: struct rcs_delta *rdp;
1.10 xsa 171: struct rcs_lock *lkp;
1.45 joris 172: char *workfile, *p;
1.1 joris 173:
1.36 ray 174: if (rflag == 1)
1.46 ! xsa 175: nrev = rcs_rev_select(file, revisions);
1.36 ray 176: else
177: nrev = file->rf_ndelta;
178:
1.45 joris 179: if ((workfile = basename(fname)) == NULL)
180: fatal("failed to get basename of '%s'", fname);
181:
182: /*
183: * In case they specified 'foo,v' as argument.
184: */
185: if ((p = strrchr(workfile, ',')) != NULL)
186: *p = '\0';
187:
1.43 ray 188: printf("\nRCS file: %s", file->rf_path);
1.45 joris 189: printf("\nWorking file: %s", workfile);
1.1 joris 190: printf("\nhead:");
191: if (file->rf_head != NULL)
192: printf(" %s", rcsnum_tostr(file->rf_head, numb, sizeof(numb)));
193:
194: printf("\nbranch:");
195: if (rcs_branch_get(file) != NULL) {
196: printf(" %s", rcsnum_tostr(rcs_branch_get(file),
197: numb, sizeof(numb)));
198: }
199:
200: printf("\nlocks: %s", (file->rf_flags & RCS_SLOCK) ? "strict" : "");
1.10 xsa 201: TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list)
202: printf("\n\t%s: %s", lkp->rl_name,
203: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.1 joris 204: printf("\naccess list:\n");
205: TAILQ_FOREACH(acp, &(file->rf_access), ra_list)
206: printf("\t%s\n", acp->ra_name);
207:
208: if (Nflag == 0) {
209: printf("symbolic names:\n");
210: TAILQ_FOREACH(sym, &(file->rf_symbols), rs_list) {
211: printf("\t%s: %s\n", sym->rs_name,
212: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
213: }
214: }
215:
216: printf("keyword substitution: %s\n",
217: file->rf_expand == NULL ? "kv" : file->rf_expand);
218:
1.20 xsa 219: printf("total revisions: %u", file->rf_ndelta);
220:
1.41 deraadt 221: if (file->rf_head != NULL && hflag == 0 && tflag == 0)
1.36 ray 222: printf(";\tselected revisions: %u", nrev);
1.20 xsa 223:
224: printf("\n");
225:
1.1 joris 226:
1.41 deraadt 227: if (hflag == 0 || tflag == 1)
1.13 xsa 228: printf("description:\n%s", file->rf_desc);
1.1 joris 229:
1.42 ray 230: if (hflag == 0 && tflag == 0 &&
231: !(lflag == 1 && TAILQ_EMPTY(&file->rf_locks))) {
1.36 ray 232: TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) {
233: /*
234: * if selections are enabled verify that entry is
1.39 niallo 235: * selected.
1.36 ray 236: */
1.41 deraadt 237: if (rflag == 0 || (rdp->rd_flags & RCS_RD_SELECT))
1.36 ray 238: rlog_rev_print(rdp);
239: }
1.20 xsa 240: }
1.1 joris 241:
242: printf("%s\n", REVEND);
1.16 xsa 243: }
244:
245: static void
1.20 xsa 246: rlog_rev_print(struct rcs_delta *rdp)
1.16 xsa 247: {
1.20 xsa 248: int i, found;
1.40 joris 249: struct tm t;
250: char *author, numb[64], *fmt, timeb[64];
1.34 pat 251: struct cvs_argvector *largv, *sargv, *wargv;
1.20 xsa 252:
253: i = found = 0;
254: author = NULL;
255:
1.23 xsa 256: /* -l[lockers] */
257: if (lflag == 1) {
1.42 ray 258: if (rdp->rd_locker != NULL)
259: found++;
1.23 xsa 260:
261: if (llist != NULL) {
262: /* if locker is empty, no need to go further. */
263: if (rdp->rd_locker == NULL)
264: return;
1.30 xsa 265: largv = cvs_strsplit(llist, ",");
1.34 pat 266: for (i = 0; largv->argv[i] != NULL; i++) {
267: if (strcmp(rdp->rd_locker, largv->argv[i])
268: == 0) {
1.23 xsa 269: found++;
270: break;
271: }
272: found = 0;
273: }
1.39 niallo 274: cvs_argv_destroy(largv);
1.23 xsa 275: }
276: }
1.40 joris 277:
1.20 xsa 278: /* -sstates */
279: if (slist != NULL) {
1.30 xsa 280: sargv = cvs_strsplit(slist, ",");
1.34 pat 281: for (i = 0; sargv->argv[i] != NULL; i++) {
282: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
1.20 xsa 283: found++;
284: break;
285: }
286: found = 0;
287: }
1.39 niallo 288: cvs_argv_destroy(sargv);
1.20 xsa 289: }
1.40 joris 290:
1.20 xsa 291: /* -w[logins] */
292: if (wflag == 1) {
293: if (wlist != NULL) {
1.30 xsa 294: wargv = cvs_strsplit(wlist, ",");
1.34 pat 295: for (i = 0; wargv->argv[i] != NULL; i++) {
296: if (strcmp(rdp->rd_author, wargv->argv[i])
297: == 0) {
1.20 xsa 298: found++;
299: break;
300: }
301: found = 0;
302: }
1.39 niallo 303: cvs_argv_destroy(wargv);
1.20 xsa 304: } else {
305: if ((author = getlogin()) == NULL)
306: fatal("getlogin failed");
1.16 xsa 307:
1.20 xsa 308: if (strcmp(rdp->rd_author, author) == 0)
309: found++;
310: }
311: }
1.16 xsa 312:
1.20 xsa 313: /* XXX dirty... */
1.41 deraadt 314: if ((((slist != NULL && wflag == 1) ||
315: (slist != NULL && lflag == 1) ||
316: (lflag == 1 && wflag == 1)) && found < 2) ||
317: (((slist != NULL && lflag == 1 && wflag == 1) ||
318: (slist != NULL || lflag == 1 || wflag == 1)) && found == 0))
1.20 xsa 319: return;
320:
321: printf("%s\n", REVSEP);
322:
323: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
324:
1.22 xsa 325: printf("revision %s", numb);
326: if (rdp->rd_locker != NULL)
327: printf("\tlocked by: %s;", rdp->rd_locker);
1.40 joris 328:
329: if (timezone_flag != NULL) {
330: rcs_set_tz(timezone_flag, rdp, &t);
331: fmt = "%Y/%m/%d %H:%M:%S%z";
332: } else {
333: t = rdp->rd_date;
334: fmt = "%Y/%m/%d %H:%M:%S";
335: }
336:
337: strftime(timeb, sizeof(timeb), fmt, &t);
338:
339: printf("\ndate: %s; author: %s; state: %s;\n", timeb, rdp->rd_author,
1.41 deraadt 340: rdp->rd_state);
1.40 joris 341:
1.20 xsa 342: printf("%s", rdp->rd_log);
1.1 joris 343: }