Annotation of src/usr.bin/cvs/getlog.c, Revision 1.16
1.16 ! joris 1: /* $OpenBSD: getlog.c,v 1.15 2005/03/26 08:09:54 tedu Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.10 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.10 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.10 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.10 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.10 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 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.10 tedu 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:
1.16 ! joris 56: int cvs_getlog_options(char *, int, char **, int *);
1.1 jfb 57:
1.16 ! joris 58: struct cvs_cmd_info cvs_getlog = {
! 59: cvs_getlog_options,
! 60: NULL,
! 61: cvs_getlog_file,
! 62: NULL, NULL,
! 63: CF_RECURSE,
! 64: CVS_REQ_LOG,
! 65: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
! 66: };
! 67:
! 68: static int rfonly = 0;
! 69: static int honly = 0;
1.1 jfb 70:
71: int
1.16 ! joris 72: cvs_getlog_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 73: {
1.16 ! joris 74: int ch;
1.1 jfb 75:
1.16 ! joris 76: while ((ch = getopt(argc, argv, opt)) != -1) {
! 77: switch (ch) {
1.1 jfb 78: case 'd':
79: break;
80: case 'h':
81: honly = 1;
82: break;
83: case 'l':
1.16 ! joris 84: cvs_getlog.file_flags &= ~CF_RECURSE;
1.1 jfb 85: break;
86: case 'R':
87: rfonly = 1;
88: break;
89: case 'r':
90: break;
91: default:
92: return (EX_USAGE);
93: }
94: }
95:
1.16 ! joris 96: *arg = optind;
1.1 jfb 97: return (0);
98: }
99:
100:
1.6 jfb 101: /*
102: * cvs_getlog_file()
103: *
104: * Diff a single file.
105: */
106: static int
107: cvs_getlog_file(CVSFILE *cf, void *arg)
108: {
1.12 jfb 109: int ret;
1.7 jfb 110: char *repo, fpath[MAXPATHLEN];
1.6 jfb 111: RCSFILE *rf;
112: struct cvsroot *root;
113: struct cvs_ent *entp;
114:
1.12 jfb 115: ret = 0;
116: rf = NULL;
117: root = CVS_DIR_ROOT(cf);
118: repo = CVS_DIR_REPO(cf);
1.7 jfb 119:
1.13 jfb 120: if (cf->cf_type == DT_DIR) {
121: if (root->cr_method != CVS_METHOD_LOCAL) {
122: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
123: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
124: CVS_FILE_NAME(cf));
125: else
126: ret = cvs_senddir(root, cf);
127: }
128:
1.12 jfb 129: return (ret);
1.6 jfb 130: }
131:
1.12 jfb 132: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.7 jfb 133: entp = cvs_ent_getent(fpath);
1.6 jfb 134:
1.12 jfb 135: if (root->cr_method != CVS_METHOD_LOCAL) {
136: if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
137: cvs_ent_free(entp);
138: return (-1);
139: }
1.6 jfb 140:
141: switch (cf->cf_cvstat) {
1.12 jfb 142: case CVS_FST_UNKNOWN:
143: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
144: CVS_FILE_NAME(cf));
145: break;
1.6 jfb 146: case CVS_FST_UPTODATE:
1.12 jfb 147: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
148: CVS_FILE_NAME(cf));
1.6 jfb 149: break;
150: case CVS_FST_ADDED:
151: case CVS_FST_MODIFIED:
1.12 jfb 152: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
1.7 jfb 153: CVS_FILE_NAME(cf));
1.6 jfb 154: break;
155: default:
1.12 jfb 156: break;
157: }
158: } else {
159: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
160: cvs_printf("? %s\n", fpath);
161: return (0);
162: }
163:
164: snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
165: root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
166:
1.14 jfb 167: rf = rcs_open(fpath, RCS_READ);
1.12 jfb 168: if (rf == NULL) {
1.15 tedu 169: if (entp != NULL)
170: cvs_ent_free(entp);
1.6 jfb 171: return (-1);
172: }
173:
1.12 jfb 174: rcs_close(rf);
1.6 jfb 175: }
1.5 jfb 176:
1.12 jfb 177: if (entp != NULL)
1.6 jfb 178: cvs_ent_free(entp);
1.12 jfb 179: return (ret);
1.6 jfb 180: }
1.5 jfb 181:
182: #ifdef notyet
1.1 jfb 183: static void
184: cvs_getlog_print(const char *file, RCSFILE *rfp, u_int flags)
185: {
186: char numbuf[64], datebuf[64], *sp;
187: struct rcs_delta *rdp;
188:
1.6 jfb 189: cvs_printf("RCS file: %s\nWorking file: %s\n",
1.1 jfb 190: rfp->rf_path, file);
1.6 jfb 191: cvs_printf("Working file: %s\n", (char *)NULL);
192: cvs_printf("head: %s\nbranch:\nlocks:\naccess list:\n");
193: cvs_printf("symbolic names:\nkeyword substitutions:\n");
194: cvs_printf("total revisions: %u;\tselected revisions: %u\n", 1, 1);
1.1 jfb 195:
1.6 jfb 196: cvs_printf("description:\n");
1.1 jfb 197:
198: for (;;) {
1.6 jfb 199: cvs_printf(CVS_GETLOG_REVSEP "\n");
1.5 jfb 200: rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
1.6 jfb 201: cvs_printf("revision %s\n", numbuf);
202: cvs_printf("date: %d/%02d/%d %02d:%02d:%02d; author: %s;"
1.1 jfb 203: " state: %s; lines:",
204: rdp->rd_date.tm_year, rdp->rd_date.tm_mon + 1,
205: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
206: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
207: rdp->rd_author, rdp->rd_state);
208: }
209:
1.6 jfb 210: cvs_printf(CVS_GETLOG_REVEND "\n");
1.1 jfb 211: }
1.5 jfb 212: #endif