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

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

1.9     ! tedu        1: /*     $OpenBSD: commit.c,v 1.8 2004/12/06 21:03:12 deraadt Exp $      */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.9     ! tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.9     ! 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.9     ! 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.9     ! 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.9     ! tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/types.h>
1.6       jfb        28: #include <sys/queue.h>
1.1       jfb        29: #include <sys/stat.h>
                     30:
                     31: #include <errno.h>
                     32: #include <stdio.h>
                     33: #include <fcntl.h>
                     34: #include <stdlib.h>
                     35: #include <unistd.h>
                     36: #include <string.h>
                     37: #include <sysexits.h>
                     38:
                     39: #include "cvs.h"
                     40: #include "log.h"
1.5       krapht     41: #include "buf.h"
1.2       jfb        42: #include "proto.h"
1.1       jfb        43:
                     44:
                     45:
1.6       jfb        46:
1.7       jfb        47: int    cvs_commit_prepare  (CVSFILE *, void *);
1.6       jfb        48: int    cvs_commit_file     (CVSFILE *, void *);
1.1       jfb        49:
                     50:
                     51: /*
                     52:  * cvs_commit()
                     53:  *
                     54:  * Handler for the `cvs commit' command.
                     55:  */
                     56: int
                     57: cvs_commit(int argc, char **argv)
                     58: {
1.7       jfb        59:        int i, ch, recurse, flags;
1.1       jfb        60:        char *msg, *mfile;
1.7       jfb        61:        struct cvs_flist cl;
                     62:        struct cvsroot *root;
1.1       jfb        63:
1.7       jfb        64:        flags = CF_RECURSE|CF_IGNORE|CF_SORT;
1.1       jfb        65:        recurse = 1;
                     66:        mfile = NULL;
                     67:        msg = NULL;
1.7       jfb        68:        TAILQ_INIT(&cl);
1.3       krapht     69:
1.1       jfb        70:        while ((ch = getopt(argc, argv, "F:flm:R")) != -1) {
                     71:                switch (ch) {
                     72:                case 'F':
                     73:                        mfile = optarg;
                     74:                        break;
                     75:                case 'f':
                     76:                        recurse = 0;
                     77:                        break;
                     78:                case 'l':
                     79:                        recurse = 0;
                     80:                        break;
                     81:                case 'm':
                     82:                        msg = optarg;
                     83:                        break;
                     84:                case 'R':
                     85:                        recurse = 1;
                     86:                        break;
                     87:                default:
                     88:                        return (EX_USAGE);
                     89:                }
                     90:        }
                     91:
                     92:        if ((msg != NULL) && (mfile != NULL)) {
                     93:                cvs_log(LP_ERR, "the -F and -m flags are mutually exclusive");
                     94:                return (EX_USAGE);
                     95:        }
                     96:
1.6       jfb        97:        if ((mfile != NULL) && (msg = cvs_logmsg_open(mfile)) == NULL)
1.1       jfb        98:                return (EX_DATAERR);
                     99:
                    100:        argc -= optind;
                    101:        argv += optind;
                    102:
1.7       jfb       103:        if (argc == 0) {
1.6       jfb       104:                cvs_files = cvs_file_get(".", flags);
1.8       deraadt   105:        } else {
1.6       jfb       106:                cvs_files = cvs_file_getspec(argv, argc, flags);
1.1       jfb       107:        }
1.6       jfb       108:        if (cvs_files == NULL)
                    109:                return (EX_DATAERR);
1.1       jfb       110:
1.7       jfb       111:        cvs_file_examine(cvs_files, cvs_commit_prepare, &cl);
                    112:
                    113:        if (msg == NULL) {
                    114:                msg = cvs_logmsg_get(CVS_FILE_NAME(cvs_files), &cl);
                    115:                if (msg == NULL)
                    116:                        return (1);
                    117:        }
                    118:
                    119:        root = CVS_DIR_ROOT(cvs_files);
                    120:        cvs_connect(root);
                    121:        cvs_logmsg_send(root, msg);
                    122:
1.6       jfb       123:        cvs_file_examine(cvs_files, cvs_commit_file, &cl);
1.3       krapht    124:
1.7       jfb       125:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    126:                cvs_senddir(root, cvs_files);
                    127:                if (argc > 0) {
                    128:                        for (i = 0; i < argc; i++)
                    129:                                cvs_sendarg(root, argv[i], 0);
                    130:                }
                    131:                cvs_sendreq(root, CVS_REQ_CI, NULL);
                    132:        }
                    133:
                    134:        return (0);
                    135: }
                    136:
                    137:
                    138: /*
                    139:  * cvs_commit_prepare()
                    140:  *
                    141:  * Examine the file <cf> to see if it will be part of the commit, in which
                    142:  * case it gets added to the list passed as second argument.
                    143:  */
                    144: int
                    145: cvs_commit_prepare(CVSFILE *cf, void *arg)
                    146: {
                    147:        CVSFILE *copy;
                    148:        struct cvs_flist *clp = (struct cvs_flist *)arg;
                    149:
                    150:        if ((cf->cf_type == DT_REG) && (cf->cf_cvstat == CVS_FST_MODIFIED)) {
                    151:                copy = cvs_file_copy(cf);
                    152:                if (copy == NULL)
                    153:                        return (-1);
                    154:
                    155:                TAILQ_INSERT_TAIL(clp, copy, cf_list);
                    156:        }
1.3       krapht    157:
1.6       jfb       158:        return (0);
1.3       krapht    159: }
                    160:
                    161:
                    162: /*
1.6       jfb       163:  * cvs_commit_file()
1.3       krapht    164:  *
1.6       jfb       165:  * Commit a single file.
1.3       krapht    166:  */
1.6       jfb       167: int
                    168: cvs_commit_file(CVSFILE *cf, void *arg)
