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

1.46    ! xsa         1: /*     $OpenBSD: tag.c,v 1.45 2006/06/07 18:19:07 xsa Exp $    */
1.1       jfb         2: /*
1.45      xsa         3:  * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         4:  *
1.45      xsa         5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         8:  *
1.45      xsa         9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.36      xsa        18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
                     22: #include "proto.h"
                     23:
1.45      xsa        24: int    cvs_tag(int, char **);
                     25: void   cvs_tag_local(struct cvs_file *);
                     26:
                     27: static int tag_del(struct cvs_file *);
                     28: static int tag_add(struct cvs_file *);
                     29:
                     30: static int     tag_delete = 0;
1.46    ! xsa        31: static int     tag_force_move = 0;
1.45      xsa        32: static char    *tag = NULL;
                     33: static char    *tag_date = NULL;
                     34: static char    *tag_name = NULL;
                     35: static char    *tag_oldname = NULL;
1.7       joris      36:
1.17      jfb        37: struct cvs_cmd cvs_cmd_tag = {
                     38:        CVS_OP_TAG, CVS_REQ_TAG, "tag",
                     39:        { "ta", "freeze" },
                     40:        "Add a symbolic tag to checked out version of files",
1.40      xsa        41:        "[-bcdFflR] [-D date | -r rev] tag [file ...]",
1.17      jfb        42:        "bcD:dFflRr:",
                     43:        NULL,
1.45      xsa        44:        cvs_tag
1.17      jfb        45: };
                     46:
1.45      xsa        47: int
                     48: cvs_tag(int argc, char **argv)
1.1       jfb        49: {
1.45      xsa        50:        int ch, flags;
                     51:        struct cvs_recursion cr;
1.1       jfb        52:
1.45      xsa        53:        flags = CR_RECURSE_DIRS;
1.1       jfb        54:
1.45      xsa        55:        while ((ch = getopt(argc, argv, cvs_cmd_tag.cmd_opts)) != -1) {
1.1       jfb        56:                switch (ch) {
1.45      xsa        57:                case 'D':
                     58:                        tag_date = optarg;
1.1       jfb        59:                        break;
                     60:                case 'd':
1.45      xsa        61:                        tag_delete = 1;
1.3       jfb        62:                        break;
1.46    ! xsa        63:                case 'F':
        !            64:                        tag_force_move = 1;
        !            65:                        break;
1.1       jfb        66:                case 'l':
1.45      xsa        67:                        flags &= ~CR_RECURSE_DIRS;
1.17      jfb        68:                        break;
                     69:                case 'R':
1.1       jfb        70:                        break;
                     71:                case 'r':
1.14      jfb        72:                        tag_oldname = optarg;
1.1       jfb        73:                        break;
                     74:                default:
1.45      xsa        75:                        fatal("%s", cvs_cmd_tag.cmd_synopsis);
1.1       jfb        76:                }
                     77:        }
                     78:
                     79:        argc -= optind;
                     80:        argv += optind;
                     81:
1.40      xsa        82:        if (argc == 0)
1.45      xsa        83:                fatal("%s", cvs_cmd_tag.cmd_synopsis);
                     84:
                     85:        tag_name = argv[0];
                     86:        argc--;
                     87:        argv++;
1.15      jfb        88:
1.38      xsa        89:        if (!rcs_sym_check(tag_name))
                     90:                fatal("tag `%s' must not contain the characters `%s'",
1.15      jfb        91:                    tag_name, RCS_SYM_INVALCHAR);
1.1       jfb        92:
1.45      xsa        93:        if (tag_oldname != NULL) {
                     94:                if (tag_delete == 1)
                     95:                        tag_oldname = NULL;
                     96:                else
                     97:                        tag = tag_oldname;
                     98:        }
                     99:
                    100:        if (tag_date != NULL) {
                    101:                if (tag_delete == 1)
                    102:                        tag_date = NULL;
                    103:                else
                    104:                        tag = tag_date;
                    105:        }
                    106:
                    107:        if (tag_oldname != NULL && tag_date != NULL)
                    108:                fatal("-r and -D options are mutually exclusive");
                    109:
                    110:        cr.enterdir = NULL;
                    111:        cr.leavedir = NULL;
                    112:        cr.local = cvs_tag_local;
                    113:        cr.remote = NULL;
                    114:        cr.flags = flags;
1.1       jfb       115:
1.45      xsa       116:        cvs_file_run(argc, argv, &cr);
1.3       jfb       117:
1.7       joris     118:        return (0);
                    119: }
                    120:
1.45      xsa       121: void
                    122: cvs_tag_local(struct cvs_file *cf)
1.7       joris     123: {
1.45      xsa       124:        cvs_log(LP_TRACE, "cvs_tag_local(%s)", cf->file_path);
1.17      jfb       125:
1.45      xsa       126:        if (cf->file_type == CVS_DIR) {
                    127:                if (verbosity > 1) {
                    128:                        cvs_log(LP_NOTICE, "%s %s",
                    129:                            (tag_delete == 1) ? "Untagging" : "Tagging",
                    130:                            cf->file_path);
                    131:                }
                    132:                return;
                    133:        }
1.40      xsa       134:
1.45      xsa       135:        cvs_file_classify(cf, tag, 0);
1.7       joris     136:
1.45      xsa       137:        if (tag_delete == 1) {
                    138:                if (tag_del(cf) == 0) {
                    139:                        if (verbosity > 0)
                    140:                                cvs_printf("D %s\n", cf->file_path);
1.21      xsa       141:
1.45      xsa       142:                        rcs_write(cf->file_rcs);
                    143:                }
                    144:                return;
                    145:        }
1.21      xsa       146:
1.45      xsa       147:        switch(cf->file_status) {
                    148:        case FILE_ADDED:
                    149:                if (verbosity > 1) {
                    150:                        cvs_log(LP_NOTICE,
                    151:                            "couldn't tag added but un-commited file `%s'",
                    152:                            cf->file_path);
1.35      joris     153:                }
1.45      xsa       154:                return;
                    155:        case FILE_REMOVED:
                    156:                if (verbosity > 1) {
                    157:                        cvs_log(LP_NOTICE,
                    158:                            "skipping removed but un-commited file `%s'",
                    159:                            cf->file_path);
                    160:                }
                    161:                return;
                    162:        case FILE_CHECKOUT:
                    163:        case FILE_MODIFIED:
                    164:        case FILE_UPTODATE:
                    165:                if (tag_add(cf) == 0) {
                    166:                        if (verbosity > 0)
                    167:                                cvs_printf("T %s\n", cf->file_path);
1.1       jfb       168:
1.45      xsa       169:                        rcs_write(cf->file_rcs);
1.35      joris     170:                }
1.45      xsa       171:                break;
                    172:        default:
                    173:                break;
1.1       jfb       174:        }
                    175: }
                    176:
1.14      jfb       177: static int
1.45      xsa       178: tag_del(struct cvs_file *cf)
1.1       jfb       179: {
1.45      xsa       180:        if (cf->file_rcs == NULL)
                    181:                return (-1);
1.1       jfb       182:
1.45      xsa       183:        if (cvs_noexec == 1)
1.35      joris     184:                return (0);
1.1       jfb       185:
1.45      xsa       186:        return (rcs_sym_remove(cf->file_rcs, tag_name));
1.14      jfb       187: }
                    188:
                    189: static int
1.45      xsa       190: tag_add(struct cvs_file *cf)
1.14      jfb       191: {
1.46    ! xsa       192:        char revbuf[16], trevbuf[16];
        !           193:        RCSNUM *trev;
        !           194:        struct rcs_sym *sym;
1.14      jfb       195:
1.45      xsa       196:        if (cf->file_rcs == NULL) {
1.23      xsa       197:                if (verbosity > 1)
1.45      xsa       198:                        cvs_log(LP_NOTICE, "cannot find revision "
                    199:                            "control file for `%s'", cf->file_name);
                    200:                return (-1);
1.14      jfb       201:        }
1.1       jfb       202:
1.45      xsa       203:        if (cvs_noexec == 1)
1.32      xsa       204:                return (0);
1.1       jfb       205:
1.46    ! xsa       206:        trev = rcs_sym_getrev(cf->file_rcs, tag_name);
        !           207:        if (trev != NULL) {
        !           208:                if (rcsnum_cmp(cf->file_rcsrev, trev, 0) == 0) {
        !           209:                        rcsnum_free(trev);
        !           210:                        return (-1);
        !           211:                }
        !           212:                (void)rcsnum_tostr(trev, trevbuf, sizeof(trevbuf));
        !           213:
        !           214:                if (tag_force_move == 0) {
        !           215:                        cvs_printf("W %s : %s ", cf->file_path, tag_name);
        !           216:                        cvs_printf("already exists on version %s", trevbuf);
        !           217:                        cvs_printf(" : NOT MOVING tag to version %s\n", revbuf);
        !           218:
        !           219:                        return (-1);
        !           220:                } else if (tag_force_move == 1) {
        !           221:                        sym = rcs_sym_get(cf->file_rcs, tag_name);
        !           222:                        rcsnum_cpy(cf->file_rcsrev, sym->rs_num, 0);
        !           223:                        cf->file_rcs->rf_flags &= ~RCS_SYNCED;
        !           224:
        !           225:                        return (0);
        !           226:                }
        !           227:        }
        !           228:
1.45      xsa       229:        if (rcs_sym_add(cf->file_rcs, tag_name, cf->file_rcsrev) == -1) {
                    230:                if (rcs_errno != RCS_ERR_DUPENT) {
1.46    ! xsa       231:                        (void)rcsnum_tostr(cf->file_rcsrev, revbuf,
        !           232:                            sizeof(revbuf));
1.45      xsa       233:                        cvs_log(LP_NOTICE,
                    234:                            "failed to set tag %s to revision %s in %s",
                    235:                            tag_name, revbuf, cf->file_rcs->rf_path);
1.39      xsa       236:                }
1.45      xsa       237:                return (-1);
1.1       jfb       238:        }
1.17      jfb       239:
1.14      jfb       240:        return (0);
1.1       jfb       241: }