Annotation of src/usr.bin/rcs/rlog.c, Revision 1.54
1.54 ! ray 1: /* $OpenBSD: rlog.c,v 1.53 2006/04/28 12:30:25 xsa 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;
1.52 joris 61: int i, ch, fd;
1.1 joris 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':
1.47 xsa 82: /*
83: * kept for compatibility
84: */
1.1 joris 85: break;
1.37 xsa 86: case 'R':
87: Rflag = 1;
88: break;
1.36 ray 89: case 'r':
90: rflag = 1;
91: revisions = rcs_optarg;
92: break;
1.20 xsa 93: case 's':
94: slist = rcs_optarg;
95: break;
1.8 xsa 96: case 'T':
97: /*
98: * kept for compatibility
99: */
100: break;
1.1 joris 101: case 't':
102: tflag = 1;
103: break;
104: case 'V':
105: printf("%s\n", rcs_version);
106: exit(0);
1.20 xsa 107: case 'w':
108: wflag = 1;
109: wlist = rcs_optarg;
110: break;
1.14 xsa 111: case 'x':
1.33 ray 112: /* Use blank extension if none given. */
113: rcs_suffixes = rcs_optarg ? rcs_optarg : "";
1.14 xsa 114: break;
1.26 joris 115: case 'z':
116: timezone_flag = rcs_optarg;
1.27 xsa 117: break;
1.1 joris 118: default:
1.21 xsa 119: (usage());
120: exit(1);
1.1 joris 121: }
122: }
123:
1.5 joris 124: argc -= rcs_optind;
125: argv += rcs_optind;
1.1 joris 126:
127: if (argc == 0) {
1.48 xsa 128: warnx("no input file");
1.1 joris 129: (usage)();
130: exit(1);
131: }
132:
1.41 deraadt 133: if (hflag == 1 && tflag == 1) {
1.48 xsa 134: warnx("warning: -t overrides -h.");
1.7 xsa 135: hflag = 0;
136: }
1.6 xsa 137:
1.1 joris 138: for (i = 0; i < argc; i++) {
1.52 joris 139: fd = rcs_statfile(argv[i], fpath, sizeof(fpath), 0);
140: if (fd < 0)
1.1 joris 141: continue;
142:
1.52 joris 143: if ((file = rcs_open(fpath, fd,
144: RCS_READ|RCS_PARSE_FULLY)) == NULL)
1.11 xsa 145: continue;
146:
1.41 deraadt 147: if (Lflag == 1 && TAILQ_EMPTY(&(file->rf_locks))) {
1.11 xsa 148: rcs_close(file);
149: continue;
150: }
151:
1.9 xsa 152: if (Rflag == 1) {
153: printf("%s\n", fpath);
1.11 xsa 154: rcs_close(file);
1.9 xsa 155: continue;
156: }
157:
1.44 ray 158: rlog_file(argv[i], file);
1.9 xsa 159:
1.1 joris 160: rcs_close(file);
161: }
162:
163: return (0);
164: }
165:
1.32 xsa 166: static void
1.44 ray 167: rlog_file(const char *fname, RCSFILE *file)
1.1 joris 168: {
169: char numb[64];
1.36 ray 170: u_int nrev;
1.1 joris 171: struct rcs_sym *sym;
172: struct rcs_access *acp;
1.20 xsa 173: struct rcs_delta *rdp;
1.10 xsa 174: struct rcs_lock *lkp;
1.45 joris 175: char *workfile, *p;
1.1 joris 176:
1.36 ray 177: if (rflag == 1)
1.46 xsa 178: nrev = rcs_rev_select(file, revisions);
1.36 ray 179: else
180: nrev = file->rf_ndelta;
181:
1.45 joris 182: if ((workfile = basename(fname)) == NULL)
1.50 xsa 183: err(1, "basename");
1.45 joris 184:
185: /*
186: * In case they specified 'foo,v' as argument.
187: */
188: if ((p = strrchr(workfile, ',')) != NULL)
189: *p = '\0';
190:
1.43 ray 191: printf("\nRCS file: %s", file->rf_path);
1.45 joris 192: printf("\nWorking file: %s", workfile);
1.1 joris 193: printf("\nhead:");
194: if (file->rf_head != NULL)
195: printf(" %s", rcsnum_tostr(file->rf_head, numb, sizeof(numb)));
196:
197: printf("\nbranch:");
198: if (rcs_branch_get(file) != NULL) {
199: printf(" %s", rcsnum_tostr(rcs_branch_get(file),
200: numb, sizeof(numb)));
201: }
202:
203: printf("\nlocks: %s", (file->rf_flags & RCS_SLOCK) ? "strict" : "");
1.10 xsa 204: TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list)
205: printf("\n\t%s: %s", lkp->rl_name,
206: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.1 joris 207: printf("\naccess list:\n");
208: TAILQ_FOREACH(acp, &(file->rf_access), ra_list)
209: printf("\t%s\n", acp->ra_name);
210:
211: if (Nflag == 0) {
212: printf("symbolic names:\n");
213: TAILQ_FOREACH(sym, &(file->rf_symbols), rs_list) {
214: printf("\t%s: %s\n", sym->rs_name,
215: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
216: }
217: }
218:
219: printf("keyword substitution: %s\n",
220: file->rf_expand == NULL ? "kv" : file->rf_expand);
221:
1.20 xsa 222: printf("total revisions: %u", file->rf_ndelta);
223:
1.41 deraadt 224: if (file->rf_head != NULL && hflag == 0 && tflag == 0)
1.36 ray 225: printf(";\tselected revisions: %u", nrev);
1.20 xsa 226:
227: printf("\n");
228:
1.1 joris 229:
1.41 deraadt 230: if (hflag == 0 || tflag == 1)
1.13 xsa 231: printf("description:\n%s", file->rf_desc);
1.1 joris 232:
1.42 ray 233: if (hflag == 0 && tflag == 0 &&
234: !(lflag == 1 && TAILQ_EMPTY(&file->rf_locks))) {
1.36 ray 235: TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) {
236: /*
237: * if selections are enabled verify that entry is
1.39 niallo 238: * selected.
1.36 ray 239: */
1.41 deraadt 240: if (rflag == 0 || (rdp->rd_flags & RCS_RD_SELECT))
1.36 ray 241: rlog_rev_print(rdp);
242: }
1.20 xsa 243: }
1.1 joris 244:
245: printf("%s\n", REVEND);
1.16 xsa 246: }
247:
248: static void
1.20 xsa 249: rlog_rev_print(struct rcs_delta *rdp)
1.16 xsa 250: {
1.20 xsa 251: int i, found;
1.40 joris 252: struct tm t;
253: char *author, numb[64], *fmt, timeb[64];
1.51 joris 254: struct rcs_argvector *largv, *sargv, *wargv;
1.20 xsa 255:
256: i = found = 0;
257: author = NULL;
258:
1.23 xsa 259: /* -l[lockers] */
260: if (lflag == 1) {
1.42 ray 261: if (rdp->rd_locker != NULL)
262: found++;
1.23 xsa 263:
264: if (llist != NULL) {
265: /* if locker is empty, no need to go further. */
266: if (rdp->rd_locker == NULL)
267: return;
1.51 joris 268: largv = rcs_strsplit(llist, ",");
1.34 pat 269: for (i = 0; largv->argv[i] != NULL; i++) {
270: if (strcmp(rdp->rd_locker, largv->argv[i])
271: == 0) {
1.23 xsa 272: found++;
273: break;
274: }
275: found = 0;
276: }
1.51 joris 277: rcs_argv_destroy(largv);
1.23 xsa 278: }
279: }
1.40 joris 280:
1.20 xsa 281: /* -sstates */
282: if (slist != NULL) {
1.51 joris 283: sargv = rcs_strsplit(slist, ",");
1.34 pat 284: for (i = 0; sargv->argv[i] != NULL; i++) {
285: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
1.20 xsa 286: found++;
287: break;
288: }
289: found = 0;
290: }
1.51 joris 291: rcs_argv_destroy(sargv);
1.20 xsa 292: }
1.40 joris 293:
1.20 xsa 294: /* -w[logins] */
295: if (wflag == 1) {
296: if (wlist != NULL) {
1.51 joris 297: wargv = rcs_strsplit(wlist, ",");
1.34 pat 298: for (i = 0; wargv->argv[i] != NULL; i++) {
299: if (strcmp(rdp->rd_author, wargv->argv[i])
300: == 0) {
1.20 xsa 301: found++;
302: break;
303: }
304: found = 0;
305: }
1.51 joris 306: rcs_argv_destroy(wargv);
1.20 xsa 307: } else {
308: if ((author = getlogin()) == NULL)
1.50 xsa 309: err(1, "getlogin");
1.16 xsa 310:
1.20 xsa 311: if (strcmp(rdp->rd_author, author) == 0)
312: found++;
313: }
314: }
1.16 xsa 315:
1.20 xsa 316: /* XXX dirty... */
1.41 deraadt 317: if ((((slist != NULL && wflag == 1) ||
318: (slist != NULL && lflag == 1) ||
319: (lflag == 1 && wflag == 1)) && found < 2) ||
320: (((slist != NULL && lflag == 1 && wflag == 1) ||
321: (slist != NULL || lflag == 1 || wflag == 1)) && found == 0))
1.20 xsa 322: return;
323:
324: printf("%s\n", REVSEP);
325:
326: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
327:
1.22 xsa 328: printf("revision %s", numb);
329: if (rdp->rd_locker != NULL)
330: printf("\tlocked by: %s;", rdp->rd_locker);
1.40 joris 331:
332: if (timezone_flag != NULL) {
333: rcs_set_tz(timezone_flag, rdp, &t);
1.53 xsa 334: fmt = "%Y-%m-%d %H:%M:%S%z";
1.40 joris 335: } else {
336: t = rdp->rd_date;
337: fmt = "%Y/%m/%d %H:%M:%S";
338: }
339:
340: strftime(timeb, sizeof(timeb), fmt, &t);
341:
342: printf("\ndate: %s; author: %s; state: %s;\n", timeb, rdp->rd_author,
1.41 deraadt 343: rdp->rd_state);
1.40 joris 344:
1.20 xsa 345: printf("%s", rdp->rd_log);
1.1 joris 346: }