[BACK]Return to add.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/add.c, Revision 1.9

1.9     ! jfb         1: /*     $OpenBSD: add.c,v 1.8 2004/12/07 17:10:56 tedu 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 <unistd.h>
                     33: #include <string.h>
                     34: #include <sysexits.h>
                     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:
                     45: int  cvs_add_file (CVSFILE *, void *);
                     46:
                     47:
1.1       jfb        48:
                     49: /*
                     50:  * cvs_add()
                     51:  *
                     52:  * Handler for the `cvs add' command.
                     53:  * Returns 0 on success, or one of the known system exit codes on failure.
                     54:  */
                     55: int
                     56: cvs_add(int argc, char **argv)
                     57: {
1.4       jfb        58:        int i, ch;
1.1       jfb        59:        char *kflag, *msg;
1.2       jfb        60:        struct cvsroot *root;
1.1       jfb        61:
                     62:        kflag = NULL;
                     63:
                     64:        while ((ch = getopt(argc, argv, "k:m:")) != -1) {
                     65:                switch (ch) {
                     66:                case 'k':
                     67:                        kflag = optarg;
                     68:                        break;
                     69:                case 'm':
                     70:                        msg = optarg;
                     71:                        break;
                     72:                default:
                     73:                        return (EX_USAGE);
                     74:                }
                     75:        }
                     76:
                     77:        argc -= optind;
                     78:        argv += optind;
                     79:
1.3       jfb        80:        if (argc == 0)
1.1       jfb        81:                return (EX_USAGE);
1.3       jfb        82:
                     83:        cvs_files = cvs_file_getspec(argv, argc, 0);
                     84:        if (cvs_files == NULL)
                     85:                return (EX_DATAERR);
                     86:
                     87:        cvs_file_examine(cvs_files, cvs_add_file, NULL);
                     88:
                     89:        root = CVS_DIR_ROOT(cvs_files);
                     90:
                     91:        for (i = 0; i < argc; i++)
                     92:                cvs_sendarg(root, argv[i], 0);
                     93:        if (cvs_sendreq(root, CVS_REQ_ADD, NULL) < 0)
                     94:                return (-1);
                     95:
                     96:        return (0);
                     97: }
                     98:
                     99:
                    100: int
                    101: cvs_add_file(CVSFILE *cf, void *arg)
                    102: {
                    103:        struct cvsroot *root;
                    104:
                    105:        if (cf->cf_type == DT_DIR) {
1.9     ! jfb       106:                if (cf->cf_cvstat != CVS_FST_UNKNOWN) {
1.3       jfb       107:                        root = cf->cf_ddat->cd_root;
                    108:                        if ((cf->cf_parent == NULL) ||
                    109:                            (root != cf->cf_parent->cf_ddat->cd_root)) {
                    110:                                cvs_connect(root);
                    111:                        }
                    112:
                    113:                        cvs_senddir(root, cf);
                    114:                }
                    115:
                    116:                return (0);
1.1       jfb       117:        }
                    118:
1.3       jfb       119:        root = CVS_DIR_ROOT(cf);
1.2       jfb       120:
1.5       krapht    121:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.6       jfb       122:                cvs_sendreq(root, CVS_REQ_ISMODIFIED, CVS_FILE_NAME(cf));
1.7       deraadt   123:        } else {
1.3       jfb       124:                cvs_log(LP_INFO, "scheduling file `%s' for addition",
                    125:                    cf->cf_name);
                    126:                cvs_log(LP_INFO, "use `%s commit' to add this file permanently",
                    127:                    __progname);
1.1       jfb       128:        }
                    129:
                    130:        return (0);
                    131: }