[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.10

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