Annotation of src/usr.bin/cvs/getlog.c, Revision 1.67
1.67 ! xsa 1: /* $OpenBSD: getlog.c,v 1.66 2006/10/24 13:15:34 xsa 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.51 xsa 19: #include "includes.h"
1.1 jfb 20:
21: #include "cvs.h"
1.57 joris 22: #include "diff.h"
1.1 jfb 23: #include "log.h"
1.65 joris 24: #include "remote.h"
1.1 jfb 25:
1.57 joris 26: #define LOG_REVSEP \
27: "----------------------------"
1.1 jfb 28:
1.57 joris 29: #define LOG_REVEND \
1.1 jfb 30: "============================================================================="
31:
1.66 xsa 32: #define L_HEAD 0x01
33: #define L_HEAD_DESCR 0x02
34: #define L_NAME 0x04
35: #define L_NOTAGS 0x08
1.67 ! xsa 36: #define L_LOGINS 0x10
! 37: #define L_STATES 0x20
1.66 xsa 38:
1.57 joris 39: void cvs_log_local(struct cvs_file *);
40:
1.67 ! xsa 41: static void log_rev_print(struct rcs_delta *);
! 42:
1.66 xsa 43: int runflags = 0;
1.57 joris 44: char *logrev = NULL;
1.67 ! xsa 45: char *slist = NULL;
! 46: char *wlist = NULL;
1.1 jfb 47:
1.29 jfb 48: struct cvs_cmd cvs_cmd_log = {
1.63 joris 49: CVS_OP_LOG, 0, "log",
1.29 jfb 50: { "lo" },
51: "Print out history information for files",
52: "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.67 ! xsa 53: "bd:hlNRr:s:tw::",
1.29 jfb 54: NULL,
1.57 joris 55: cvs_getlog
1.16 joris 56: };
57:
1.57 joris 58: int
59: cvs_getlog(int argc, char **argv)
1.1 jfb 60: {
1.16 joris 61: int ch;
1.57 joris 62: int flags;
63: char *arg = ".";
64: struct cvs_recursion cr;
1.1 jfb 65:
1.57 joris 66: rcsnum_flags |= RCSNUM_NO_MAGIC;
67: flags = CR_RECURSE_DIRS;
68:
69: while ((ch = getopt(argc, argv, cvs_cmd_log.cmd_opts)) != -1) {
1.16 joris 70: switch (ch) {
1.66 xsa 71: case 'h':
72: runflags |= L_HEAD;
73: break;
1.1 jfb 74: case 'l':
1.57 joris 75: flags &= ~CR_RECURSE_DIRS;
1.1 jfb 76: break;
1.66 xsa 77: case 'N':
78: runflags |= L_NOTAGS;
79: break;
80: case 'R':
81: runflags |= L_NAME;
1.1 jfb 82: case 'r':
1.57 joris 83: logrev = optarg;
1.25 xsa 84: break;
1.67 ! xsa 85: case 's':
! 86: runflags |= L_STATES;
! 87: slist = optarg;
! 88: break;
1.66 xsa 89: case 't':
90: runflags |= L_HEAD_DESCR;
91: break;
1.67 ! xsa 92: case 'w':
! 93: runflags |= L_LOGINS;
! 94: wlist = optarg;
! 95: break;
1.1 jfb 96: default:
1.57 joris 97: fatal("%s", cvs_cmd_log.cmd_synopsis);
1.1 jfb 98: }
99: }
100:
1.57 joris 101: argc -= optind;
102: argv += optind;
1.6 jfb 103:
1.57 joris 104: cr.enterdir = NULL;
105: cr.leavedir = NULL;
1.65 joris 106:
107: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
108: cr.fileproc = cvs_client_sendfile;
109:
1.66 xsa 110: if (runflags & L_HEAD)
111: cvs_client_send_request("Argument -h");
112:
1.65 joris 113: if (!(flags & CR_RECURSE_DIRS))
114: cvs_client_send_request("Argument -l");
115:
1.66 xsa 116: if (runflags & L_NOTAGS)
117: cvs_client_send_request("Argument -N");
118:
119: if (runflags & L_NAME)
120: cvs_client_send_request("Argument -R");
121:
1.65 joris 122: if (logrev != NULL)
123: cvs_client_send_request("Argument -r%s", logrev);
1.66 xsa 124:
1.67 ! xsa 125: if (runflags & L_STATES)
! 126: cvs_client_send_request("Argument -s%s", slist);
! 127:
1.66 xsa 128: if (runflags & L_HEAD_DESCR)
129: cvs_client_send_request("Argument -t");
1.67 ! xsa 130:
! 131: if (runflags & L_LOGINS)
! 132: cvs_client_send_request("Argument -w%s", wlist);
1.65 joris 133: } else {
134: cr.fileproc = cvs_log_local;
135: }
136:
1.57 joris 137: cr.flags = flags;
138:
139: if (argc > 0)
140: cvs_file_run(argc, argv, &cr);
141: else
142: cvs_file_run(1, &arg, &cr);
1.5 jfb 143:
1.65 joris 144: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
145: cvs_client_send_files(argv, argc);
146: cvs_client_senddir(".");
147: cvs_client_send_request("log");
148: cvs_client_get_responses();
149: }
150:
1.49 joris 151: return (0);
1.6 jfb 152: }
1.5 jfb 153:
1.57 joris 154: void
155: cvs_log_local(struct cvs_file *cf)
1.1 jfb 156: {
1.57 joris 157: u_int nrev;
1.20 jfb 158: struct rcs_sym *sym;
1.57 joris 159: struct rcs_lock *lkp;
1.1 jfb 160: struct rcs_delta *rdp;
1.21 jfb 161: struct rcs_access *acp;
1.67 ! xsa 162: char numb[32];
1.60 joris 163:
164: cvs_log(LP_TRACE, "cvs_log_local(%s)", cf->file_path);
1.20 jfb 165:
1.61 joris 166: cvs_file_classify(cf, NULL, 0);
1.39 xsa 167:
1.57 joris 168: if (cf->file_status == FILE_UNKNOWN) {
169: if (verbosity > 0)
170: cvs_log(LP_ERR, "nothing known about %s",
171: cf->file_path);
172: return;
173: } else if (cf->file_status == FILE_ADDED) {
1.39 xsa 174: if (verbosity > 0)
1.62 david 175: cvs_log(LP_ERR, "%s has been added, but not committed",
1.57 joris 176: cf->file_path);
1.59 joris 177: return;
178: }
179:
180: if (cf->file_type == CVS_DIR) {
181: if (verbosity > 1)
182: cvs_log(LP_NOTICE, "Logging %s", cf->file_path);
1.57 joris 183: return;
1.39 xsa 184: }
185:
1.66 xsa 186: if (runflags & L_NAME) {
187: cvs_printf("%s\n", cf->file_rpath);
188: return;
189: }
190:
1.65 joris 191: cvs_printf("\nRCS file: %s", cf->file_rpath);
192: cvs_printf("\nWorking file: %s", cf->file_path);
193: cvs_printf("\nhead:");
1.57 joris 194: if (cf->file_rcs->rf_head != NULL)
1.65 joris 195: cvs_printf(" %s", rcsnum_tostr(cf->file_rcs->rf_head,
1.57 joris 196: numb, sizeof(numb)));
197:
1.65 joris 198: cvs_printf("\nbranch:");
1.57 joris 199: if (rcs_branch_get(cf->file_rcs) != NULL) {
1.65 joris 200: cvs_printf(" %s", rcsnum_tostr(rcs_branch_get(cf->file_rcs),
1.57 joris 201: numb, sizeof(numb)));
1.20 jfb 202: }
1.1 jfb 203:
1.65 joris 204: cvs_printf("\nlocks: %s", (cf->file_rcs->rf_flags & RCS_SLOCK)
1.57 joris 205: ? "strict" : "");
206: TAILQ_FOREACH(lkp, &(cf->file_rcs->rf_locks), rl_list)
1.65 joris 207: cvs_printf("\n\t%s: %s", lkp->rl_name,
1.57 joris 208: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.20 jfb 209:
1.65 joris 210: cvs_printf("\naccess list:\n");
1.57 joris 211: TAILQ_FOREACH(acp, &(cf->file_rcs->rf_access), ra_list)
1.65 joris 212: cvs_printf("\t%s\n", acp->ra_name);
1.20 jfb 213:
1.66 xsa 214: if (!(runflags & L_NOTAGS)) {
215: cvs_printf("symbolic names:\n");
216: TAILQ_FOREACH(sym, &(cf->file_rcs->rf_symbols), rs_list) {
217: cvs_printf("\t%s: %s\n", sym->rs_name,
218: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
219: }
1.21 jfb 220: }
221:
1.65 joris 222: cvs_printf("keyword substitution: %s\n",
1.57 joris 223: cf->file_rcs->rf_expand == NULL ? "kv" : cf->file_rcs->rf_expand);
224:
1.65 joris 225: cvs_printf("total revisions: %u", cf->file_rcs->rf_ndelta);
1.20 jfb 226:
1.57 joris 227: if (logrev != NULL)
1.58 joris 228: nrev = cvs_revision_select(cf->file_rcs, logrev);
1.57 joris 229: else
230: nrev = cf->file_rcs->rf_ndelta;
1.21 jfb 231:
1.66 xsa 232: if (cf->file_rcs->rf_head != NULL &&
233: !(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR))
234: cvs_printf(";\tselected revisions: %u", nrev);
235:
1.65 joris 236: cvs_printf("\n");
1.1 jfb 237:
1.66 xsa 238: if (!(runflags & L_HEAD) || (runflags & L_HEAD_DESCR))
239: cvs_printf("description:\n%s", cf->file_rcs->rf_desc);
240:
241: if (!(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR)) {
242: TAILQ_FOREACH(rdp, &(cf->file_rcs->rf_delta), rd_list) {
1.67 ! xsa 243: /*
! 244: * if selections are enabled verify that entry is
! 245: * selected.
! 246: */
! 247: if (logrev == NULL || (rdp->rd_flags & RCS_RD_SELECT))
! 248: log_rev_print(rdp);
1.66 xsa 249: }
1.57 joris 250: }
1.20 jfb 251:
1.65 joris 252: cvs_printf("%s\n", LOG_REVEND);
1.67 ! xsa 253: }
! 254:
! 255: static void
! 256: log_rev_print(struct rcs_delta *rdp)
! 257: {
! 258: int i, found;
! 259: char numb[32], timeb[32];
! 260: struct cvs_argvector *sargv, *wargv;
! 261:
! 262: i = found = 0;
! 263:
! 264: /* -s states */
! 265: if (runflags & L_STATES) {
! 266: sargv = cvs_strsplit(slist, ",");
! 267: for (i = 0; sargv->argv[i] != NULL; i++) {
! 268: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
! 269: found++;
! 270: break;
! 271: }
! 272: found = 0;
! 273: }
! 274: cvs_argv_destroy(sargv);
! 275: }
! 276:
! 277: /* -w[logins] */
! 278: if (runflags & L_LOGINS) {
! 279: wargv = cvs_strsplit(wlist, ",");
! 280: for (i = 0; wargv->argv[i] != NULL; i++) {
! 281: if (strcmp(rdp->rd_author, wargv->argv[i]) == 0) {
! 282: found++;
! 283: break;
! 284: }
! 285: found = 0;
! 286: }
! 287: cvs_argv_destroy(wargv);
! 288: }
! 289:
! 290: if ((((runflags & L_STATES) && (runflags & L_LOGINS)) ||
! 291: (runflags & (L_STATES | L_LOGINS))) && found == 0)
! 292: return;
! 293:
! 294: cvs_printf("%s\n", LOG_REVSEP);
! 295:
! 296: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
! 297: cvs_printf("revision %s", numb);
! 298:
! 299: strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S", &rdp->rd_date);
! 300: cvs_printf("\ndate: %s; author: %s; state: %s;\n",
! 301: timeb, rdp->rd_author, rdp->rd_state);
! 302: cvs_printf("%s", rdp->rd_log);
1.1 jfb 303: }