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

Annotation of src/usr.bin/cvs/tag.c, Revision 1.10

1.10    ! joris       1: /*     $OpenBSD: tag.c,v 1.9 2005/04/11 17:56:27 joris Exp $   */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.5       joris       4:  * Copyright (c) 2004 Joris Vink <joris@openbsd.org>
1.1       jfb         5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  *
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. The name of the author may not be used to endorse or promote products
                     14:  *    derived from this software without specific prior written permission.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     17:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     18:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     19:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     20:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     21:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     22:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     23:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     24:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     25:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
                     28: #include <sys/types.h>
                     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:
                     38: #include "cvs.h"
                     39: #include "log.h"
                     40: #include "proto.h"
                     41:
                     42:
1.7       joris      43: int cvs_tag_file(CVSFILE *, void *);
                     44: int cvs_tag_options(char *, int, char **, int *);
                     45: int cvs_tag_sendflags(struct cvsroot *);
                     46:
                     47: static char *tag, *old_tag, *date;
                     48: static int branch, delete;
                     49:
                     50: struct cvs_cmd_info cvs_tag = {
                     51:        cvs_tag_options,
                     52:        cvs_tag_sendflags,
                     53:        cvs_tag_file,
                     54:        NULL, NULL,
                     55:        CF_SORT | CF_IGNORE | CF_RECURSE,
                     56:        CVS_REQ_TAG,
                     57:        CVS_CMD_ALLOWSPEC
                     58: };
1.1       jfb        59:
                     60: int
1.7       joris      61: cvs_tag_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        62: {
1.7       joris      63:        int ch;
1.1       jfb        64:
1.3       jfb        65:        date = old_tag = NULL;
1.1       jfb        66:        branch = delete = 0;
                     67:
1.7       joris      68:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        69:                switch (ch) {
                     70:                case 'b':
                     71:                        branch = 1;
                     72:                        break;
                     73:                case 'd':
                     74:                        delete = 1;
                     75:                        break;
1.3       jfb        76:                case 'D':
                     77:                        date = optarg;
                     78:                        break;
1.1       jfb        79:                case 'l':
1.7       joris      80:                        cvs_tag.file_flags &= ~CF_RECURSE;
1.1       jfb        81:                        break;
                     82:                case 'r':
                     83:                        old_tag = optarg;
                     84:                        break;
                     85:                default:
1.9       joris      86:                        return (1);
1.1       jfb        87:                }
                     88:        }
                     89:
1.7       joris      90:        *arg = optind;
1.1       jfb        91:        argc -= optind;
                     92:        argv += optind;
                     93:
                     94:        if (argc == 0) {
1.9       joris      95:                return (1);
1.1       jfb        96:        } else {
                     97:                tag = argv[0];
                     98:                argc--;
                     99:                argv++;
1.7       joris     100:                *arg += 1;
1.1       jfb       101:        }
                    102:
                    103:        if (branch && delete) {
                    104:                cvs_log(LP_WARN, "ignoring -b with -d options");
                    105:                branch = 0;
                    106:        }
                    107:
                    108:        if (delete && old_tag)
                    109:                old_tag = NULL;
                    110:
1.3       jfb       111:        if (delete && date)
                    112:                date = NULL;
                    113:
                    114:        if (old_tag != NULL && date != NULL) {
                    115:                cvs_log(LP_ERROR, "-r and -D options are mutually exclusive");
                    116:                return (-1);
                    117:        }
                    118:
1.7       joris     119:        return (0);
                    120: }
                    121:
                    122: int
                    123: cvs_tag_sendflags(struct cvsroot *root)
                    124: {
                    125:        if (branch && (cvs_sendarg(root, "-b", 0) < 0))
1.8       xsa       126:                return (-1);
1.7       joris     127:
                    128:        if (delete && (cvs_sendarg(root, "-d", 0) < 0))
1.8       xsa       129:                return (-1);
1.1       jfb       130:
1.7       joris     131:        if (old_tag) {
                    132:                if ((cvs_sendarg(root, "-r", 0) < 0) ||
                    133:                    (cvs_sendarg(root, old_tag, 0) < 0))
1.8       xsa       134:                        return (-1);
1.1       jfb       135:        }
                    136:
1.7       joris     137:        if (date) {
                    138:                if ((cvs_sendarg(root, "-D", 0) < 0) ||
                    139:                    (cvs_sendarg(root, date, 0) < 0))
1.8       xsa       140:                        return (-1);
1.1       jfb       141:        }
1.7       joris     142:
                    143:        if (cvs_sendarg(root, tag, 0) < 0)
1.8       xsa       144:                return (-1);
1.1       jfb       145:
                    146:        return (0);
                    147: }
                    148:
                    149:
                    150: /*
                    151:  * cvs_tag_file()
                    152:  *
                    153:  * Get the status of a single file.
                    154:  */
                    155: int
                    156: cvs_tag_file(CVSFILE *cfp, void *arg)
                    157: {
                    158:        int ret;
                    159:        char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
                    160:        RCSFILE *rf;
                    161:        struct cvs_ent *entp;
                    162:        struct cvsroot *root;
                    163:
                    164:        ret = 0;
                    165:        rf = NULL;
                    166:        root = CVS_DIR_ROOT(cfp);
                    167:
                    168:        if ((root->cr_method != CVS_METHOD_LOCAL) && (cfp->cf_type == DT_DIR)) {
                    169:                if (cvs_senddir(root, cfp) < 0)
                    170:                        return (-1);
                    171:                return (0);
                    172:        }
                    173:
                    174:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
                    175:        entp = cvs_ent_getent(fpath);
                    176:
                    177:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    178:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
                    179:                        cvs_ent_free(entp);
                    180:                        return (-1);
                    181:                }
                    182:
                    183:                switch (cfp->cf_cvstat) {
                    184:                case CVS_FST_UNKNOWN:
                    185:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    186:                            CVS_FILE_NAME(cfp));
                    187:                        break;
                    188:                case CVS_FST_UPTODATE:
                    189:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
                    190:                            CVS_FILE_NAME(cfp));
                    191:                        break;
                    192:                case CVS_FST_MODIFIED:
                    193:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
                    194:                            CVS_FILE_NAME(cfp));
                    195:                default:
                    196:                        break;
                    197:                }
                    198:        } else {
                    199:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
                    200:                        cvs_log(LP_WARN, "I know nothing about %s", fpath);
                    201:                        return (0);
                    202:                }
                    203:
                    204:                if (cfp->cf_parent != NULL)
                    205:                        repo = cfp->cf_parent->cf_ddat->cd_repo;
                    206:                else
                    207:                        repo = NULL;
                    208:
                    209:                snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
                    210:                    root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
                    211:
1.4       jfb       212:                rf = rcs_open(rcspath, RCS_READ);
1.1       jfb       213:                if (rf == NULL) {
1.6       tedu      214:                        if (entp != NULL)
                    215:                                cvs_ent_free(entp);
1.1       jfb       216:                        return (-1);
                    217:                }
                    218:
                    219:                rcs_close(rf);
                    220:        }
                    221:
                    222:        if (entp != NULL)
                    223:                cvs_ent_free(entp);
                    224:
                    225:        return (ret);
                    226: }