1.3       krapht    169: {
1.6       jfb       170:        char *repo, rcspath[MAXPATHLEN], fpath[MAXPATHLEN];
                    171:        RCSFILE *rf;
                    172:        struct cvsroot *root;
                    173:        struct cvs_ent *entp;
                    174:
1.7       jfb       175:        rf = NULL;
                    176:        repo = NULL;
1.6       jfb       177:
                    178:        if (cf->cf_type == DT_DIR) {
                    179:                if (cf->cf_cvstat != CVS_FST_UNKNOWN) {
1.7       jfb       180:                        root = CVS_DIR_ROOT(cf);
                    181:                        if ((cf->cf_parent != NULL) &&
1.6       jfb       182:                            (root != cf->cf_parent->cf_ddat->cd_root)) {
                    183:                                cvs_connect(root);
                    184:                        }
                    185:
                    186:                        cvs_senddir(root, cf);
                    187:                }
1.3       krapht    188:
1.6       jfb       189:                return (0);
1.3       krapht    190:        }
                    191:
1.7       jfb       192:
                    193:        root = CVS_DIR_ROOT(cf);
                    194:        cvs_file_getpath(cf, fpath, sizeof(fpath));
                    195:
                    196:        if (cf->cf_parent != NULL)
1.6       jfb       197:                repo = cf->cf_parent->cf_ddat->cd_repo;
1.5       krapht    198:
1.6       jfb       199:        entp = cvs_ent_getent(fpath);
                    200:        if (entp == NULL)
                    201:                return (-1);
1.3       krapht    202:
1.6       jfb       203:        if ((cf->cf_cvstat == CVS_FST_ADDED) ||
                    204:            (cf->cf_cvstat == CVS_FST_MODIFIED)) {
                    205:                if ((root->cr_method != CVS_METHOD_LOCAL) &&
                    206:                    (cvs_sendentry(root, entp) < 0)) {
                    207:                        cvs_ent_free(entp);
                    208:                        return (-1);
1.5       krapht    209:                }
1.3       krapht    210:
1.6       jfb       211:                cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cf));
                    212:                cvs_sendfile(root, fpath);
1.5       krapht    213:        }
1.3       krapht    214:
1.6       jfb       215:        snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
                    216:            root->cr_dir, repo, fpath, RCS_FILE_EXT);
1.3       krapht    217:
1.6       jfb       218:        cvs_ent_free(entp);
1.3       krapht    219:
1.6       jfb       220:        return (0);
1.1       jfb       221: }