Annotation of src/usr.bin/cvs/update.c, Revision 1.6
1.1 jfb 1: /* $OpenBSD$ */
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/param.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 "rcs.h"
40: #include "log.h"
1.4 jfb 41: #include "proto.h"
1.1 jfb 42:
43:
1.2 jfb 44: int cvs_update_file (CVSFILE *, void *);
45: int cvs_update_prune (CVSFILE *, void *);
46:
47:
48:
49:
1.1 jfb 50: /*
51: * cvs_update()
52: *
53: * Handle the `cvs update' command.
1.2 jfb 54: * Returns 0 on success, or the appropriate exit code on error.
1.1 jfb 55: */
56:
57: int
58: cvs_update(int argc, char **argv)
59: {
1.2 jfb 60: int ch, i, flags;
61: struct cvs_file *cf;
62:
63: cf = NULL;
1.6 ! jfb 64: flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_KNOWN;
1.1 jfb 65:
66: while ((ch = getopt(argc, argv, "ACD:dflPpQqRr:")) != -1) {
67: switch (ch) {
68: case 'A':
69: case 'C':
70: case 'D':
71: case 'd':
72: case 'f':
1.2 jfb 73: break;
1.1 jfb 74: case 'l':
1.2 jfb 75: flags &= ~CF_RECURSE;
76: break;
1.1 jfb 77: case 'P':
78: case 'p':
79: case 'Q':
80: case 'q':
1.2 jfb 81: break;
1.1 jfb 82: case 'R':
1.2 jfb 83: flags |= CF_RECURSE;
84: break;
1.1 jfb 85: case 'r':
86: break;
87: default:
88: return (EX_USAGE);
89: }
90: }
91:
92: argc -= optind;
93: argv += optind;
1.2 jfb 94:
95: if (argc == 0) {
96: cf = cvs_file_get(".", flags);
97: }
98: else {
99: /* don't perform ignore on explicitly listed files */
100: flags &= ~CF_IGNORE;
101:
102: for (i = 0; i < argc; i++) {
103: cf = cvs_file_get(argv[i], flags);
104: }
105: }
106:
107: cvs_file_examine(cf, cvs_update_file, NULL);
108:
1.4 jfb 109: cvs_senddir(cf->cf_ddat->cd_root, cf);
110: cvs_sendreq(cf->cf_ddat->cd_root, CVS_REQ_UPDATE, NULL);
1.2 jfb 111:
112: return (0);
113: }
114:
115:
116: /*
117: * cvs_update_file()
118: *
119: * Diff a single file.
120: */
121:
122: int
123: cvs_update_file(CVSFILE *cf, void *arg)
124: {
125: char *dir, *repo, rcspath[MAXPATHLEN];
126: RCSFILE *rf;
127: struct cvsroot *root;
128: struct cvs_ent *entp;
129:
130: if (cf->cf_type == DT_DIR) {
1.6 ! jfb 131: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
! 132: root = cf->cf_parent->cf_ddat->cd_root;
! 133: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
! 134: }
! 135: else {
! 136: root = cf->cf_ddat->cd_root;
! 137: if ((cf->cf_parent == NULL) ||
! 138: (root != cf->cf_parent->cf_ddat->cd_root)) {
! 139: cvs_connect(root);
! 140: }
! 141:
! 142: cvs_senddir(root, cf);
1.2 jfb 143: }
144:
145: return (0);
146: }
147: else
148: root = cf->cf_parent->cf_ddat->cd_root;
149:
150: rf = NULL;
151: if (cf->cf_parent != NULL) {
152: dir = cf->cf_parent->cf_path;
153: repo = cf->cf_parent->cf_ddat->cd_repo;
154: }
155: else {
156: dir = ".";
157: repo = NULL;
158: }
159:
160: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
161: if (root->cr_method == CVS_METHOD_LOCAL)
162: cvs_printf("? %s\n", cf->cf_path);
163: else
1.4 jfb 164: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.2 jfb 165: return (0);
166: }
167:
168: entp = cvs_ent_getent(cf->cf_path);
169: if (entp == NULL)
170: return (-1);
171:
172: if ((root->cr_method != CVS_METHOD_LOCAL) &&
1.4 jfb 173: (cvs_sendentry(root, entp) < 0)) {
1.2 jfb 174: cvs_ent_free(entp);
175: return (-1);
176: }
177:
178: if (root->cr_method != CVS_METHOD_LOCAL) {
179: switch (cf->cf_cvstat) {
180: case CVS_FST_UPTODATE:
1.4 jfb 181: cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.2 jfb 182: break;
183: case CVS_FST_ADDED:
184: case CVS_FST_MODIFIED:
1.4 jfb 185: cvs_sendreq(root, CVS_REQ_MODIFIED, cf->cf_name);
186: cvs_sendfile(root, cf->cf_path);
1.2 jfb 187: break;
188: default:
189: return (-1);
190: }
191:
192: cvs_ent_free(entp);
193: return (0);
194: }
195:
196: snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
197: root->cr_dir, repo, cf->cf_path, RCS_FILE_EXT);
198:
199: rf = rcs_open(rcspath, RCS_MODE_READ);
200: if (rf == NULL) {
201: cvs_ent_free(entp);
202: return (-1);
203: }
204:
205: rcs_close(rf);
206: cvs_ent_free(entp);
207: return (0);
208: }
209:
210:
211: /*
212: * cvs_update_prune()
213: *
214: * Prune all directories which contain no more files known to CVS.
215: */
216:
217: int
218: cvs_update_prune(CVSFILE *cf, void *arg)
219: {
1.1 jfb 220:
221: return (0);
222: }