Annotation of src/usr.bin/cvs/status.c, Revision 1.19
1.19 ! jfb 1: /* $OpenBSD: status.c,v 1.18 2005/04/16 20:31:18 xsa 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 cvsroot *root;
120:
1.5 jfb 121: ret = 0;
1.1 jfb 122: rf = NULL;
1.5 jfb 123: root = CVS_DIR_ROOT(cfp);
124: repo = CVS_DIR_REPO(cfp);
1.1 jfb 125:
1.6 jfb 126: if (cfp->cf_type == DT_DIR) {
1.15 jfb 127: if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
128: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
129: CVS_FILE_NAME(cfp));
130: else
131: ret = cvs_senddir(root, cfp);
1.6 jfb 132: return (ret);
133: }
1.1 jfb 134:
1.5 jfb 135: cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.1 jfb 136:
1.19 ! jfb 137: if (cvs_sendentry(root, cfp) < 0) {
1.15 jfb 138: return (-1);
139: }
140:
141: switch (cfp->cf_cvstat) {
142: case CVS_FST_UNKNOWN:
143: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
144: CVS_FILE_NAME(cfp));
145: break;
146: case CVS_FST_UPTODATE:
147: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
148: CVS_FILE_NAME(cfp));
149: break;
1.17 joris 150: case CVS_FST_ADDED:
1.15 jfb 151: case CVS_FST_MODIFIED:
152: ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
153: CVS_FILE_NAME(cfp));
154: if (ret == 0)
155: ret = cvs_sendfile(root, fpath);
156: default:
157: break;
158: }
159:
160: return (ret);
161: }
162:
163: int
164: cvs_status_local(CVSFILE *cfp, void *arg)
165: {
1.18 xsa 166: int l;
1.16 jfb 167: char *repo, buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.15 jfb 168: RCSFILE *rf;
169: struct cvs_ent *entp;
170: struct cvsroot *root;
171:
172: if (cfp->cf_type == DT_DIR)
173: return (0);
174:
175: root = CVS_DIR_ROOT(cfp);
176: repo = CVS_DIR_REPO(cfp);
1.1 jfb 177:
1.15 jfb 178: cvs_file_getpath(cfp, fpath, sizeof(fpath));
179: entp = cvs_ent_getent(fpath);
1.1 jfb 180:
1.15 jfb 181: if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
182: cvs_log(LP_WARN, "I know nothing about %s", fpath);
183: return (0);
184: }
1.1 jfb 185:
1.18 xsa 186: l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.15 jfb 187: root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.18 xsa 188: if (l == -1 || l >= (int)sizeof(rcspath)) {
189: errno = ENAMETOOLONG;
190: cvs_log(LP_ERRNO, "%s", rcspath);
191:
192: cvs_ent_free(entp);
193: return (-1);
194: }
1.1 jfb 195:
1.15 jfb 196: rf = rcs_open(rcspath, RCS_READ);
197: if (rf == NULL) {
198: if (entp != NULL)
199: cvs_ent_free(entp);
200: return (-1);
1.1 jfb 201: }
1.5 jfb 202:
1.16 jfb 203: buf[0] = '\0';
204: if (cfp->cf_cvstat == CVS_FST_LOST)
205: strlcpy(buf, "No file ", sizeof(buf));
206: strlcat(buf, CVS_FILE_NAME(cfp), sizeof(buf));
207:
1.15 jfb 208: cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
1.16 jfb 209: buf, cvs_statstr[cfp->cf_cvstat]);
210:
211: if (entp == NULL) {
212: snprintf(buf, sizeof(buf), "No entry for %s",
213: CVS_FILE_NAME(cfp));
214: } else {
215: snprintf(buf, sizeof(buf), "%s %s",
216: rcsnum_tostr(entp->ce_rev, buf, sizeof(buf)),
217: "date here");
218: }
1.15 jfb 219:
1.16 jfb 220: cvs_printf(" Working revision: %s\n", buf);
221: rcsnum_tostr(rf->rf_head, buf, sizeof(buf));
222: cvs_printf(" Repository revision: %s %s\n", buf, rcspath);
1.15 jfb 223: cvs_printf(" Sticky Tag: %s\n", "(none)");
224: cvs_printf(" Sticky Date: %s\n", "(none)");
225: cvs_printf(" Sticky Options: %s\n", "(none)");
226:
227: rcs_close(rf);
228:
1.5 jfb 229: if (entp != NULL)
230: cvs_ent_free(entp);
1.15 jfb 231: return (0);
1.1 jfb 232: }