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