Annotation of src/usr.bin/cvs/add.c, Revision 1.24
1.24 ! joris 1: /* $OpenBSD: add.c,v 1.23 2005/07/10 21:55:30 joris 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>
1.10 xsa 33: #include <unistd.h>
1.1 jfb 34:
35: #include "cvs.h"
36: #include "log.h"
1.2 jfb 37: #include "proto.h"
1.1 jfb 38:
39:
1.3 jfb 40: extern char *__progname;
41:
42:
1.22 joris 43: static int cvs_add_remote(CVSFILE *, void *);
44: static int cvs_add_local(CVSFILE *, void *);
1.21 jfb 45: static int cvs_add_init(struct cvs_cmd *, int, char **, int *);
46: static int cvs_add_pre_exec(struct cvsroot *);
47:
48: struct cvs_cmd cvs_cmd_add = {
49: CVS_OP_ADD, CVS_REQ_ADD, "add",
50: { "ad", "new" },
51: "Add a new file/directory to the repository",
52: "[-k mode] [-m msg] file ...",
53: "k:m:",
54: NULL,
55: 0,
56: cvs_add_init,
57: cvs_add_pre_exec,
1.22 joris 58: cvs_add_remote,
59: cvs_add_local,
1.21 jfb 60: NULL,
61: NULL,
1.15 joris 62: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
63: };
1.3 jfb 64:
1.15 joris 65: static int kflag = RCS_KWEXP_DEFAULT;
66: static char *koptstr;
1.3 jfb 67:
1.21 jfb 68: static int
69: cvs_add_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1 jfb 70: {
1.15 joris 71: int ch;
1.1 jfb 72:
1.13 jfb 73: cvs_msg = NULL;
1.1 jfb 74:
1.21 jfb 75: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1 jfb 76: switch (ch) {
77: case 'k':
1.13 jfb 78: koptstr = optarg;
79: kflag = rcs_kflag_get(koptstr);
80: if (RCS_KWEXP_INVAL(kflag)) {
81: cvs_log(LP_ERR,
82: "invalid RCS keyword expansion mode");
83: rcs_kflag_usage();
1.19 joris 84: return (CVS_EX_USAGE);
1.13 jfb 85: }
1.1 jfb 86: break;
87: case 'm':
1.13 jfb 88: if ((cvs_msg = strdup(optarg)) == NULL) {
89: cvs_log(LP_ERRNO, "failed to copy message");
1.19 joris 90: return (CVS_EX_DATA);
1.13 jfb 91: }
1.1 jfb 92: break;
93: default:
1.19 joris 94: return (CVS_EX_USAGE);
1.1 jfb 95: }
96: }
97:
1.15 joris 98: *arg = optind;
99: return (0);
100: }
1.10 xsa 101:
1.21 jfb 102: static int
103: cvs_add_pre_exec(struct cvsroot *root)
1.15 joris 104: {
105: char buf[16];
1.3 jfb 106:
1.21 jfb 107: if ((root->cr_method != CVS_METHOD_LOCAL) &&
108: (kflag != RCS_KWEXP_DEFAULT)) {
1.15 joris 109: strlcpy(buf, "-k", sizeof(buf));
110: strlcat(buf, koptstr, sizeof(buf));
111: if (cvs_sendarg(root, buf, 0) < 0)
1.19 joris 112: return (CVS_EX_PROTO);
1.10 xsa 113: }
1.3 jfb 114:
115: return (0);
116: }
117:
1.21 jfb 118: static int
1.22 joris 119: cvs_add_remote(CVSFILE *cf, void *arg)
1.3 jfb 120: {
1.10 xsa 121: int ret;
1.3 jfb 122: struct cvsroot *root;
123:
1.10 xsa 124: ret = 0;
125: root = CVS_DIR_ROOT(cf);
126:
1.3 jfb 127: if (cf->cf_type == DT_DIR) {
1.22 joris 128: ret = cvs_senddir(root, cf);
1.20 joris 129: if (ret == -1)
130: ret = CVS_EX_PROTO;
1.10 xsa 131: return (ret);
1.1 jfb 132: }
133:
1.24 ! joris 134: if (cf->cf_cvstat == CVS_FST_ADDED)
1.22 joris 135: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
1.21 jfb 136: cf->cf_name);
1.23 joris 137:
138: if (ret == -1)
139: ret = CVS_EX_PROTO;
1.1 jfb 140:
1.10 xsa 141: return (ret);
1.22 joris 142: }
143:
144: static
145: int cvs_add_local(CVSFILE *cf, void *arg)
146: {
147: cvs_log(LP_INFO, "scheduling file `%s' for addition", cf->cf_name);
148: cvs_log(LP_INFO, "use `%s commit' to add this file permanently",
149: __progname);
150:
151: return (0);
1.1 jfb 152: }