Annotation of src/usr.bin/cvs/add.c, Revision 1.12
1.12 ! jfb 1: /* $OpenBSD: add.c,v 1.11 2004/12/21 17:50:40 jfb Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.8 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.8 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.8 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.8 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.8 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/types.h>
28:
29: #include <errno.h>
30: #include <stdio.h>
31: #include <stdlib.h>
32: #include <string.h>
33: #include <sysexits.h>
1.10 xsa 34: #include <unistd.h>
1.1 jfb 35:
36: #include "cvs.h"
37: #include "log.h"
1.2 jfb 38: #include "proto.h"
1.1 jfb 39:
40:
1.3 jfb 41: extern char *__progname;
42:
43:
44: int cvs_add_file (CVSFILE *, void *);
45:
46:
1.1 jfb 47: /*
48: * cvs_add()
49: *
50: * Handler for the `cvs add' command.
51: * Returns 0 on success, or one of the known system exit codes on failure.
52: */
53: int
54: cvs_add(int argc, char **argv)
55: {
1.4 jfb 56: int i, ch;
1.1 jfb 57: char *kflag, *msg;
1.2 jfb 58: struct cvsroot *root;
1.1 jfb 59:
1.10 xsa 60: kflag = msg = NULL;
1.1 jfb 61:
62: while ((ch = getopt(argc, argv, "k:m:")) != -1) {
63: switch (ch) {
64: case 'k':
65: kflag = optarg;
66: break;
67: case 'm':
68: msg = optarg;
69: break;
70: default:
71: return (EX_USAGE);
72: }
73: }
74:
75: argc -= optind;
76: argv += optind;
77:
1.3 jfb 78: if (argc == 0)
1.1 jfb 79: return (EX_USAGE);
1.3 jfb 80:
81: cvs_files = cvs_file_getspec(argv, argc, 0);
82: if (cvs_files == NULL)
83: return (EX_DATAERR);
84:
1.10 xsa 85: root = CVS_DIR_ROOT(cvs_files);
1.11 jfb 86: if (root == NULL) {
87: cvs_log(LP_ERR,
88: "No CVSROOT specified! Please use the `-d' option");
89: cvs_log(LP_ERR,
90: "or set the CVSROOT environment variable.");
91: return (EX_USAGE);
92: }
1.10 xsa 93: if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
94: return (EX_PROTOCOL);
95:
1.3 jfb 96: cvs_file_examine(cvs_files, cvs_add_file, NULL);
97:
1.10 xsa 98: if (root->cr_method != CVS_METHOD_LOCAL) {
99: if (cvs_senddir(root, cvs_files) < 0)
100: return (EX_PROTOCOL);
101:
102: for (i = 0; i < argc; i++)
103: if (cvs_sendarg(root, argv[i], 0) < 0)
104: return (EX_PROTOCOL);
1.3 jfb 105:
1.10 xsa 106: if (cvs_sendreq(root, CVS_REQ_ADD, NULL) < 0)
107: return (EX_PROTOCOL);
108: }
1.3 jfb 109:
110: return (0);
111: }
112:
113:
114: int
115: cvs_add_file(CVSFILE *cf, void *arg)
116: {
1.10 xsa 117: int ret;
1.3 jfb 118: struct cvsroot *root;
119:
1.10 xsa 120: ret = 0;
121: root = CVS_DIR_ROOT(cf);
122:
1.3 jfb 123: if (cf->cf_type == DT_DIR) {
1.12 ! jfb 124: if (root->cr_method != CVS_METHOD_LOCAL)
! 125: ret = cvs_senddir(root, cf);
1.3 jfb 126:
1.10 xsa 127: return (ret);
1.1 jfb 128: }
129:
1.5 krapht 130: if (root->cr_method != CVS_METHOD_LOCAL) {
1.12 ! jfb 131: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
! 132: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
! 133: CVS_FILE_NAME(cf));
1.7 deraadt 134: } else {
1.3 jfb 135: cvs_log(LP_INFO, "scheduling file `%s' for addition",
1.10 xsa 136: CVS_FILE_NAME(cf));
1.3 jfb 137: cvs_log(LP_INFO, "use `%s commit' to add this file permanently",
138: __progname);
1.1 jfb 139: }
140:
1.10 xsa 141: return (ret);
1.1 jfb 142: }