Annotation of src/usr.bin/cvs/status.c, Revision 1.13
1.13 ! joris 1: /* $OpenBSD: status.c,v 1.12 2005/04/11 17:56:27 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:
42: const char *cvs_statstr[] = {
43: "Unknown",
44: "Up to date",
45: "Locally Modified",
46: "Added",
47: "Removed",
48: "Conflict",
49: "Patched",
50: };
51:
52:
1.10 joris 53: int cvs_status_file(CVSFILE *, void *);
54: int cvs_status_options(char *, int, char **, int *);
55: int cvs_status_sendflags(struct cvsroot *);
56:
57: struct cvs_cmd_info cvs_status = {
58: cvs_status_options,
59: cvs_status_sendflags,
60: cvs_status_file,
61: NULL, NULL,
62: CF_SORT | CF_IGNORE | CF_RECURSE,
63: CVS_REQ_STATUS,
64: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
65: };
1.1 jfb 66:
1.10 joris 67: static int verbose = 0;
1.1 jfb 68:
69: int
1.10 joris 70: cvs_status_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 71: {
1.10 joris 72: int ch;
1.1 jfb 73:
1.10 joris 74: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 75: switch (ch) {
1.7 jfb 76: case 'l':
1.10 joris 77: cvs_status.file_flags &= ~CF_RECURSE;
1.7 jfb 78: break;
79: case 'R':
1.10 joris 80: cvs_status.file_flags |= CF_RECURSE;
1.7 jfb 81: break;
82: case 'v':
83: verbose = 1;
84: break;
1.1 jfb 85: default:
1.12 joris 86: return (1);
1.1 jfb 87: }
88: }
89:
1.10 joris 90: *arg = optind;
91: return (0);
92: }
1.1 jfb 93:
1.10 joris 94: int
95: cvs_status_sendflags(struct cvsroot *root)
96: {
97: if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
1.11 xsa 98: return (-1);
1.1 jfb 99: return (0);
100: }
101:
102: /*
103: * cvs_status_file()
104: *
105: * Get the status of a single file.
106: */
107: int
1.2 jfb 108: cvs_status_file(CVSFILE *cfp, void *arg)
1.1 jfb 109: {
1.5 jfb 110: int ret;
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.5 jfb 116: ret = 0;
1.1 jfb 117: rf = NULL;
1.5 jfb 118: root = CVS_DIR_ROOT(cfp);
119: repo = CVS_DIR_REPO(cfp);
1.1 jfb 120:
1.6 jfb 121: if (cfp->cf_type == DT_DIR) {
122: if (root->cr_method != CVS_METHOD_LOCAL) {
123: if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
124: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
125: CVS_FILE_NAME(cfp));
126: else
127: ret = cvs_senddir(root, cfp);
128: }
129:
130: return (ret);
131: }
1.1 jfb 132:
1.5 jfb 133: cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.2 jfb 134: entp = cvs_ent_getent(fpath);
1.1 jfb 135:
136: if (root->cr_method != CVS_METHOD_LOCAL) {
1.5 jfb 137: if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
1.1 jfb 138: cvs_ent_free(entp);
139: return (-1);
140: }
141:
1.5 jfb 142: switch (cfp->cf_cvstat) {
143: case CVS_FST_UNKNOWN:
144: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
145: CVS_FILE_NAME(cfp));
146: break;
147: case CVS_FST_UPTODATE:
148: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
149: CVS_FILE_NAME(cfp));
150: break;
151: case CVS_FST_MODIFIED:
152: ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
1.2 jfb 153: CVS_FILE_NAME(cfp));
1.5 jfb 154: if (ret == 0)
155: ret = cvs_sendfile(root, fpath);
156: default:
157: break;
158: }
159: } else {
160: if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
161: cvs_log(LP_WARN, "I know nothing about %s", fpath);
162: return (0);
163: }
1.1 jfb 164:
165: snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.2 jfb 166: root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.1 jfb 167:
1.8 jfb 168: rf = rcs_open(rcspath, RCS_READ);
1.1 jfb 169: if (rf == NULL) {
1.9 tedu 170: if (entp != NULL)
171: cvs_ent_free(entp);
1.1 jfb 172: return (-1);
173: }
174:
175: rcs_close(rf);
176: }
1.5 jfb 177:
178: if (entp != NULL)
179: cvs_ent_free(entp);
180: return (ret);
1.1 jfb 181: }