Annotation of src/usr.bin/cvs/update.c, Revision 1.4
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;
64: flags = CF_SORT|CF_RECURSE|CF_IGNORE;
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: cvs_log(LP_DEBUG, "%s: updating %s", __func__, cf->cf_path);
131:
132: if (cf->cf_type == DT_DIR) {
133: root = cf->cf_ddat->cd_root;
134: if ((cf->cf_parent == NULL) ||
135: (root != cf->cf_parent->cf_ddat->cd_root)) {
1.4 ! jfb 136: cvs_connect(root);
1.2 jfb 137: }
138:
1.4 ! jfb 139: cvs_senddir(root, cf);
1.2 jfb 140: return (0);
141: }
142: else
143: root = cf->cf_parent->cf_ddat->cd_root;
144:
145: rf = NULL;
146: if (cf->cf_parent != NULL) {
147: dir = cf->cf_parent->cf_path;
148: repo = cf->cf_parent->cf_ddat->cd_repo;
149: }
150: else {
151: dir = ".";
152: repo = NULL;
153: }
154:
155: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
156: if (root->cr_method == CVS_METHOD_LOCAL)
157: cvs_printf("? %s\n", cf->cf_path);
158: else
1.4 ! jfb 159: cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.2 jfb 160: return (0);
161: }
162:
163: entp = cvs_ent_getent(cf->cf_path);
164: if (entp == NULL)
165: return (-1);
166:
167: if ((root->cr_method != CVS_METHOD_LOCAL) &&
1.4 ! jfb 168: (cvs_sendentry(root, entp) < 0)) {
1.2 jfb 169: cvs_ent_free(entp);
170: return (-1);
171: }
172:
173: if (root->cr_method != CVS_METHOD_LOCAL) {
174: switch (cf->cf_cvstat) {
175: case CVS_FST_UPTODATE:
1.4 ! jfb 176: cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.2 jfb 177: break;
178: case CVS_FST_ADDED:
179: case CVS_FST_MODIFIED:
1.4 ! jfb 180: cvs_sendreq(root, CVS_REQ_MODIFIED, cf->cf_name);
! 181: cvs_sendfile(root, cf->cf_path);
1.2 jfb 182: break;
183: default:
184: return (-1);
185: }
186:
187: cvs_ent_free(entp);
188: return (0);
189: }
190:
191: snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
192: root->cr_dir, repo, cf->cf_path, RCS_FILE_EXT);
193:
194: rf = rcs_open(rcspath, RCS_MODE_READ);
195: if (rf == NULL) {
196: cvs_ent_free(entp);
197: return (-1);
198: }
199:
200: rcs_close(rf);
201: cvs_ent_free(entp);
202: return (0);
203: }
204:
205:
206: /*
207: * cvs_update_prune()
208: *
209: * Prune all directories which contain no more files known to CVS.
210: */
211:
212: int
213: cvs_update_prune(CVSFILE *cf, void *arg)
214: {
1.1 jfb 215:
216: return (0);
217: }