Annotation of src/usr.bin/cvs/getlog.c, Revision 1.8
1.8 ! jfb 1: /* $OpenBSD: getlog.c,v 1.7 2004/11/26 16:23:50 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:
29: #include <stdlib.h>
30: #include <stdio.h>
31: #include <unistd.h>
32: #include <errno.h>
33: #include <string.h>
34: #include <paths.h>
35: #include <sysexits.h>
36:
37: #include "cvs.h"
38: #include "log.h"
1.6 jfb 39: #include "file.h"
1.3 jfb 40: #include "proto.h"
1.1 jfb 41:
42:
43: #define CVS_GLOG_RFONLY 0x01
44: #define CVS_GLOG_HDONLY 0x02
45:
46:
47: #define CVS_GETLOG_REVSEP "----------------------------"
48: #define CVS_GETLOG_REVEND \
49: "============================================================================="
50:
1.8 ! jfb 51: #ifdef notyet
1.1 jfb 52: static void cvs_getlog_print (const char *, RCSFILE *, u_int);
1.8 ! jfb 53: #endif
1.6 jfb 54: static int cvs_getlog_file (CVSFILE *, void *);
1.1 jfb 55:
56:
57:
58: /*
59: * cvs_getlog()
60: *
61: * Implement the `cvs log' command.
62: */
63:
64: int
65: cvs_getlog(int argc, char **argv)
66: {
1.5 jfb 67: int i, rfonly, honly, flags;
1.6 jfb 68: struct cvsroot *root;
1.1 jfb 69:
1.5 jfb 70: flags = CF_RECURSE;
1.1 jfb 71: rfonly = 0;
72: honly = 0;
73:
74: while ((i = getopt(argc, argv, "d:hlRr:")) != -1) {
75: switch (i) {
76: case 'd':
77: break;
78: case 'h':
79: honly = 1;
80: break;
81: case 'l':
1.5 jfb 82: flags &= ~CF_RECURSE;
1.1 jfb 83: break;
84: case 'R':
85: rfonly = 1;
86: break;
87: case 'r':
88: break;
89: default:
90: return (EX_USAGE);
91: }
92: }
93:
94: argc -= optind;
95: argv += optind;
96:
1.4 jfb 97: if (argc == 0) {
1.5 jfb 98: cvs_files = cvs_file_get(".", flags);
1.4 jfb 99: }
100: else {
1.5 jfb 101: cvs_files = cvs_file_getspec(argv, argc, flags);
1.1 jfb 102: }
1.5 jfb 103: if (cvs_files == NULL)
104: return (EX_DATAERR);
1.1 jfb 105:
1.6 jfb 106: cvs_file_examine(cvs_files, cvs_getlog_file, NULL);
107:
108: root = cvs_files->cf_ddat->cd_root;
109: if (root->cr_method != CVS_METHOD_LOCAL) {
110: cvs_senddir(root, cvs_files);
111: if (argc > 0) {
112: for (i = 0; i < argc; i++)
113: cvs_sendarg(root, argv[i], 0);
114: }
115: cvs_sendreq(root, CVS_REQ_LOG, NULL);
116: }
117:
1.1 jfb 118: return (0);
119: }
120:
121:
1.6 jfb 122: /*
123: * cvs_getlog_file()
124: *
125: * Diff a single file.
126: */
127:
128: static int
129: cvs_getlog_file(CVSFILE *cf, void *arg)
130: {
1.7 jfb 131: char *repo, fpath[MAXPATHLEN];
1.6 jfb 132: RCSFILE *rf;
133: struct cvsroot *root;
134: struct cvs_ent *entp;
135:
1.7 jfb 136: cvs_file_getpath(cf, fpath, sizeof(fpath));
137:
1.6 jfb 138: if (cf->cf_type == DT_DIR) {
139: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
140: root = cf->cf_parent->cf_ddat->cd_root;
1.7 jfb 141: cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
142: CVS_FILE_NAME(cf));
1.6 jfb 143: }
144: else {
145: root = cf->cf_ddat->cd_root;
146: if ((cf->cf_parent == NULL) ||
147: (root != cf->cf_parent->cf_ddat->cd_root)) {
148: cvs_connect(root);
149: }
150:
151: cvs_senddir(root, cf);
152: }
153:
154: return (0);
155: }
156: else
157: root = cf->cf_parent->cf_ddat->cd_root;
158:
159: rf = NULL;
160: if (cf->cf_parent != NULL) {
161: repo = cf->cf_parent->cf_ddat->cd_repo;
162: }
163: else {
164: repo = NULL;
165: }
166:
167: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
168: if (root->cr_method == CVS_METHOD_LOCAL)
1.7 jfb 169: cvs_printf("? %s\n", fpath);
1.6 jfb 170: else
1.7 jfb 171: cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
172: CVS_FILE_NAME(cf));
1.6 jfb 173: return (0);
174: }
175:
1.7 jfb 176: entp = cvs_ent_getent(fpath);
1.6 jfb 177: if (entp == NULL)
178: return (-1);
179:
180: if ((root->cr_method != CVS_METHOD_LOCAL) &&
181: (cvs_sendentry(root, entp) < 0)) {
182: cvs_ent_free(entp);
183: return (-1);
184: }
185:
186: if (root->cr_method != CVS_METHOD_LOCAL) {
187: switch (cf->cf_cvstat) {
188: case CVS_FST_UPTODATE:
1.7 jfb 189: cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
1.6 jfb 190: break;
191: case CVS_FST_ADDED:
192: case CVS_FST_MODIFIED:
1.7 jfb 193: cvs_sendreq(root, CVS_REQ_ISMODIFIED,
194: CVS_FILE_NAME(cf));
1.6 jfb 195: break;
196: default:
197: return (-1);
198: }
199:
200: cvs_ent_free(entp);
201: return (0);
202: }
1.5 jfb 203:
1.7 jfb 204: snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
205: root->cr_dir, repo, fpath, RCS_FILE_EXT);
1.5 jfb 206:
1.7 jfb 207: rf = rcs_open(fpath, RCS_MODE_READ);
1.6 jfb 208: if (rf == NULL) {
209: cvs_ent_free(entp);
210: return (-1);
211: }
212:
213: rcs_close(rf);
214: cvs_ent_free(entp);
215: return (0);
216: }
1.5 jfb 217:
218: #ifdef notyet
1.1 jfb 219: static void
220: cvs_getlog_print(const char *file, RCSFILE *rfp, u_int flags)
221: {
222: char numbuf[64], datebuf[64], *sp;
223: struct rcs_delta *rdp;
224:
1.6 jfb 225: cvs_printf("RCS file: %s\nWorking file: %s\n",
1.1 jfb 226: rfp->rf_path, file);
1.6 jfb 227: cvs_printf("Working file: %s\n", (char *)NULL);
228: cvs_printf("head: %s\nbranch:\nlocks:\naccess list:\n");
229: cvs_printf("symbolic names:\nkeyword substitutions:\n");
230: cvs_printf("total revisions: %u;\tselected revisions: %u\n", 1, 1);
1.1 jfb 231:
1.6 jfb 232: cvs_printf("description:\n");
1.1 jfb 233:
234: for (;;) {
1.6 jfb 235: cvs_printf(CVS_GETLOG_REVSEP "\n");
1.5 jfb 236: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
1.6 jfb 237: cvs_printf("revision %s\n", numbuf);
238: cvs_printf("date: %d/%02d/%d %02d:%02d:%02d; author: %s;"
1.1 jfb 239: " state: %s; lines:",
240: rdp->rd_date.tm_year, rdp->rd_date.tm_mon + 1,
241: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
242: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
243: rdp->rd_author, rdp->rd_state);
244: }
245:
1.6 jfb 246: cvs_printf(CVS_GETLOG_REVEND "\n");
1.1 jfb 247: }
1.5 jfb 248: #endif