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

Annotation of src/usr.bin/cvs/checkout.c, Revision 1.22

1.22    ! jfb         1: /*     $OpenBSD: checkout.c,v 1.21 2005/05/23 17:30:35 xsa Exp $       */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.11      tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.11      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.11      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.11      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.11      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:
                     35: #include "cvs.h"
                     36: #include "log.h"
1.6       jfb        37: #include "file.h"
1.5       jfb        38: #include "proto.h"
1.1       jfb        39:
                     40:
1.13      jfb        41: #define CVS_LISTMOD    1
                     42: #define CVS_STATMOD    2
                     43:
1.22    ! jfb        44: static int cvs_checkout_init     (struct cvs_cmd *, int, char **, int *);
        !            45: static int cvs_checkout_pre_exec (struct cvsroot *);
1.14      joris      46:
1.22    ! jfb        47: struct cvs_cmd cvs_cmd_checkout = {
        !            48:        CVS_OP_CHECKOUT, CVS_REQ_CO, "checkout",
        !            49:        { "co", "get" },
        !            50:        "Checkout sources for editing",
        !            51:        "[-AcflNnPpRs] [-D date | -r rev] [-d dir] [-j rev] [-k mode] "
        !            52:        "[-t id] module ...",
        !            53:        "AcD:d:fj:k:lNnPRr:st:",
        !            54:        NULL,
1.14      joris      55:        0,
1.22    ! jfb        56:        cvs_checkout_init,
        !            57:        cvs_checkout_pre_exec,
        !            58:        NULL,
        !            59:        NULL,
        !            60:        NULL,
        !            61:        NULL,
        !            62:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
1.14      joris      63: };
                     64:
                     65: static char *date, *rev, *koptstr, *tgtdir, *rcsid;
                     66: static int statmod = 0;
1.22    ! jfb        67: static int shorten = 1;
        !            68: static int usehead = 0;
1.14      joris      69: static int kflag = RCS_KWEXP_DEFAULT;
1.1       jfb        70:
1.22    ! jfb        71: /* modules */
        !            72: static char **co_mods;
        !            73: static int    co_nmod;
        !            74:
        !            75: static int
        !            76: cvs_checkout_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        77: {
1.14      joris      78:        int ch;
                     79:
                     80:        date = rev = koptstr = tgtdir = rcsid = NULL;
1.13      jfb        81:
1.22    ! jfb        82:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1       jfb        83:                switch (ch) {
1.13      jfb        84:                case 'A':
                     85:                        break;
1.10      jfb        86:                case 'c':
1.13      jfb        87:                        statmod = CVS_LISTMOD;
                     88:                        break;
                     89:                case 'D':
                     90:                        date = optarg;
                     91:                        break;
                     92:                case 'd':
                     93:                        tgtdir = optarg;
                     94:                        break;
                     95:                case 'f':
1.21      xsa        96:                        usehead = 1;
1.13      jfb        97:                        break;
                     98:                case 'j':
                     99:                        break;
                    100:                case 'k':
                    101:                        koptstr = optarg;
                    102:                        kflag = rcs_kflag_get(koptstr);
                    103:                        if (RCS_KWEXP_INVAL(kflag)) {
                    104:                                cvs_log(LP_ERR,
                    105:                                    "invalid RCS keyword expansion mode");
                    106:                                rcs_kflag_usage();
1.18      joris     107:                                return (CVS_EX_USAGE);
1.13      jfb       108:                        }
1.20      xsa       109:                        break;
1.22    ! jfb       110:                case 'N':
        !           111:                        shorten = 0;
        !           112:                        break;
1.20      xsa       113:                case 'p':
                    114:                        cvs_noexec = 1; /* no locks will be created */
1.13      jfb       115:                        break;
                    116:                case 'r':
                    117:                        rev = optarg;
                    118:                        break;
                    119:                case 's':
                    120:                        statmod = CVS_STATMOD;
                    121:                        break;
                    122:                case 't':
                    123:                        rcsid = optarg;
1.10      jfb       124:                        break;
1.1       jfb       125:                default:
1.18      joris     126:                        return (CVS_EX_USAGE);
1.1       jfb       127:                }
                    128:        }
                    129:
                    130:        argc -= optind;
                    131:        argv += optind;
                    132:
1.22    ! jfb       133:        co_mods = argv;
        !           134:        co_nmod = argc;
        !           135:
1.13      jfb       136:        if (!statmod && (argc == 0)) {
1.1       jfb       137:                cvs_log(LP_ERR,
                    138:                    "must specify at least one module or directory");
1.18      joris     139:                return (CVS_EX_USAGE);
1.1       jfb       140:        }
                    141:
1.13      jfb       142:        if (statmod && (argc > 0)) {
                    143:                cvs_log(LP_ERR,  "-c and -s must not get any arguments");
1.18      joris     144:                return (CVS_EX_USAGE);
1.13      jfb       145:        }
                    146:
1.14      joris     147:        *arg = optind;
                    148:        return (0);
                    149: }
1.9       jfb       150:
1.22    ! jfb       151: static int
        !           152: cvs_checkout_pre_exec(struct cvsroot *root)
1.14      joris     153: {
1.22    ! jfb       154:        int i;
1.1       jfb       155:
1.22    ! jfb       156:        /* create any required base directories */
        !           157:        for (i = 0; i < co_nmod; i++) {
        !           158:                if (cvs_file_create(NULL, co_mods[i], DT_DIR, 0755) < 0)
        !           159:                        return (CVS_EX_DATA);
        !           160:        }
        !           161:
        !           162:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           163:                for (i = 0; i < co_nmod; i++)
        !           164:                        if (cvs_sendarg(root, co_mods[i], 0) < 0)
        !           165:                                return (CVS_EX_PROTO);
        !           166:                if (cvs_sendreq(root, CVS_REQ_DIRECTORY, ".") < 0)
        !           167:                        return (CVS_EX_PROTO);
        !           168:                if (cvs_sendln(root, root->cr_dir) < 0)
        !           169:                        return (CVS_EX_PROTO);
        !           170:
        !           171:                if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0)
        !           172:                        cvs_log(LP_ERR, "failed to expand module");
        !           173:
        !           174:                if (usehead && (cvs_sendarg(root, "-f", 0) < 0))
        !           175:                        return (CVS_EX_PROTO);
        !           176:
        !           177:                if ((tgtdir != NULL) &&
        !           178:                    ((cvs_sendarg(root, "-d", 0) < 0) ||
        !           179:                    (cvs_sendarg(root, tgtdir, 0) < 0)))
        !           180:                        return (CVS_EX_PROTO);
        !           181:
        !           182:                if (!shorten && cvs_sendarg(root, "-N", 0) < 0)
        !           183:                        return (CVS_EX_PROTO);
        !           184:
        !           185:                for (i = 0; i < co_nmod; i++)
        !           186:                        if (cvs_sendarg(root, co_mods[i], 0) < 0)
        !           187:                                return (CVS_EX_PROTO);
        !           188:
        !           189:                if ((statmod == CVS_LISTMOD) &&
        !           190:                    (cvs_sendarg(root, "-c", 0) < 0))
        !           191:                        return (CVS_EX_PROTO);
        !           192:                else if ((statmod == CVS_STATMOD) &&
        !           193:                    (cvs_sendarg(root, "-s", 0) < 0))
        !           194:                        return (CVS_EX_PROTO);
        !           195:        }
1.1       jfb       196:        return (0);
                    197: }