Annotation of src/usr.bin/cvs/status.c, Revision 1.3
1.3 ! deraadt 1: /* $OpenBSD: status.c,v 1.2 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/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: #include <sysexits.h>
37:
38: #include "cvs.h"
39: #include "log.h"
40: #include "proto.h"
41:
42:
43: const char *cvs_statstr[] = {
44: "Unknown",
45: "Up to date",
46: "Locally Modified",
47: "Added",
48: "Removed",
49: "Conflict",
50: "Patched",
51: };
52:
53:
54: int cvs_status_file (CVSFILE *, void *);
55:
56:
57:
58:
59: /*
60: * cvs_status()
61: *
62: * Handler for the `cvs status' command.
63: * Returns 0 on success, or one of the known exit codes on error.
64: */
65:
66: int
67: cvs_status(int argc, char **argv)
68: {
69: int i, ch, flags;
70: struct cvs_file *cf;
71:
72: cf = NULL;
73: flags = CF_SORT|CF_IGNORE|CF_RECURSE;
74:
75: while ((ch = getopt(argc, argv, "F:flm:Rr:")) != -1) {
76: switch (ch) {
77: default:
78: return (EX_USAGE);
79: }
80: }
81:
82: argc -= optind;
83: argv += optind;
84:
85: if (argc == 0) {
86: cf = cvs_file_get(".", flags);
87: if (cf == NULL) {
88: return (EX_DATAERR);
89: }
90:
91: cvs_file_examine(cf, cvs_status_file, NULL);
1.3 ! deraadt 92: } else {
1.1 jfb 93: for (i = 0; i < argc; i++) {
94: cf = cvs_file_get(argv[i], flags);
95: }
96: }
97:
98: return (0);
99: }
100:
101:
102: /*
103: * cvs_status_file()
104: *
105: * Get the status of a single file.
106: */
107:
108: int
1.2 jfb 109: cvs_status_file(CVSFILE *cfp, void *arg)
1.1 jfb 110: {
1.2 jfb 111: char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.1 jfb 112: RCSFILE *rf;
113: struct cvs_ent *entp;
114: struct cvsroot *root;
115:
1.2 jfb 116: cvs_file_getpath(cfp, fpath, sizeof(fpath));
117: cvs_log(LP_DEBUG, "%s: getting status for %s", __func__, fpath);
1.1 jfb 118:
119: if (cfp->cf_type == DT_DIR) {
120: root = cfp->cf_ddat->cd_root;
121: if ((cfp->cf_parent == NULL) ||
122: (root != cfp->cf_parent->cf_ddat->cd_root)) {
123: cvs_connect(root);
124: }
125:
126: cvs_senddir(root, cfp);
127: return (0);
1.3 ! deraadt 128: } else
1.1 jfb 129: root = cfp->cf_parent->cf_ddat->cd_root;
130:
131: rf = NULL;
132: if (cfp->cf_parent != NULL) {
133: repo = cfp->cf_parent->cf_ddat->cd_repo;
1.3 ! deraadt 134: } else {
1.1 jfb 135: repo = NULL;
136: }
137:
138: if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
139: if (root->cr_method == CVS_METHOD_LOCAL)
1.2 jfb 140: cvs_log(LP_WARN, "I know nothing about %s", fpath);
1.1 jfb 141: else
1.2 jfb 142: cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
143: CVS_FILE_NAME(cfp));
1.1 jfb 144: return (0);
145: }
146:
1.2 jfb 147: entp = cvs_ent_getent(fpath);
1.1 jfb 148: if (entp == NULL)
149: return (-1);
150:
151: if (root->cr_method != CVS_METHOD_LOCAL) {
152: if (cvs_sendentry(root, entp) < 0) {
153: cvs_ent_free(entp);
154: return (-1);
155: }
156: }
157:
158: if (cfp->cf_cvstat == CVS_FST_UPTODATE) {
159: if (root->cr_method != CVS_METHOD_LOCAL)
1.2 jfb 160: cvs_sendreq(root, CVS_REQ_UNCHANGED,
161: CVS_FILE_NAME(cfp));
1.1 jfb 162: cvs_ent_free(entp);
163: return (0);
164: }
165:
166: /* at this point, the file is modified */
167: if (root->cr_method != CVS_METHOD_LOCAL) {
1.2 jfb 168: cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cfp));
169: cvs_sendfile(root, fpath);
1.3 ! deraadt 170: } else {
1.1 jfb 171: snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.2 jfb 172: root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.1 jfb 173:
174: rf = rcs_open(rcspath, RCS_MODE_READ);
175: if (rf == NULL) {
176: cvs_ent_free(entp);
177: return (-1);
178: }
179:
180: rcs_close(rf);
181: }
182: cvs_ent_free(entp);
183: return (0);
184: }