Annotation of src/usr.bin/cvs/status.c, Revision 1.18
1.18 ! xsa 1: /* $OpenBSD: status.c,v 1.17 2005/04/16 20:26:05 joris Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.4 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.4 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.4 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.4 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.4 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/types.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 "log.h"
39: #include "proto.h"
40:
41:
1.15 jfb 42: #define CVS_STATUS_SEP \
43: "==================================================================="
44:
45:
1.1 jfb 46: const char *cvs_statstr[] = {
47: "Unknown",
1.15 jfb 48: "Up-to-date",
1.1 jfb 49: "Locally Modified",
50: "Added",
51: "Removed",
52: "Conflict",
53: "Patched",
1.16 jfb 54: "Needs Checkout",
1.1 jfb 55: };
56:
57:
1.15 jfb 58: int cvs_status_file (CVSFILE *, void *);
59: int cvs_status_local (CVSFILE *, void *);
60: int cvs_status_options (char *, int, char **, int *);
61: int cvs_status_sendflags (struct cvsroot *);
1.10 joris 62:
63: struct cvs_cmd_info cvs_status = {
64: cvs_status_options,
65: cvs_status_sendflags,
66: cvs_status_file,
67: NULL, NULL,
68: CF_SORT | CF_IGNORE | CF_RECURSE,
69: CVS_REQ_STATUS,
70: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
71: };
1.1 jfb 72:
1.10 joris 73: static int verbose = 0;
1.1 jfb 74:
75: int
1.10 joris 76: cvs_status_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 77: {
1.10 joris 78: int ch;
1.1 jfb 79:
1.10 joris 80: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 81: switch (ch) {
1.7 jfb 82: case 'l':
1.10 joris 83: cvs_status.file_flags &= ~CF_RECURSE;
1.7 jfb 84: break;
85: case 'R':
1.10 joris 86: cvs_status.file_flags |= CF_RECURSE;
1.7 jfb 87: break;
88: case 'v':
89: verbose = 1;
90: break;
1.1 jfb 91: default:
1.14 joris 92: return (CVS_EX_USAGE);
1.1 jfb 93: }
94: }
95:
1.10 joris 96: *arg = optind;
97: return (0);
98: }
1.1 jfb 99:
1.10 joris 100: int
101: cvs_status_sendflags(struct cvsroot *root)
102: {
103: if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
1.14 joris 104: return (CVS_EX_PROTO);
1.1 jfb 105: return (0);
106: }
107:
108: /*
109: * cvs_status_file()
110: *
111: * Get the status of a single file.
112: */
113: int
1.2 jfb 114: cvs_status_file(CVSFILE *cfp, void *arg)
1.1 jfb 115: {
1.5 jfb 116: int ret;
1.15 jfb 117: char *repo, fpath[MAXPATHLEN];
1.1 jfb 118: RCSFILE *rf;
119: struct cvs_ent *entp;
120: struct cvsroot *root;
121:
1.5 jfb 122: ret = 0;
1.1 jfb 123: rf = NULL;
1.5 jfb 124: root = CVS_DIR_ROOT(cfp);
125: repo = CVS_DIR_REPO(cfp);
1.1 jfb 126:
1.6 jfb 127: if (cfp->cf_type == DT_DIR) {
1.15 jfb 128: if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
129: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
130: CVS_FILE_NAME(cfp));
131: else
132: ret = cvs_senddir(root, cfp);
1.6 jfb 133: return (ret);
134: }
1.1 jfb 135:
1.5 jfb 136: cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.2 jfb 137: entp = cvs_ent_getent(fpath);
1.1 jfb 138:
1.15 jfb 139: if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
140: cvs_ent_free(entp);
141: return (-1);
142: }
143:
144: switch (cfp->cf_cvstat) {
145: case CVS_FST_UNKNOWN:
146: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
147: CVS_FILE_NAME(cfp));
148: break;
149: case CVS_FST_UPTODATE:
150: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
151: CVS_FILE_NAME(cfp));
152: break;
1.17 joris 153: case CVS_FST_ADDED:
1.15 jfb 154: case CVS_FST_MODIFIED:
155: ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
156: CVS_FILE_NAME(cfp));
157: if (ret == 0)
158: ret = cvs_sendfile(root, fpath);
159: default:
160: break;
161: }
162:
163: if (entp != NULL)
164: cvs_ent_free(entp);
165: return (ret);
166: }
167:
168: int
169: cvs_status_local(CVSFILE *cfp, void *arg)
170: {
1.18 ! xsa 171: int l;
1.16 jfb 172: char *repo, buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.15 jfb 173: RCSFILE *rf;
174: struct cvs_ent *entp;
175: struct cvsroot *root;
176:
177: if (cfp->cf_type == DT_DIR)
178: return (0);
179:
180: root = CVS_DIR_ROOT(cfp);
181: repo = CVS_DIR_REPO(cfp);
1.1 jfb 182:
1.15 jfb 183: cvs_file_getpath(cfp, fpath, sizeof(fpath));
184: entp = cvs_ent_getent(fpath);
1.1 jfb 185:
1.15 jfb 186: if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
187: cvs_log(LP_WARN, "I know nothing about %s", fpath);
188: return (0);
189: }
1.1 jfb 190:
1.18 ! xsa 191: l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.15 jfb 192: root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.18 ! xsa 193: if (l == -1 || l >= (int)sizeof(rcspath)) {
! 194: errno = ENAMETOOLONG;
! 195: cvs_log(LP_ERRNO, "%s", rcspath);
! 196:
! 197: cvs_ent_free(entp);
! 198: return (-1);
! 199: }
1.1 jfb 200:
1.15 jfb 201: rf = rcs_open(rcspath, RCS_READ);
202: if (rf == NULL) {
203: if (entp != NULL)
204: cvs_ent_free(entp);
205: return (-1);
1.1 jfb 206: }
1.5 jfb 207:
1.16 jfb 208: buf[0] = '\0';
209: if (cfp->cf_cvstat == CVS_FST_LOST)
210: strlcpy(buf, "No file ", sizeof(buf));
211: strlcat(buf, CVS_FILE_NAME(cfp), sizeof(buf));
212:
1.15 jfb 213: cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
1.16 jfb 214: buf, cvs_statstr[cfp->cf_cvstat]);
215:
216: if (entp == NULL) {
217: snprintf(buf, sizeof(buf), "No entry for %s",
218: CVS_FILE_NAME(cfp));
219: } else {
220: snprintf(buf, sizeof(buf), "%s %s",
221: rcsnum_tostr(entp->ce_rev, buf, sizeof(buf)),
222: "date here");
223: }
1.15 jfb 224:
1.16 jfb 225: cvs_printf(" Working revision: %s\n", buf);
226: rcsnum_tostr(rf->rf_head, buf, sizeof(buf));
227: cvs_printf(" Repository revision: %s %s\n", buf, rcspath);
1.15 jfb 228: cvs_printf(" Sticky Tag: %s\n", "(none)");
229: cvs_printf(" Sticky Date: %s\n", "(none)");
230: cvs_printf(" Sticky Options: %s\n", "(none)");
231:
232: rcs_close(rf);
233:
1.5 jfb 234: if (entp != NULL)
235: cvs_ent_free(entp);
1.15 jfb 236: return (0);
1.1 jfb 237: }