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

1.1     ! jfb         1: /*     $OpenBSD$       */
        !             2: /*
        !             3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
        !             4:  * Copyright (c) 2004 Joris Vink <amni@pandora.be>
        !             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: #include <sysexits.h>
        !            38:
        !            39: #include "cvs.h"
        !            40: #include "log.h"
        !            41: #include "proto.h"
        !            42:
        !            43:
        !            44: int cvs_tag_file (CVSFILE *, void *);
        !            45:
        !            46:
        !            47: /*
        !            48:  * cvs_tag()
        !            49:  *
        !            50:  * Handler for the `cvs tag' command.
        !            51:  * Returns 0 on success, or one of the known exit codes on error.
        !            52:  */
        !            53: int
        !            54: cvs_tag(int argc, char **argv)
        !            55: {
        !            56:        int ch, flags;
        !            57:        struct cvsroot *root;
        !            58:        char *tag, *old_tag;
        !            59:        int branch, delete;
        !            60:
        !            61:        old_tag = NULL;
        !            62:        branch = delete = 0;
        !            63:        flags = CF_SORT|CF_IGNORE|CF_RECURSE;
        !            64:
        !            65:        while ((ch = getopt(argc, argv, "bdlr:")) != -1) {
        !            66:                switch (ch) {
        !            67:                case 'b':
        !            68:                        branch = 1;
        !            69:                        break;
        !            70:                case 'd':
        !            71:                        delete = 1;
        !            72:                        break;
        !            73:                case 'l':
        !            74:                        flags &= ~CF_RECURSE;
        !            75:                        break;
        !            76:                case 'r':
        !            77:                        old_tag = optarg;
        !            78:                        break;
        !            79:                default:
        !            80:                        return (EX_USAGE);
        !            81:                }
        !            82:        }
        !            83:
        !            84:        argc -= optind;
        !            85:        argv += optind;
        !            86:
        !            87:        if (argc == 0) {
        !            88:                return (EX_USAGE);
        !            89:        } else {
        !            90:                tag = argv[0];
        !            91:                argc--;
        !            92:                argv++;
        !            93:        }
        !            94:
        !            95:        if (branch && delete) {
        !            96:                cvs_log(LP_WARN, "ignoring -b with -d options");
        !            97:                branch = 0;
        !            98:        }
        !            99:
        !           100:        if (delete && old_tag)
        !           101:                old_tag = NULL;
        !           102:
        !           103:        if (argc == 0)
        !           104:                cvs_files = cvs_file_get(".", flags);
        !           105:        else
        !           106:                cvs_files = cvs_file_getspec(argv, argc, 0);
        !           107:        if (cvs_files == NULL)
        !           108:                return (EX_DATAERR);
        !           109:
        !           110:        root = CVS_DIR_ROOT(cvs_files);
        !           111:        if (root == NULL) {
        !           112:                cvs_log(LP_ERR,
        !           113:                    "No CVSROOT specified!  Please use the `-d' option");
        !           114:                cvs_log(LP_ERR,
        !           115:                    "or set the CVSROOT environment variable.");
        !           116:                return (EX_USAGE);
        !           117:        }
        !           118:
        !           119:        if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
        !           120:                return (EX_OSERR);
        !           121:
        !           122:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           123:                if (branch)
        !           124:                        cvs_sendarg(root, "-b", 0);
        !           125:                if (delete)
        !           126:                        cvs_sendarg(root, "-d", 0);
        !           127:                if (old_tag) {
        !           128:                        cvs_sendarg(root, "-r", 0);
        !           129:                        cvs_sendarg(root, old_tag, 0);
        !           130:                }
        !           131:                cvs_sendarg(root, tag, 0);
        !           132:        }
        !           133:
        !           134:        cvs_file_examine(cvs_files, cvs_tag_file, NULL);
        !           135:
        !           136:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           137:                cvs_senddir(root, cvs_files);
        !           138:                cvs_sendreq(root, CVS_REQ_TAG, NULL);
        !           139:        }
        !           140:
        !           141:        return (0);
        !           142: }
        !           143:
        !           144:
        !           145: /*
        !           146:  * cvs_tag_file()
        !           147:  *
        !           148:  * Get the status of a single file.
        !           149:  */
        !           150: int
        !           151: cvs_tag_file(CVSFILE *cfp, void *arg)
        !           152: {
        !           153:        int ret;
        !           154:        char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
        !           155:        RCSFILE *rf;
        !           156:        struct cvs_ent *entp;
        !           157:        struct cvsroot *root;
        !           158:
        !           159:        ret = 0;
        !           160:        rf = NULL;
        !           161:        root = CVS_DIR_ROOT(cfp);
        !           162:
        !           163:        if ((root->cr_method != CVS_METHOD_LOCAL) && (cfp->cf_type == DT_DIR)) {
        !           164:                if (cvs_senddir(root, cfp) < 0)
        !           165:                        return (-1);
        !           166:                return (0);
        !           167:        }
        !           168:
        !           169:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
        !           170:        entp = cvs_ent_getent(fpath);
        !           171:
        !           172:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           173:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
        !           174:                        cvs_ent_free(entp);
        !           175:                        return (-1);
        !           176:                }
        !           177:
        !           178:                switch (cfp->cf_cvstat) {
        !           179:                case CVS_FST_UNKNOWN:
        !           180:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
        !           181:                            CVS_FILE_NAME(cfp));
        !           182:                        break;
        !           183:                case CVS_FST_UPTODATE:
        !           184:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
        !           185:                            CVS_FILE_NAME(cfp));
        !           186:                        break;
        !           187:                case CVS_FST_MODIFIED:
        !           188:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
        !           189:                            CVS_FILE_NAME(cfp));
        !           190:                default:
        !           191:                        break;
        !           192:                }
        !           193:        } else {
        !           194:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
        !           195:                        cvs_log(LP_WARN, "I know nothing about %s", fpath);
        !           196:                        return (0);
        !           197:                }
        !           198:
        !           199:                if (cfp->cf_parent != NULL)
        !           200:                        repo = cfp->cf_parent->cf_ddat->cd_repo;
        !           201:                else
        !           202:                        repo = NULL;
        !           203:
        !           204:                snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
        !           205:                    root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
        !           206:
        !           207:                rf = rcs_open(rcspath, RCS_MODE_READ);
        !           208:                if (rf == NULL) {
        !           209:                        cvs_ent_free(entp);
        !           210:                        return (-1);
        !           211:                }
        !           212:
        !           213:                rcs_close(rf);
        !           214:        }
        !           215:
        !           216:        if (entp != NULL)
        !           217:                cvs_ent_free(entp);
        !           218:
        !           219:        return (ret);
        !           220: }