Annotation of src/usr.bin/cvs/getlog.c, Revision 1.79
1.79 ! tobias 1: /* $OpenBSD: getlog.c,v 1.78 2007/09/24 22:06:28 joris 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.79 ! tobias 65: int ch, flags, i;
1.57 joris 66: char *arg = ".";
67: struct cvs_recursion cr;
1.1 jfb 68:
1.57 joris 69: rcsnum_flags |= RCSNUM_NO_MAGIC;
70: flags = CR_RECURSE_DIRS;
71:
72: while ((ch = getopt(argc, argv, cvs_cmd_log.cmd_opts)) != -1) {
1.16 joris 73: switch (ch) {
1.66 xsa 74: case 'h':
75: runflags |= L_HEAD;
76: break;
1.1 jfb 77: case 'l':
1.57 joris 78: flags &= ~CR_RECURSE_DIRS;
1.1 jfb 79: break;
1.66 xsa 80: case 'N':
81: runflags |= L_NOTAGS;
82: break;
83: case 'R':
84: runflags |= L_NAME;
1.1 jfb 85: case 'r':
1.57 joris 86: logrev = optarg;
1.25 xsa 87: break;
1.67 xsa 88: case 's':
89: runflags |= L_STATES;
90: slist = optarg;
91: break;
1.66 xsa 92: case 't':
93: runflags |= L_HEAD_DESCR;
94: break;
1.67 xsa 95: case 'w':
96: runflags |= L_LOGINS;
97: wlist = optarg;
98: break;
1.1 jfb 99: default:
1.57 joris 100: fatal("%s", cvs_cmd_log.cmd_synopsis);
1.1 jfb 101: }
102: }
103:
1.57 joris 104: argc -= optind;
105: argv += optind;
1.6 jfb 106:
1.79 ! tobias 107: if (cvs_cmdop == CVS_OP_RLOG) {
! 108: if (argc == 0)
! 109: return 0;
! 110:
! 111: for (i = 0; i < argc; i++)
! 112: if (argv[i][0] == '/')
! 113: fatal("Absolute path name is invalid: %s",
! 114: argv[i]);
! 115: }
! 116:
1.57 joris 117: cr.enterdir = NULL;
118: cr.leavedir = NULL;
1.65 joris 119:
120: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.69 joris 121: cvs_client_connect_to_server();
1.65 joris 122: cr.fileproc = cvs_client_sendfile;
123:
1.66 xsa 124: if (runflags & L_HEAD)
125: cvs_client_send_request("Argument -h");
126:
1.65 joris 127: if (!(flags & CR_RECURSE_DIRS))
128: cvs_client_send_request("Argument -l");
129:
1.66 xsa 130: if (runflags & L_NOTAGS)
131: cvs_client_send_request("Argument -N");
132:
133: if (runflags & L_NAME)
134: cvs_client_send_request("Argument -R");
135:
1.65 joris 136: if (logrev != NULL)
137: cvs_client_send_request("Argument -r%s", logrev);
1.66 xsa 138:
1.67 xsa 139: if (runflags & L_STATES)
140: cvs_client_send_request("Argument -s%s", slist);
141:
1.66 xsa 142: if (runflags & L_HEAD_DESCR)
143: cvs_client_send_request("Argument -t");
1.67 xsa 144:
145: if (runflags & L_LOGINS)
146: cvs_client_send_request("Argument -w%s", wlist);
1.65 joris 147: } else {
1.75 xsa 148: if (cvs_cmdop == CVS_OP_RLOG &&
1.72 niallo 149: chdir(current_cvsroot->cr_dir) == -1)
1.76 xsa 150: fatal("cvs_getlog: %s", strerror(errno));
1.72 niallo 151:
1.65 joris 152: cr.fileproc = cvs_log_local;
153: }
154:
1.57 joris 155: cr.flags = flags;
156:
1.79 ! tobias 157: if (cvs_cmdop == CVS_OP_LOG ||
! 158: current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
! 159: if (argc > 0)
! 160: cvs_file_run(argc, argv, &cr);
! 161: else
! 162: cvs_file_run(1, &arg, &cr);
! 163: }
1.5 jfb 164:
1.65 joris 165: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
166: cvs_client_send_files(argv, argc);
167: cvs_client_senddir(".");
1.75 xsa 168:
169: cvs_client_send_request((cvs_cmdop == CVS_OP_RLOG) ?
170: "rlog" : "log");
171:
1.65 joris 172: cvs_client_get_responses();
173: }
174:
1.49 joris 175: return (0);
1.6 jfb 176: }
1.5 jfb 177:
1.57 joris 178: void
179: cvs_log_local(struct cvs_file *cf)
1.1 jfb 180: {
1.57 joris 181: u_int nrev;
1.20 jfb 182: struct rcs_sym *sym;
1.57 joris 183: struct rcs_lock *lkp;
1.1 jfb 184: struct rcs_delta *rdp;
1.21 jfb 185: struct rcs_access *acp;
1.73 xsa 186: char numb[CVS_REV_BUFSZ];
1.60 joris 187:
188: cvs_log(LP_TRACE, "cvs_log_local(%s)", cf->file_path);
1.20 jfb 189:
1.78 joris 190: cvs_file_classify(cf, cvs_directory_tag);
1.39 xsa 191:
1.57 joris 192: if (cf->file_status == FILE_UNKNOWN) {
1.79 ! tobias 193: if (verbosity > 0 && cvs_cmdop != CVS_OP_RLOG)
1.57 joris 194: cvs_log(LP_ERR, "nothing known about %s",
195: cf->file_path);
196: return;
197: } else if (cf->file_status == FILE_ADDED) {
1.39 xsa 198: if (verbosity > 0)
1.62 david 199: cvs_log(LP_ERR, "%s has been added, but not committed",
1.57 joris 200: cf->file_path);
1.59 joris 201: return;
202: }
203:
204: if (cf->file_type == CVS_DIR) {
205: if (verbosity > 1)
206: cvs_log(LP_NOTICE, "Logging %s", cf->file_path);
1.57 joris 207: return;
1.39 xsa 208: }
209:
1.66 xsa 210: if (runflags & L_NAME) {
211: cvs_printf("%s\n", cf->file_rpath);
212: return;
213: }
214:
1.65 joris 215: cvs_printf("\nRCS file: %s", cf->file_rpath);
1.74 xsa 216:
217: if (cvs_cmdop != CVS_OP_RLOG)
218: cvs_printf("\nWorking file: %s", cf->file_path);
219:
1.65 joris 220: cvs_printf("\nhead:");
1.57 joris 221: if (cf->file_rcs->rf_head != NULL)
1.65 joris 222: cvs_printf(" %s", rcsnum_tostr(cf->file_rcs->rf_head,
1.57 joris 223: numb, sizeof(numb)));
224:
1.65 joris 225: cvs_printf("\nbranch:");
1.57 joris 226: if (rcs_branch_get(cf->file_rcs) != NULL) {
1.65 joris 227: cvs_printf(" %s", rcsnum_tostr(rcs_branch_get(cf->file_rcs),
1.57 joris 228: numb, sizeof(numb)));
1.20 jfb 229: }
1.1 jfb 230:
1.65 joris 231: cvs_printf("\nlocks: %s", (cf->file_rcs->rf_flags & RCS_SLOCK)
1.57 joris 232: ? "strict" : "");
233: TAILQ_FOREACH(lkp, &(cf->file_rcs->rf_locks), rl_list)
1.65 joris 234: cvs_printf("\n\t%s: %s", lkp->rl_name,
1.57 joris 235: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.20 jfb 236:
1.65 joris 237: cvs_printf("\naccess list:\n");
1.57 joris 238: TAILQ_FOREACH(acp, &(cf->file_rcs->rf_access), ra_list)
1.65 joris 239: cvs_printf("\t%s\n", acp->ra_name);
1.20 jfb 240:
1.66 xsa 241: if (!(runflags & L_NOTAGS)) {
242: cvs_printf("symbolic names:\n");
243: TAILQ_FOREACH(sym, &(cf->file_rcs->rf_symbols), rs_list) {
244: cvs_printf("\t%s: %s\n", sym->rs_name,
245: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
246: }
1.21 jfb 247: }
248:
1.65 joris 249: cvs_printf("keyword substitution: %s\n",
1.57 joris 250: cf->file_rcs->rf_expand == NULL ? "kv" : cf->file_rcs->rf_expand);
251:
1.65 joris 252: cvs_printf("total revisions: %u", cf->file_rcs->rf_ndelta);
1.20 jfb 253:
1.57 joris 254: if (logrev != NULL)
1.58 joris 255: nrev = cvs_revision_select(cf->file_rcs, logrev);
1.57 joris 256: else
257: nrev = cf->file_rcs->rf_ndelta;
1.21 jfb 258:
1.66 xsa 259: if (cf->file_rcs->rf_head != NULL &&
260: !(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR))
261: cvs_printf(";\tselected revisions: %u", nrev);
262:
1.65 joris 263: cvs_printf("\n");
1.1 jfb 264:
1.66 xsa 265: if (!(runflags & L_HEAD) || (runflags & L_HEAD_DESCR))
266: cvs_printf("description:\n%s", cf->file_rcs->rf_desc);
267:
268: if (!(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR)) {
269: TAILQ_FOREACH(rdp, &(cf->file_rcs->rf_delta), rd_list) {
1.67 xsa 270: /*
271: * if selections are enabled verify that entry is
272: * selected.
273: */
274: if (logrev == NULL || (rdp->rd_flags & RCS_RD_SELECT))
275: log_rev_print(rdp);
1.66 xsa 276: }
1.57 joris 277: }
1.20 jfb 278:
1.65 joris 279: cvs_printf("%s\n", LOG_REVEND);
1.67 xsa 280: }
281:
282: static void
283: log_rev_print(struct rcs_delta *rdp)
284: {
285: int i, found;
1.73 xsa 286: char numb[CVS_REV_BUFSZ], timeb[CVS_TIME_BUFSZ];
1.67 xsa 287: struct cvs_argvector *sargv, *wargv;
288:
289: i = found = 0;
290:
291: /* -s states */
292: if (runflags & L_STATES) {
293: sargv = cvs_strsplit(slist, ",");
294: for (i = 0; sargv->argv[i] != NULL; i++) {
295: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
296: found++;
297: break;
298: }
299: found = 0;
300: }
301: cvs_argv_destroy(sargv);
302: }
303:
304: /* -w[logins] */
305: if (runflags & L_LOGINS) {
306: wargv = cvs_strsplit(wlist, ",");
307: for (i = 0; wargv->argv[i] != NULL; i++) {
308: if (strcmp(rdp->rd_author, wargv->argv[i]) == 0) {
309: found++;
310: break;
311: }
312: found = 0;
313: }
314: cvs_argv_destroy(wargv);
315: }
316:
1.68 xsa 317: if ((runflags & (L_STATES|L_LOGINS)) && found == 0)
1.67 xsa 318: return;
319:
320: cvs_printf("%s\n", LOG_REVSEP);
321:
322: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
323: cvs_printf("revision %s", numb);
324:
325: strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S", &rdp->rd_date);
326: cvs_printf("\ndate: %s; author: %s; state: %s;\n",
327: timeb, rdp->rd_author, rdp->rd_state);
328: cvs_printf("%s", rdp->rd_log);
1.1 jfb 329: }