Annotation of src/usr.bin/cvs/history.c, Revision 1.21
1.21 ! joris 1: /* $OpenBSD: history.c,v 1.20 2005/06/30 16:37:29 joris Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.5 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.5 tedu 6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
1.1 jfb 9: *
1.5 tedu 10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
1.1 jfb 12: * 2. The name of the author may not be used to endorse or promote products
1.5 tedu 13: * derived from this software without specific prior written permission.
1.1 jfb 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
1.5 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/param.h>
28: #include <sys/stat.h>
29:
30: #include <errno.h>
1.18 xsa 31: #include <fcntl.h>
1.1 jfb 32: #include <stdio.h>
33: #include <stdlib.h>
1.18 xsa 34: #include <string.h>
1.1 jfb 35: #include <unistd.h>
36:
37: #include "cvs.h"
38: #include "log.h"
1.3 jfb 39: #include "proto.h"
1.1 jfb 40:
41: #define CVS_HISTORY_MAXMOD 16
42:
43: /* history flags */
44: #define CVS_HF_A 0x01
45: #define CVS_HF_C 0x02
46: #define CVS_HF_E 0x04
47: #define CVS_HF_L 0x08
48: #define CVS_HF_M 0x10
49: #define CVS_HF_O 0x20
50: #define CVS_HF_T 0x40
51: #define CVS_HF_W 0x80
52:
53: #define CVS_HF_EXCL (CVS_HF_C|CVS_HF_E|CVS_HF_M|CVS_HF_O|CVS_HF_T|CVS_HF_X)
54:
1.14 jfb 55: static int cvs_history_init (struct cvs_cmd *, int, char **, int *);
1.21 ! joris 56: #if 0
1.14 jfb 57: static void cvs_history_print (struct cvs_hent *);
1.21 ! joris 58: #endif
1.14 jfb 59: static int cvs_history_pre_exec (struct cvsroot *);
1.1 jfb 60:
61: extern char *__progname;
62:
1.14 jfb 63: struct cvs_cmd cvs_cmd_history = {
64: CVS_OP_HISTORY, CVS_REQ_HISTORY, "history",
65: { "hi", "his" },
66: "Show repository access history",
1.15 xsa 67: "[-aceloTw] [-b str] [-D date] [-f file] [-m module] [-n module] "
68: "[-p path] [-r rev] [-t tag] [-u user] [-x ACEFGMORTUW] [-z tz]",
69: "ab:cD:ef:lm:n:op:r:Tt:u:wx:z:",
1.14 jfb 70: NULL,
71: 0,
72: cvs_history_init,
73: cvs_history_pre_exec,
74: NULL,
1.9 joris 75: NULL,
76: NULL,
77: NULL,
78: CVS_CMD_SENDDIR
79: };
80:
81: static int flags = 0;
1.19 xsa 82: static char *date, *rev, *user, *tag;
1.9 joris 83: static char *zone = "+0000";
84: static u_int nbmod = 0;
85: static u_int rep = 0;
86: static char *modules[CVS_HISTORY_MAXMOD];
1.1 jfb 87:
1.14 jfb 88: static int
89: cvs_history_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 90: {
1.9 joris 91: int ch;
1.1 jfb 92:
1.19 xsa 93: date = rev = user = tag = NULL;
94:
1.14 jfb 95: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1 jfb 96: switch (ch) {
97: case 'a':
98: flags |= CVS_HF_A;
99: break;
1.15 xsa 100: case 'b':
101: break;
1.1 jfb 102: case 'c':
103: rep++;
104: flags |= CVS_HF_C;
105: break;
1.15 xsa 106: case 'D':
107: break;
1.1 jfb 108: case 'e':
109: rep++;
110: flags |= CVS_HF_E;
111: break;
1.15 xsa 112: case 'f':
113: break;
1.1 jfb 114: case 'l':
115: flags |= CVS_HF_L;
116: break;
117: case 'm':
118: rep++;
119: flags |= CVS_HF_M;
120: if (nbmod == CVS_HISTORY_MAXMOD) {
121: cvs_log(LP_ERR, "too many `-m' options");
1.13 joris 122: return (CVS_EX_USAGE);
1.1 jfb 123: }
124: modules[nbmod++] = optarg;
125: break;
1.15 xsa 126: case 'n':
127: break;
1.1 jfb 128: case 'o':
129: rep++;
130: flags |= CVS_HF_O;
131: break;
1.16 xsa 132: case 'r':
133: rev = optarg;
134: break;
1.1 jfb 135: case 'T':
136: rep++;
137: flags |= CVS_HF_T;
138: break;
139: case 't':
140: tag = optarg;
141: break;
142: case 'u':
143: user = optarg;
144: break;
145: case 'w':
146: flags |= CVS_HF_W;
147: break;
148: case 'x':
149: rep++;
150: break;
151: case 'z':
152: zone = optarg;
153: break;
154: default:
1.13 joris 155: return (CVS_EX_USAGE);
1.1 jfb 156: }
157: }
158:
159: if (rep > 1) {
160: cvs_log(LP_ERR,
161: "Only one report type allowed from: \"-Tcomxe\"");
1.13 joris 162: return (CVS_EX_USAGE);
1.4 deraadt 163: } else if (rep == 0)
1.1 jfb 164: flags |= CVS_HF_O; /* use -o as default */
165:
1.9 joris 166: *arg = optind;
167: return (0);
168: }
1.1 jfb 169:
1.14 jfb 170: static int
171: cvs_history_pre_exec(struct cvsroot *root)
1.9 joris 172: {
1.20 joris 173: if (root->cr_method != CVS_METHOD_LOCAL) {
174: if ((flags & CVS_HF_A) && (cvs_sendarg(root, "-a", 0) < 0))
175: return (CVS_EX_PROTO);
1.1 jfb 176:
1.20 joris 177: if ((flags & CVS_HF_C) && (cvs_sendarg(root, "-c", 0) < 0))
178: return (CVS_EX_PROTO);
1.1 jfb 179:
1.20 joris 180: if ((flags & CVS_HF_O) && (cvs_sendarg(root, "-o", 0) < 0))
181: return (CVS_EX_PROTO);
1.16 xsa 182:
1.20 joris 183: if ((date != NULL) && ((cvs_sendarg(root, "-D", 0) < 0) ||
184: (cvs_sendarg(root, date, 0) < 0)))
185: return (CVS_EX_PROTO);
1.19 xsa 186:
1.20 joris 187: if ((rev != NULL) && ((cvs_sendarg(root, "-r", 0) < 0) ||
188: (cvs_sendarg(root, rev, 0) < 0)))
1.16 xsa 189: return (CVS_EX_PROTO);
1.1 jfb 190:
1.20 joris 191: if ((tag != NULL) && ((cvs_sendarg(root, "-t", 0) < 0) ||
192: (cvs_sendarg(root, tag, 0) < 0)))
1.13 joris 193: return (CVS_EX_PROTO);
1.1 jfb 194:
1.20 joris 195: /* if no user is specified, get login name of command issuer */
196: if (!(flags & CVS_HF_A) && (user == NULL)) {
197: if ((user = getlogin()) == NULL) {
198: cvs_log(LP_ERRNO, "cannot get login name");
199: return (CVS_EX_DATA);
200: }
1.15 xsa 201: }
1.20 joris 202:
203: if (!(flags & CVS_HF_A)) {
204: if ((cvs_sendarg(root, "-u", 0) < 0) ||
205: (cvs_sendarg(root, user, 0) < 0))
206: return (CVS_EX_PROTO);
207: }
208:
209: if ((cvs_sendarg(root, "-z", 0) < 0) ||
210: (cvs_sendarg(root, zone, 0) < 0))
211: return (CVS_EX_PROTO);
1.15 xsa 212: }
1.1 jfb 213:
214: return (0);
215: }
216:
217:
1.21 ! joris 218: #if 0
1.1 jfb 219: static void
220: cvs_history_print(struct cvs_hent *hent)
221: {
222: struct tm etime;
223:
224: if (localtime_r(&(hent->ch_date), &etime) == NULL) {
1.17 xsa 225: cvs_log(LP_ERR, "failed to convert timestamp to structure");
1.1 jfb 226: return;
227: }
228:
229: printf("%c %4d-%02d-%02d %02d:%02d +%04d %-16s %-16s\n",
230: hent->ch_event, etime.tm_year + 1900, etime.tm_mon + 1,
231: etime.tm_mday, etime.tm_hour, etime.tm_min,
232: 0, hent->ch_user, hent->ch_repo);
233: }
1.21 ! joris 234: #endif