Annotation of src/usr.bin/cvs/status.c, Revision 1.24
1.24 ! joris 1: /* $OpenBSD: status.c,v 1.23 2005/05/31 08:58:48 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>
1.23 xsa 31: #include <fcntl.h>
1.1 jfb 32: #include <stdio.h>
33: #include <stdlib.h>
1.23 xsa 34: #include <string.h>
1.1 jfb 35: #include <unistd.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.22 jfb 58: static int cvs_status_init (struct cvs_cmd *, int, char **, int *);
59: static int cvs_status_remote (CVSFILE *, void *);
60: static int cvs_status_local (CVSFILE *, void *);
61: static int cvs_status_pre_exec (struct cvsroot *);
62:
63: struct cvs_cmd cvs_cmd_status = {
64: CVS_OP_STATUS, CVS_REQ_STATUS, "status",
65: { "st", "stat" },
66: "Display status information on checked out files",
67: "[-lRv]",
68: "lRv",
69: NULL,
70: CF_SORT | CF_IGNORE | CF_RECURSE,
71: cvs_status_init,
72: cvs_status_pre_exec,
1.20 jfb 73: cvs_status_remote,
1.22 jfb 74: cvs_status_local,
75: NULL,
76: NULL,
1.10 joris 77: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
78: };
1.1 jfb 79:
1.10 joris 80: static int verbose = 0;
1.1 jfb 81:
1.22 jfb 82: static int
83: cvs_status_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 84: {
1.10 joris 85: int ch;
1.1 jfb 86:
1.22 jfb 87: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1 jfb 88: switch (ch) {
1.7 jfb 89: case 'l':
1.22 jfb 90: cmd->file_flags &= ~CF_RECURSE;
1.7 jfb 91: break;
92: case 'R':
1.22 jfb 93: cmd->file_flags |= CF_RECURSE;
1.7 jfb 94: break;
95: case 'v':
96: verbose = 1;
97: break;
1.1 jfb 98: default:
1.14 joris 99: return (CVS_EX_USAGE);
1.1 jfb 100: }
101: }
102:
1.10 joris 103: *arg = optind;
104: return (0);
105: }
1.1 jfb 106:
1.22 jfb 107: static int
108: cvs_status_pre_exec(struct cvsroot *root)
1.10 joris 109: {
110: if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
1.14 joris 111: return (CVS_EX_PROTO);
1.1 jfb 112: return (0);
113: }
114:
115: /*
1.20 jfb 116: * cvs_status_remote()
1.1 jfb 117: *
118: * Get the status of a single file.
119: */
1.22 jfb 120: static int
1.20 jfb 121: cvs_status_remote(CVSFILE *cfp, void *arg)
1.1 jfb 122: {
1.5 jfb 123: int ret;
1.15 jfb 124: char *repo, fpath[MAXPATHLEN];
1.1 jfb 125: RCSFILE *rf;
126: struct cvsroot *root;
127:
1.5 jfb 128: ret = 0;
1.1 jfb 129: rf = NULL;
1.5 jfb 130: root = CVS_DIR_ROOT(cfp);
131: repo = CVS_DIR_REPO(cfp);
1.1 jfb 132:
1.6 jfb 133: if (cfp->cf_type == DT_DIR) {
1.15 jfb 134: if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
135: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
136: CVS_FILE_NAME(cfp));
137: else
138: ret = cvs_senddir(root, cfp);
1.21 joris 139:
140: if (ret == -1)
141: ret = CVS_EX_PROTO;
142:
1.6 jfb 143: return (ret);
144: }
1.1 jfb 145:
1.5 jfb 146: cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.1 jfb 147:
1.21 joris 148: if (cvs_sendentry(root, cfp) < 0)
149: return (CVS_EX_PROTO);
1.15 jfb 150:
151: switch (cfp->cf_cvstat) {
152: case CVS_FST_UNKNOWN:
1.20 jfb 153: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cfp->cf_name);
1.15 jfb 154: break;
155: case CVS_FST_UPTODATE:
1.20 jfb 156: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cfp->cf_name);
1.15 jfb 157: break;
1.17 joris 158: case CVS_FST_ADDED:
1.15 jfb 159: case CVS_FST_MODIFIED:
1.20 jfb 160: ret = cvs_sendreq(root, CVS_REQ_MODIFIED, cfp->cf_name);
1.15 jfb 161: if (ret == 0)
162: ret = cvs_sendfile(root, fpath);
163: default:
164: break;
165: }
166:
1.21 joris 167: if (ret == -1)
168: ret = CVS_EX_PROTO;
169:
1.15 jfb 170: return (ret);
171: }
172:
1.22 jfb 173: static int
174: cvs_status_local(CVSFILE *cf, void *arg)
1.15 jfb 175: {
1.22 jfb 176: int len;
1.16 jfb 177: char *repo, buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.15 jfb 178: RCSFILE *rf;
179: struct cvsroot *root;
180:
1.22 jfb 181: if (cf->cf_type == DT_DIR)
1.15 jfb 182: return (0);
183:
1.22 jfb 184: root = CVS_DIR_ROOT(cf);
185: repo = CVS_DIR_REPO(cf);
1.1 jfb 186:
1.22 jfb 187: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1 jfb 188:
1.22 jfb 189: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.15 jfb 190: cvs_log(LP_WARN, "I know nothing about %s", fpath);
191: return (0);
192: }
1.1 jfb 193:
1.22 jfb 194: len = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
195: root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
196: if (len == -1 || len >= (int)sizeof(rcspath)) {
1.18 xsa 197: errno = ENAMETOOLONG;
198: cvs_log(LP_ERRNO, "%s", rcspath);
1.21 joris 199: return (CVS_EX_DATA);
1.18 xsa 200: }
1.1 jfb 201:
1.15 jfb 202: rf = rcs_open(rcspath, RCS_READ);
1.21 joris 203: if (rf == NULL)
204: return (CVS_EX_DATA);
1.5 jfb 205:
1.16 jfb 206: buf[0] = '\0';
1.22 jfb 207: if (cf->cf_cvstat == CVS_FST_LOST)
1.16 jfb 208: strlcpy(buf, "No file ", sizeof(buf));
1.22 jfb 209: strlcat(buf, cf->cf_name, sizeof(buf));
1.16 jfb 210:
1.15 jfb 211: cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
1.22 jfb 212: buf, cvs_statstr[cf->cf_cvstat]);
1.16 jfb 213:
1.22 jfb 214: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
215: snprintf(buf, sizeof(buf), "No entry for %s", cf->cf_name);
1.16 jfb 216: } else {
1.24 ! joris 217: snprintf(buf, sizeof(buf), "%s",
! 218: rcsnum_tostr(cf->cf_lrev, buf, sizeof(buf)));
1.16 jfb 219: }
1.15 jfb 220:
1.16 jfb 221: cvs_printf(" Working revision: %s\n", buf);
222: rcsnum_tostr(rf->rf_head, buf, sizeof(buf));
223: cvs_printf(" Repository revision: %s %s\n", buf, rcspath);
1.22 jfb 224: cvs_printf(" Sticky Tag: %s\n",
225: cf->cf_tag == NULL ? "(none)" : cf->cf_tag);
1.15 jfb 226: cvs_printf(" Sticky Date: %s\n", "(none)");
1.22 jfb 227: cvs_printf(" Sticky Options: %s\n",
228: cf->cf_opts == NULL ? "(none)" : cf->cf_opts);
1.15 jfb 229:
230: rcs_close(rf);
231:
232: return (0);
1.1 jfb 233: }