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