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

Annotation of src/usr.bin/cvs/import.c, Revision 1.8

1.8     ! xsa         1: /*     $OpenBSD: import.c,v 1.7 2005/03/30 17:43:04 joris Exp $        */
1.1       krapht      2: /*
1.5       joris       3:  * Copyright (c) 2004 Joris Vink <joris@openbsd.org>
1.1       krapht      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/types.h>
                     28: #include <sys/queue.h>
                     29:
                     30: #include <err.h>
                     31: #include <dirent.h>
                     32: #include <errno.h>
                     33: #include <stdio.h>
                     34: #include <stdlib.h>
                     35: #include <unistd.h>
                     36: #include <string.h>
                     37: #include <sysexits.h>
                     38:
                     39: #include "log.h"
                     40: #include "file.h"
1.3       jfb        41: #include "cvs.h"
1.1       krapht     42: #include "proto.h"
                     43:
1.3       jfb        44:
                     45: #define CVS_IMPORT_DEFBRANCH    "1.1.1"
                     46:
1.7       joris      47: int cvs_import_options(char *, int, char **, int *);
                     48: int cvs_import_sendflags(struct cvsroot *);
                     49: int cvs_import_file(CVSFILE *, void *);
1.3       jfb        50:
1.7       joris      51: static RCSNUM *bnum;
                     52: static char *branch, *module, *vendor, *release;
1.3       jfb        53:
1.7       joris      54: struct cvs_cmd_info cvs_import = {
                     55:        cvs_import_options,
                     56:        cvs_import_sendflags,
                     57:        cvs_import_file,
                     58:        NULL, NULL,
                     59:        CF_RECURSE | CF_IGNORE | CF_NOSYMS,
                     60:        CVS_REQ_IMPORT,
                     61:        CVS_CMD_SENDDIR
                     62: };
1.1       krapht     63:
                     64: int
1.7       joris      65: cvs_import_options(char *opt, int argc, char **argv, int *arg)
1.1       krapht     66: {
1.7       joris      67:        int ch;
1.1       krapht     68:
1.7       joris      69:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       krapht     70:                switch (ch) {
                     71:                case 'b':
1.3       jfb        72:                        branch = optarg;
1.6       joris      73:                        if ((bnum = rcsnum_parse(branch)) == NULL) {
1.3       jfb        74:                                cvs_log(LP_ERR, "%s is not a numeric branch",
                     75:                                    branch);
                     76:                                return (EX_USAGE);
                     77:                        }
1.6       joris      78:                        rcsnum_free(bnum);
1.3       jfb        79:                        break;
1.1       krapht     80:                case 'd':
                     81:                        break;
                     82:                case 'I':
                     83:                        if (cvs_file_ignore(optarg) < 0) {
                     84:                                cvs_log(LP_ERR, "failed to add `%s' to list "
                     85:                                    "of ignore patterns", optarg);
                     86:                                return (EX_USAGE);
                     87:                        }
                     88:                        break;
                     89:                case 'k':
                     90:                        break;
                     91:                case 'm':
1.4       jfb        92:                        cvs_msg = strdup(optarg);
                     93:                        if (cvs_msg == NULL) {
                     94:                                cvs_log(LP_ERRNO, "failed to copy message");
1.8     ! xsa        95:                                return (-1);
1.4       jfb        96:                        }
1.1       krapht     97:                        break;
                     98:                default:
                     99:                        return (EX_USAGE);
                    100:                }
                    101:        }
                    102:
                    103:        argc -= optind;
                    104:        argv += optind;
1.7       joris     105:        *arg = optind;
                    106:
1.1       krapht    107:        if (argc > 4)
                    108:                return (EX_USAGE);
                    109:
1.7       joris     110:        module = argv[0];
                    111:        vendor = argv[1];
                    112:        release = argv[2];
1.1       krapht    113:
1.3       jfb       114:        if ((cvs_msg == NULL) &&
                    115:            (cvs_msg = cvs_logmsg_get(NULL, NULL, NULL, NULL)) == NULL)
                    116:                return (-1);
1.1       krapht    117:
1.7       joris     118:        return (0);
                    119: }
1.1       krapht    120:
1.7       joris     121: int
                    122: cvs_import_sendflags(struct cvsroot *root)
                    123: {
                    124:        if ((cvs_connect(root) < 0) ||
                    125:            (cvs_sendarg(root, "-b", 0) < 0) ||
                    126:            (cvs_sendarg(root, branch, 0) < 0) ||
                    127:            (cvs_logmsg_send(root, cvs_msg) < 0) ||
                    128:            (cvs_sendarg(root, module, 0) < 0) ||
                    129:            (cvs_sendarg(root, vendor, 0) < 0) ||
                    130:            (cvs_sendarg(root, release, 0) < 0))
1.8     ! xsa       131:                return (-1);
1.1       krapht    132:
                    133:        return (0);
                    134: }
                    135:
1.3       jfb       136: /*
                    137:  * cvs_import_file()
                    138:  *
                    139:  * Perform the import of a single file or directory.
                    140:  */
                    141: int
                    142: cvs_import_file(CVSFILE *cfp, void *arg)
1.1       krapht    143: {
1.3       jfb       144:        int ret;
                    145:        struct cvsroot *root;
                    146:        char fpath[MAXPATHLEN], repodir[MAXPATHLEN];
1.7       joris     147:        char repo[MAXPATHLEN];
1.1       krapht    148:
1.3       jfb       149:        root = CVS_DIR_ROOT(cfp);
1.7       joris     150:        snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, module);
1.1       krapht    151:
1.3       jfb       152:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
                    153:        printf("Importing %s\n", fpath);
1.1       krapht    154:
1.3       jfb       155:        if (cfp->cf_type == DT_DIR) {
                    156:                if (!strcmp(CVS_FILE_NAME(cfp), "."))
                    157:                        strlcpy(repodir, repo, sizeof(repodir));
                    158:                else
                    159:                        snprintf(repodir, sizeof(repodir), "%s/%s", repo, fpath);
                    160:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    161:                        ret = cvs_sendreq(root, CVS_REQ_DIRECTORY, fpath);
                    162:                        if (ret == 0)
                    163:                                ret = cvs_sendln(root, repodir);
                    164:                } else {
                    165:                        /* create the directory */
                    166:                }
1.1       krapht    167:
1.3       jfb       168:                return (0);
1.1       krapht    169:        }
                    170:
1.3       jfb       171:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    172:                if (cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cfp)) < 0)
                    173:                        return (-1);
                    174:                if (cvs_sendfile(root, fpath) < 0)
                    175:                        return (-1);
                    176:        } else {
                    177:                /* local import */
1.1       krapht    178:        }
                    179:
                    180:        return (0);
                    181: }