Annotation of src/usr.bin/cvs/annotate.c, Revision 1.29
1.29 ! xsa 1: /* $OpenBSD: annotate.c,v 1.28 2006/01/27 15:26:38 xsa Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: *
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
1.27 xsa 27: #include "includes.h"
1.1 jfb 28:
29: #include "cvs.h"
30: #include "log.h"
31: #include "proto.h"
32:
1.23 xsa 33: static int cvs_annotate_init(struct cvs_cmd *, int, char **, int *);
34: static int cvs_annotate_remote(CVSFILE *, void *);
35: static int cvs_annotate_local(CVSFILE *, void *);
36: static int cvs_annotate_pre_exec(struct cvsroot *);
1.14 jfb 37:
38: struct cvs_cmd cvs_cmd_annotate = {
39: CVS_OP_ANNOTATE, CVS_REQ_ANNOTATE, "annotate",
40: { "ann", "blame" },
41: "Show last revision where each line was modified",
42: "[-flR] [-D date | -r rev] ...",
43: "D:flRr:",
44: NULL,
45: CF_SORT | CF_RECURSE | CF_IGNORE | CF_NOSYMS,
1.18 xsa 46: cvs_annotate_init,
47: cvs_annotate_pre_exec,
48: cvs_annotate_remote,
49: cvs_annotate_local,
1.14 jfb 50: NULL,
51: NULL,
1.5 joris 52: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
1.19 joris 53: };
1.1 jfb 54:
1.5 joris 55: static char *date, *rev;
56: static int usehead;
1.1 jfb 57:
1.12 jfb 58: static int
1.18 xsa 59: cvs_annotate_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 60: {
1.5 joris 61: int ch;
1.1 jfb 62:
1.4 jfb 63: usehead = 0;
1.1 jfb 64: date = NULL;
65: rev = NULL;
66:
1.14 jfb 67: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1 jfb 68: switch (ch) {
69: case 'D':
70: date = optarg;
71: break;
1.4 jfb 72: case 'f':
73: usehead = 1;
74: break;
1.1 jfb 75: case 'l':
1.14 jfb 76: cmd->file_flags &= ~CF_RECURSE;
1.1 jfb 77: break;
78: case 'R':
1.14 jfb 79: cmd->file_flags |= CF_RECURSE;
1.1 jfb 80: break;
81: case 'r':
1.4 jfb 82: rev = optarg;
1.1 jfb 83: break;
84: default:
1.9 joris 85: return (CVS_EX_USAGE);
1.1 jfb 86: }
1.4 jfb 87: }
88:
1.5 joris 89: *arg = optind;
90: return (0);
91: }
1.1 jfb 92:
1.12 jfb 93: static int
1.18 xsa 94: cvs_annotate_pre_exec(struct cvsroot *root)
1.5 joris 95: {
1.18 xsa 96: if (root->cr_method != CVS_METHOD_LOCAL) {
1.26 xsa 97: if (usehead == 1)
1.25 joris 98: cvs_sendarg(root, "-f", 0);
1.2 jfb 99:
1.18 xsa 100: if (rev != NULL) {
1.25 joris 101: cvs_sendarg(root, "-r", 0);
102: cvs_sendarg(root, rev, 0);
1.18 xsa 103: }
1.1 jfb 104:
1.18 xsa 105: if (date != NULL) {
1.25 joris 106: cvs_sendarg(root, "-D", 0);
107: cvs_sendarg(root, date, 0);
1.18 xsa 108: }
1.1 jfb 109: }
110:
111: return (0);
112: }
113:
114: /*
1.18 xsa 115: * cvs_annotate_remote()
1.1 jfb 116: *
117: * Annotate a single file.
118: */
1.12 jfb 119: static int
1.18 xsa 120: cvs_annotate_remote(CVSFILE *cf, void *arg)
1.1 jfb 121: {
122: char fpath[MAXPATHLEN];
123: struct cvsroot *root;
124:
1.2 jfb 125: root = CVS_DIR_ROOT(cf);
1.1 jfb 126:
1.3 jfb 127: if (cf->cf_type == DT_DIR) {
1.12 jfb 128: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
1.25 joris 129: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.12 jfb 130: else
1.25 joris 131: cvs_senddir(root, cf);
132: return (0);
1.1 jfb 133: }
134:
1.2 jfb 135: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.25 joris 136: cvs_sendentry(root, cf);
1.2 jfb 137:
1.12 jfb 138: switch (cf->cf_cvstat) {
139: case CVS_FST_UNKNOWN:
1.25 joris 140: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.12 jfb 141: break;
142: case CVS_FST_UPTODATE:
1.25 joris 143: cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.12 jfb 144: break;
145: case CVS_FST_ADDED:
146: case CVS_FST_MODIFIED:
1.25 joris 147: cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.12 jfb 148: break;
149: default:
150: break;
1.1 jfb 151: }
1.13 joris 152:
1.25 joris 153: return (0);
1.18 xsa 154: }
155:
156:
157: static int
158: cvs_annotate_local(CVSFILE *cf, void *arg)
159: {
1.21 xsa 160: char fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.18 xsa 161: RCSFILE *rf;
162:
163: if (cf->cf_type == DT_DIR)
164: return (0);
165:
166: cvs_file_getpath(cf, fpath, sizeof(fpath));
167:
168: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
169: return (0);
170:
1.24 xsa 171: cvs_rcs_getpath(cf, rcspath, sizeof(rcspath));
1.18 xsa 172:
1.28 xsa 173: if ((rf = rcs_open(rcspath, RCS_READ)) == NULL)
174: fatal("cvs_annotate_local: rcs_open `%s': %s", rcspath,
1.29 ! xsa 175: rcs_errstr(rcs_errno));
1.18 xsa 176:
177: cvs_printf("Annotations for %s", cf->cf_name);
178: cvs_printf("\n***************\n");
179:
180: rcs_close(rf);
181:
182: return (0);
1.1 jfb 183: }