Annotation of src/usr.bin/cvs/getlog.c, Revision 1.73
1.73 ! xsa 1: /* $OpenBSD: getlog.c,v 1.72 2007/06/26 02:24:10 niallo Exp $ */
1.1 jfb 2: /*
1.66 xsa 3: * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.57 joris 4: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1 jfb 5: *
1.57 joris 6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 jfb 9: *
1.57 joris 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 jfb 17: */
18:
1.71 otto 19: #include <unistd.h>
20: #include <string.h>
1.72 niallo 21: #include <errno.h>
1.1 jfb 22:
23: #include "cvs.h"
1.65 joris 24: #include "remote.h"
1.1 jfb 25:
1.66 xsa 26: #define L_HEAD 0x01
27: #define L_HEAD_DESCR 0x02
28: #define L_NAME 0x04
29: #define L_NOTAGS 0x08
1.67 xsa 30: #define L_LOGINS 0x10
31: #define L_STATES 0x20
1.66 xsa 32:
1.57 joris 33: void cvs_log_local(struct cvs_file *);
34:
1.67 xsa 35: static void log_rev_print(struct rcs_delta *);
36:
1.66 xsa 37: int runflags = 0;
1.57 joris 38: char *logrev = NULL;
1.67 xsa 39: char *slist = NULL;
40: char *wlist = NULL;
1.1 jfb 41:
1.29 jfb 42: struct cvs_cmd cvs_cmd_log = {
1.63 joris 43: CVS_OP_LOG, 0, "log",
1.29 jfb 44: { "lo" },
45: "Print out history information for files",
46: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.68 xsa 47: "bd:hlNRr:s:tw:",
1.29 jfb 48: NULL,
1.57 joris 49: cvs_getlog
1.16 joris 50: };
51:
1.72 niallo 52: struct cvs_cmd cvs_cmd_rlog = {
53: CVS_OP_RLOG, 0, "rlog",
54: { "rlo" },
55: "Print out history information for files",
56: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
57: "bd:hlNRr:s:tw:",
58: NULL,
59: cvs_getlog
60: };
61:
1.57 joris 62: int
63: cvs_getlog(int argc, char **argv)
1.1 jfb 64: {
1.16 joris 65: int ch;
1.57 joris 66: int flags;
67: char *arg = ".";
68: struct cvs_recursion cr;
1.1 jfb 69:
1.57 joris 70: rcsnum_flags |= RCSNUM_NO_MAGIC;
71: flags = CR_RECURSE_DIRS;
72:
73: while ((ch = getopt(argc, argv, cvs_cmd_log.cmd_opts)) != -1) {
1.16 joris 74: switch (ch) {
1.66 xsa 75: case 'h':
76: runflags |= L_HEAD;
77: break;
1.1 jfb 78: case 'l':
1.57 joris 79: flags &= ~CR_RECURSE_DIRS;
1.1 jfb 80: break;
1.66 xsa 81: case 'N':
82: runflags |= L_NOTAGS;
83: break;
84: case 'R':
85: runflags |= L_NAME;
1.1 jfb 86: case 'r':
1.57 joris 87: logrev = optarg;
1.25 xsa 88: break;
1.67 xsa 89: case 's':
90: runflags |= L_STATES;
91: slist = optarg;
92: break;
1.66 xsa 93: case 't':
94: runflags |= L_HEAD_DESCR;
95: break;
1.67 xsa 96: case 'w':
97: runflags |= L_LOGINS;
98: wlist = optarg;
99: break;
1.1 jfb 100: default:
1.57 joris 101: fatal("%s", cvs_cmd_log.cmd_synopsis);
1.1 jfb 102: }
103: }
104:
1.57 joris 105: argc -= optind;
106: argv += optind;
1.6 jfb 107:
1.57 joris 108: cr.enterdir = NULL;
109: cr.leavedir = NULL;
1.65 joris 110:
111: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.69 joris 112: cvs_client_connect_to_server();
1.65 joris 113: cr.fileproc = cvs_client_sendfile;
114:
1.66 xsa 115: if (runflags & L_HEAD)
116: cvs_client_send_request("Argument -h");
117:
1.65 joris 118: if (!(flags & CR_RECURSE_DIRS))
119: cvs_client_send_request("Argument -l");
120:
1.66 xsa 121: if (runflags & L_NOTAGS)
122: cvs_client_send_request("Argument -N");
123:
124: if (runflags & L_NAME)
125: cvs_client_send_request("Argument -R");
126:
1.65 joris 127: if (logrev != NULL)
128: cvs_client_send_request("Argument -r%s", logrev);
1.66 xsa 129:
1.67 xsa 130: if (runflags & L_STATES)
131: cvs_client_send_request("Argument -s%s", slist);
132:
1.66 xsa 133: if (runflags & L_HEAD_DESCR)
134: cvs_client_send_request("Argument -t");
1.67 xsa 135:
136: if (runflags & L_LOGINS)
137: cvs_client_send_request("Argument -w%s", wlist);
1.65 joris 138: } else {
1.72 niallo 139: if (cvs_command[0] == 'r' &&
140: chdir(current_cvsroot->cr_dir) == -1)
141: fatal("cvs_server_log: %s", strerror(errno));
142:
1.65 joris 143: cr.fileproc = cvs_log_local;
144: }
145:
1.57 joris 146: cr.flags = flags;
147:
148: if (argc > 0)
149: cvs_file_run(argc, argv, &cr);
150: else
151: cvs_file_run(1, &arg, &cr);
1.5 jfb 152:
1.65 joris 153: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
154: cvs_client_send_files(argv, argc);
155: cvs_client_senddir(".");
1.72 niallo 156: if (cvs_command[0] == 'r')
157: cvs_client_send_request("rlog");
158: else
159: cvs_client_send_request("log");
1.65 joris 160: cvs_client_get_responses();
161: }
162:
1.49 joris 163: return (0);
1.6 jfb 164: }
1.5 jfb 165:
1.57 joris 166: void
167: cvs_log_local(struct cvs_file *cf)
1.1 jfb 168: {
1.57 joris 169: u_int nrev;
1.20 jfb 170: struct rcs_sym *sym;
1.57 joris 171: struct rcs_lock *lkp;
1.1 jfb 172: struct rcs_delta *rdp;
1.21 jfb 173: struct rcs_access *acp;
1.73 ! xsa 174: char numb[CVS_REV_BUFSZ];
1.60 joris 175:
176: cvs_log(LP_TRACE, "cvs_log_local(%s)", cf->file_path);
1.20 jfb 177:
1.70 joris 178: cvs_file_classify(cf, NULL);
1.39 xsa 179:
1.57 joris 180: if (cf->file_status == FILE_UNKNOWN) {
181: if (verbosity > 0)
182: cvs_log(LP_ERR, "nothing known about %s",
183: cf->file_path);
184: return;
185: } else if (cf->file_status == FILE_ADDED) {
1.39 xsa 186: if (verbosity > 0)
1.62 david 187: cvs_log(LP_ERR, "%s has been added, but not committed",
1.57 joris 188: cf->file_path);
1.59 joris 189: return;
190: }
191:
192: if (cf->file_type == CVS_DIR) {
193: if (verbosity > 1)
194: cvs_log(LP_NOTICE, "Logging %s", cf->file_path);
1.57 joris 195: return;
1.39 xsa 196: }
197:
1.66 xsa 198: if (runflags & L_NAME) {
199: cvs_printf("%s\n", cf->file_rpath);
200: return;
201: }
202:
1.65 joris 203: cvs_printf("\nRCS file: %s", cf->file_rpath);
204: cvs_printf("\nWorking file: %s", cf->file_path);
205: cvs_printf("\nhead:");
1.57 joris 206: if (cf->file_rcs->rf_head != NULL)
1.65 joris 207: cvs_printf(" %s", rcsnum_tostr(cf->file_rcs->rf_head,
1.57 joris 208: numb, sizeof(numb)));
209:
1.65 joris 210: cvs_printf("\nbranch:");
1.57 joris 211: if (rcs_branch_get(cf->file_rcs) != NULL) {
1.65 joris 212: cvs_printf(" %s", rcsnum_tostr(rcs_branch_get(cf->file_rcs),
1.57 joris 213: numb, sizeof(numb)));
1.20 jfb 214: }
1.1 jfb 215:
1.65 joris 216: cvs_printf("\nlocks: %s", (cf->file_rcs->rf_flags & RCS_SLOCK)
1.57 joris 217: ? "strict" : "");
218: TAILQ_FOREACH(lkp, &(cf->file_rcs->rf_locks), rl_list)
1.65 joris 219: cvs_printf("\n\t%s: %s", lkp->rl_name,
1.57 joris 220: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.20 jfb 221:
1.65 joris 222: cvs_printf("\naccess list:\n");
1.57 joris 223: TAILQ_FOREACH(acp, &(cf->file_rcs->rf_access), ra_list)
1.65 joris 224: cvs_printf("\t%s\n", acp->ra_name);
1.20 jfb 225:
1.66 xsa 226: if (!(runflags & L_NOTAGS)) {
227: cvs_printf("symbolic names:\n");
228: TAILQ_FOREACH(sym, &(cf->file_rcs->rf_symbols), rs_list) {
229: cvs_printf("\t%s: %s\n", sym->rs_name,
230: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
231: }
1.21 jfb 232: }
233:
1.65 joris 234: cvs_printf("keyword substitution: %s\n",
1.57 joris 235: cf->file_rcs->rf_expand == NULL ? "kv" : cf->file_rcs->rf_expand);
236:
1.65 joris 237: cvs_printf("total revisions: %u", cf->file_rcs->rf_ndelta);
1.20 jfb 238:
1.57 joris 239: if (logrev != NULL)
1.58 joris 240: nrev = cvs_revision_select(cf->file_rcs, logrev);
1.57 joris 241: else
242: nrev = cf->file_rcs->rf_ndelta;
1.21 jfb 243:
1.66 xsa 244: if (cf->file_rcs->rf_head != NULL &&
245: !(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR))
246: cvs_printf(";\tselected revisions: %u", nrev);
247:
1.65 joris 248: cvs_printf("\n");
1.1 jfb 249:
1.66 xsa 250: if (!(runflags & L_HEAD) || (runflags & L_HEAD_DESCR))
251: cvs_printf("description:\n%s", cf->file_rcs->rf_desc);
252:
253: if (!(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR)) {
254: TAILQ_FOREACH(rdp, &(cf->file_rcs->rf_delta), rd_list) {
1.67 xsa 255: /*
256: * if selections are enabled verify that entry is
257: * selected.
258: */
259: if (logrev == NULL || (rdp->rd_flags & RCS_RD_SELECT))
260: log_rev_print(rdp);
1.66 xsa 261: }
1.57 joris 262: }
1.20 jfb 263:
1.65 joris 264: cvs_printf("%s\n", LOG_REVEND);
1.67 xsa 265: }
266:
267: static void
268: log_rev_print(struct rcs_delta *rdp)
269: {
270: int i, found;
1.73 ! xsa 271: char numb[CVS_REV_BUFSZ], timeb[CVS_TIME_BUFSZ];
1.67 xsa 272: struct cvs_argvector *sargv, *wargv;
273:
274: i = found = 0;
275:
276: /* -s states */
277: if (runflags & L_STATES) {
278: sargv = cvs_strsplit(slist, ",");
279: for (i = 0; sargv->argv[i] != NULL; i++) {
280: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
281: found++;
282: break;
283: }
284: found = 0;
285: }
286: cvs_argv_destroy(sargv);
287: }
288:
289: /* -w[logins] */
290: if (runflags & L_LOGINS) {
291: wargv = cvs_strsplit(wlist, ",");
292: for (i = 0; wargv->argv[i] != NULL; i++) {
293: if (strcmp(rdp->rd_author, wargv->argv[i]) == 0) {
294: found++;
295: break;
296: }
297: found = 0;
298: }
299: cvs_argv_destroy(wargv);
300: }
301:
1.68 xsa 302: if ((runflags & (L_STATES|L_LOGINS)) && found == 0)
1.67 xsa 303: return;
304:
305: cvs_printf("%s\n", LOG_REVSEP);
306:
307: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
308: cvs_printf("revision %s", numb);
309:
310: strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S", &rdp->rd_date);
311: cvs_printf("\ndate: %s; author: %s; state: %s;\n",
312: timeb, rdp->rd_author, rdp->rd_state);
313: cvs_printf("%s", rdp->rd_log);
1.1 jfb 314: }