Annotation of src/usr.bin/cvs/history.c, Revision 1.1.1.1
1.1 jfb 1: /* $OpenBSD$ */
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: #include <sysexits.h>
37:
38: #include "cvs.h"
39: #include "rcs.h"
40: #include "log.h"
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:
56: static void cvs_history_print (struct cvs_hent *);
57:
58:
59: extern char *__progname;
60:
61: extern struct cvsroot *cvs_root;
62:
63:
64: /*
65: * cvs_history()
66: *
67: * Handle the `cvs history' command.
68: */
69:
70:
71: int
72: cvs_history(int argc, char **argv)
73: {
74: int ch, flags;
75: u_int nbmod, rep;
76: char *user, *zone, *tag, *cp;
77: char *modules[CVS_HISTORY_MAXMOD], histpath[MAXPATHLEN];
78: struct cvs_hent *hent;
79: CVSHIST *hp;
80:
81: tag = NULL;
82: user = NULL;
83: zone = "+0000";
84: nbmod = 0;
85: flags = 0;
86: rep = 0;
87:
88: while ((ch = getopt(argc, argv, "acelm:oTt:u:wx:z:")) != -1) {
89: switch (ch) {
90: case 'a':
91: flags |= CVS_HF_A;
92: break;
93: case 'c':
94: rep++;
95: flags |= CVS_HF_C;
96: break;
97: case 'e':
98: rep++;
99: flags |= CVS_HF_E;
100: break;
101: case 'l':
102: flags |= CVS_HF_L;
103: break;
104: case 'm':
105: rep++;
106: flags |= CVS_HF_M;
107: if (nbmod == CVS_HISTORY_MAXMOD) {
108: cvs_log(LP_ERR, "too many `-m' options");
109: return (EX_USAGE);
110: }
111: modules[nbmod++] = optarg;
112: break;
113: case 'o':
114: rep++;
115: flags |= CVS_HF_O;
116: break;
117: case 'T':
118: rep++;
119: flags |= CVS_HF_T;
120: break;
121: case 't':
122: tag = optarg;
123: break;
124: case 'u':
125: user = optarg;
126: break;
127: case 'w':
128: flags |= CVS_HF_W;
129: break;
130: case 'x':
131: rep++;
132: for (cp = optarg; *cp != '\0'; cp++) {
133: }
134: break;
135: case 'z':
136: zone = optarg;
137: break;
138: default:
139: return (EX_USAGE);
140: }
141: }
142:
143: if (rep > 1) {
144: cvs_log(LP_ERR,
145: "Only one report type allowed from: \"-Tcomxe\"");
146: return (EX_USAGE);
147: }
148: else if (rep == 0)
149: flags |= CVS_HF_O; /* use -o as default */
150:
151: if (cvs_root->cr_method == CVS_METHOD_LOCAL) {
152: snprintf(histpath, sizeof(histpath), "%s/%s", cvs_root->cr_dir,
153: CVS_PATH_HISTORY);
154: hp = cvs_hist_open(histpath);
155: if (hp == NULL) {
156: return (EX_UNAVAILABLE);
157: }
158:
159: while ((hent = cvs_hist_getnext(hp)) != NULL) {
160: cvs_history_print(hent);
161: }
162: cvs_hist_close(hp);
163: }
164: else {
165: if (flags & CVS_HF_C)
166: cvs_client_sendarg("-c", 0);
167:
168: if (flags & CVS_HF_O)
169: cvs_client_sendarg("-o", 0);
170:
171: if (tag != NULL) {
172: cvs_client_sendarg("-t", 0);
173: cvs_client_sendarg(tag, 0);
174: }
175: if (user != NULL) {
176: cvs_client_sendarg("-u", 0);
177: cvs_client_sendarg(user, 0);
178: }
179:
180:
181: cvs_client_sendarg("-z", 0);
182: cvs_client_sendarg(zone, 0);
183:
184: cvs_client_sendreq(CVS_REQ_HISTORY, NULL, 1);
185: }
186:
187: return (0);
188: }
189:
190:
191: static void
192: cvs_history_print(struct cvs_hent *hent)
193: {
194: struct tm etime;
195:
196: if (localtime_r(&(hent->ch_date), &etime) == NULL) {
197: cvs_log(LP_ERROR, "failed to convert timestamp to structure");
198: return;
199: }
200:
201: printf("%c %4d-%02d-%02d %02d:%02d +%04d %-16s %-16s\n",
202: hent->ch_event, etime.tm_year + 1900, etime.tm_mon + 1,
203: etime.tm_mday, etime.tm_hour, etime.tm_min,
204: 0, hent->ch_user, hent->ch_repo);
205: }