Annotation of src/usr.bin/cvs/history.c, Revision 1.14
1.14 ! jfb 1: /* $OpenBSD: history.c,v 1.13 2005/04/12 14:58:40 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>
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"
1.3 jfb 40: #include "proto.h"
1.1 jfb 41:
42: #define CVS_HISTORY_MAXMOD 16
43:
44: /* history flags */
45: #define CVS_HF_A 0x01
46: #define CVS_HF_C 0x02
47: #define CVS_HF_E 0x04
48: #define CVS_HF_L 0x08
49: #define CVS_HF_M 0x10
50: #define CVS_HF_O 0x20
51: #define CVS_HF_T 0x40
52: #define CVS_HF_W 0x80
53:
54: #define CVS_HF_EXCL (CVS_HF_C|CVS_HF_E|CVS_HF_M|CVS_HF_O|CVS_HF_T|CVS_HF_X)
55:
1.14 ! jfb 56: static int cvs_history_init (struct cvs_cmd *, int, char **, int *);
! 57: static void cvs_history_print (struct cvs_hent *);
! 58: static int cvs_history_pre_exec (struct cvsroot *);
1.1 jfb 59:
60: extern char *__progname;
61:
1.14 ! jfb 62: struct cvs_cmd cvs_cmd_history = {
! 63: CVS_OP_HISTORY, CVS_REQ_HISTORY, "history",
! 64: { "hi", "his" },
! 65: "Show repository access history",
! 66: "",
! 67: "acelm:oTt:u:wx:z:",
! 68: NULL,
! 69: 0,
! 70: cvs_history_init,
! 71: cvs_history_pre_exec,
! 72: NULL,
1.9 joris 73: NULL,
74: NULL,
75: NULL,
76: CVS_CMD_SENDDIR
77: };
78:
79: static int flags = 0;
80: static char *user = NULL;
81: static char *zone = "+0000";
82: static char *tag = NULL;
83: static u_int nbmod = 0;
84: static u_int rep = 0;
85: static char *modules[CVS_HISTORY_MAXMOD];
1.1 jfb 86:
1.14 ! jfb 87: static int
! 88: cvs_history_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 89: {
1.9 joris 90: int ch;
1.1 jfb 91:
1.14 ! jfb 92: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1 jfb 93: switch (ch) {
94: case 'a':
95: flags |= CVS_HF_A;
96: break;
97: case 'c':
98: rep++;
99: flags |= CVS_HF_C;
100: break;
101: case 'e':
102: rep++;
103: flags |= CVS_HF_E;
104: break;
105: case 'l':
106: flags |= CVS_HF_L;
107: break;
108: case 'm':
109: rep++;
110: flags |= CVS_HF_M;
111: if (nbmod == CVS_HISTORY_MAXMOD) {
112: cvs_log(LP_ERR, "too many `-m' options");
1.13 joris 113: return (CVS_EX_USAGE);
1.1 jfb 114: }
115: modules[nbmod++] = optarg;
116: break;
117: case 'o':
118: rep++;
119: flags |= CVS_HF_O;
120: break;
121: case 'T':
122: rep++;
123: flags |= CVS_HF_T;
124: break;
125: case 't':
126: tag = optarg;
127: break;
128: case 'u':
129: user = optarg;
130: break;
131: case 'w':
132: flags |= CVS_HF_W;
133: break;
134: case 'x':
135: rep++;
136: break;
137: case 'z':
138: zone = optarg;
139: break;
140: default:
1.13 joris 141: return (CVS_EX_USAGE);
1.1 jfb 142: }
143: }
144:
145: if (rep > 1) {
146: cvs_log(LP_ERR,
147: "Only one report type allowed from: \"-Tcomxe\"");
1.13 joris 148: return (CVS_EX_USAGE);
1.4 deraadt 149: } else if (rep == 0)
1.1 jfb 150: flags |= CVS_HF_O; /* use -o as default */
151:
1.9 joris 152: *arg = optind;
153: return (0);
154: }
1.1 jfb 155:
1.14 ! jfb 156: static int
! 157: cvs_history_pre_exec(struct cvsroot *root)
1.9 joris 158: {
1.1 jfb 159:
1.9 joris 160: if ((flags & CVS_HF_C) && (cvs_sendarg(root, "-c", 0) < 0))
1.13 joris 161: return (CVS_EX_PROTO);
1.1 jfb 162:
1.9 joris 163: if ((flags & CVS_HF_O) && (cvs_sendarg(root, "-o", 0) < 0))
1.13 joris 164: return (CVS_EX_PROTO);
1.1 jfb 165:
1.9 joris 166: if (tag != NULL) {
167: if ((cvs_sendarg(root, "-t", 0) < 0) ||
168: (cvs_sendarg(root, tag, 0) < 0))
1.13 joris 169: return (CVS_EX_PROTO);
1.9 joris 170: }
1.1 jfb 171:
1.9 joris 172: if (user != NULL) {
173: if ((cvs_sendarg(root, "-u", 0) < 0) ||
174: (cvs_sendarg(root, user, 0) < 0))
1.13 joris 175: return (CVS_EX_PROTO);
1.1 jfb 176: }
1.9 joris 177:
178: if ((cvs_sendarg(root, "-z", 0) < 0) ||
179: (cvs_sendarg(root, zone, 0) < 0))
1.13 joris 180: return (CVS_EX_PROTO);
1.1 jfb 181:
182: return (0);
183: }
184:
185:
186: static void
187: cvs_history_print(struct cvs_hent *hent)
188: {
189: struct tm etime;
190:
191: if (localtime_r(&(hent->ch_date), &etime) == NULL) {
192: cvs_log(LP_ERROR, "failed to convert timestamp to structure");
193: return;
194: }
195:
196: printf("%c %4d-%02d-%02d %02d:%02d +%04d %-16s %-16s\n",
197: hent->ch_event, etime.tm_year + 1900, etime.tm_mon + 1,
198: etime.tm_mday, etime.tm_hour, etime.tm_min,
199: 0, hent->ch_user, hent->ch_repo);
200: }