Annotation of src/usr.bin/cvs/annotate.c, Revision 1.13
1.13 ! joris 1: /* $OpenBSD: annotate.c,v 1.12 2005/05/20 18:32:23 jfb 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:
27: #include <sys/param.h>
28: #include <sys/stat.h>
29:
30: #include <errno.h>
31: #include <stdio.h>
32: #include <fcntl.h>
33: #include <stdlib.h>
34: #include <unistd.h>
35: #include <string.h>
36:
37: #include "cvs.h"
38: #include "rcs.h"
39: #include "log.h"
40: #include "proto.h"
41:
42:
1.12 jfb 43: static int cvs_annotate_file (CVSFILE *, void *);
44: static int cvs_annotate_options (char *, int, char **, int *);
45: static int cvs_annotate_sendflags (struct cvsroot *);
1.5 joris 46:
47: struct cvs_cmd_info cvs_annotate = {
48: cvs_annotate_options,
49: cvs_annotate_sendflags,
50: cvs_annotate_file,
51: NULL, NULL,
52: CF_SORT | CF_RECURSE | CF_IGNORE | CF_NOSYMS,
53: CVS_REQ_ANNOTATE,
54: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
55: };
1.1 jfb 56:
1.5 joris 57: static char *date, *rev;
58: static int usehead;
1.1 jfb 59:
1.12 jfb 60: static int
1.5 joris 61: cvs_annotate_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 62: {
1.5 joris 63: int ch;
1.1 jfb 64:
1.4 jfb 65: usehead = 0;
1.1 jfb 66: date = NULL;
67: rev = NULL;
68:
1.10 jfb 69: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 70: switch (ch) {
71: case 'D':
72: date = optarg;
73: break;
1.4 jfb 74: case 'f':
75: usehead = 1;
76: break;
1.1 jfb 77: case 'l':
1.5 joris 78: cvs_annotate.file_flags &= ~CF_RECURSE;
1.1 jfb 79: break;
80: case 'R':
1.5 joris 81: cvs_annotate.file_flags |= CF_RECURSE;
1.1 jfb 82: break;
83: case 'r':
1.4 jfb 84: rev = optarg;
1.1 jfb 85: break;
86: default:
1.9 joris 87: return (CVS_EX_USAGE);
1.1 jfb 88: }
89: }
90:
1.4 jfb 91: if ((date != NULL) && (rev != NULL)) {
92: cvs_log(LP_ERR,
93: "the -D and -d arguments are mutually exclusive");
1.9 joris 94: return (CVS_EX_USAGE);
1.4 jfb 95: }
96:
1.5 joris 97: *arg = optind;
98: return (0);
99: }
1.1 jfb 100:
1.12 jfb 101: static int
1.5 joris 102: cvs_annotate_sendflags(struct cvsroot *root)
103: {
104: if (usehead && (cvs_sendarg(root, "-f", 0) < 0))
1.9 joris 105: return (CVS_EX_PROTO);
1.2 jfb 106:
1.5 joris 107: if (rev != NULL) {
108: if ((cvs_sendarg(root, "-r", 0) < 0) ||
109: (cvs_sendarg(root, rev, 0) < 0))
1.9 joris 110: return (CVS_EX_PROTO);
1.1 jfb 111: }
112:
1.5 joris 113: if (date != NULL) {
114: if ((cvs_sendarg(root, "-D", 0) < 0) ||
115: (cvs_sendarg(root, date, 0) < 0))
1.9 joris 116: return (CVS_EX_PROTO);
1.1 jfb 117: }
118:
119: return (0);
120: }
121:
122: /*
123: * cvs_annotate_file()
124: *
125: * Annotate a single file.
126: */
1.12 jfb 127: static int
1.1 jfb 128: cvs_annotate_file(CVSFILE *cf, void *arg)
129: {
1.2 jfb 130: int ret;
1.1 jfb 131: char fpath[MAXPATHLEN];
132: struct cvsroot *root;
133:
1.2 jfb 134: ret = 0;
135: root = CVS_DIR_ROOT(cf);
1.1 jfb 136:
1.3 jfb 137: if (cf->cf_type == DT_DIR) {
1.12 jfb 138: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
139: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
140: cf->cf_name);
141: else
142: ret = cvs_senddir(root, cf);
1.13 ! joris 143:
! 144: if (ret == -1)
! 145: ret = CVS_EX_PROTO;
! 146:
1.2 jfb 147: return (ret);
1.1 jfb 148: }
149:
1.2 jfb 150: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1 jfb 151:
1.12 jfb 152: if (cvs_sendentry(root, cf) < 0) {
153: return (CVS_EX_PROTO);
154: }
1.2 jfb 155:
1.12 jfb 156: switch (cf->cf_cvstat) {
157: case CVS_FST_UNKNOWN:
158: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
159: break;
160: case CVS_FST_UPTODATE:
161: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
162: break;
163: case CVS_FST_ADDED:
164: case CVS_FST_MODIFIED:
165: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
166: break;
167: default:
168: break;
1.1 jfb 169: }
1.13 ! joris 170:
! 171: if (ret == -1)
! 172: ret = CVS_EX_PROTO;
1.1 jfb 173:
1.2 jfb 174: return (ret);
1.1 jfb 175: }