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

Annotation of src/usr.bin/cvs/status.c, Revision 1.15

1.15    ! jfb         1: /*     $OpenBSD: status.c,v 1.14 2005/04/12 14:58:40 joris Exp $       */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.4       tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.4       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.4       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.4       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.4       tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/types.h>
                     28: #include <sys/stat.h>
                     29:
                     30: #include <errno.h>
                     31: #include <stdio.h>
                     32: #include <fcntl.h>
                     33: #include <stdlib.h>
                     34: #include <unistd.h>
                     35: #include <string.h>
                     36:
                     37: #include "cvs.h"
                     38: #include "log.h"
                     39: #include "proto.h"
                     40:
                     41:
1.15    ! jfb        42: #define CVS_STATUS_SEP \
        !            43:  "==================================================================="
        !            44:
        !            45:
1.1       jfb        46: const char *cvs_statstr[] = {
                     47:        "Unknown",
1.15    ! jfb        48:        "Up-to-date",
1.1       jfb        49:        "Locally Modified",
                     50:        "Added",
                     51:        "Removed",
                     52:        "Conflict",
                     53:        "Patched",
1.15    ! jfb        54:        "Lost",
1.1       jfb        55: };
                     56:
                     57:
1.15    ! jfb        58: int cvs_status_file      (CVSFILE *, void *);
        !            59: int cvs_status_local     (CVSFILE *, void *);
        !            60: int cvs_status_options   (char *, int, char **, int *);
        !            61: int cvs_status_sendflags (struct cvsroot *);
1.10      joris      62:
                     63: struct cvs_cmd_info cvs_status = {
                     64:        cvs_status_options,
                     65:        cvs_status_sendflags,
                     66:        cvs_status_file,
                     67:        NULL, NULL,
                     68:        CF_SORT | CF_IGNORE | CF_RECURSE,
                     69:        CVS_REQ_STATUS,
                     70:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     71: };
1.1       jfb        72:
1.10      joris      73: static int verbose = 0;
1.1       jfb        74:
                     75: int
1.10      joris      76: cvs_status_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        77: {
1.10      joris      78:        int ch;
1.1       jfb        79:
1.10      joris      80:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        81:                switch (ch) {
1.7       jfb        82:                case 'l':
1.10      joris      83:                        cvs_status.file_flags &= ~CF_RECURSE;
1.7       jfb        84:                        break;
                     85:                case 'R':
1.10      joris      86:                        cvs_status.file_flags |= CF_RECURSE;
1.7       jfb        87:                        break;
                     88:                case 'v':
                     89:                        verbose = 1;
                     90:                        break;
1.1       jfb        91:                default:
1.14      joris      92:                        return (CVS_EX_USAGE);
1.1       jfb        93:                }
                     94:        }
                     95:
1.10      joris      96:        *arg = optind;
                     97:        return (0);
                     98: }
1.1       jfb        99:
1.10      joris     100: int
                    101: cvs_status_sendflags(struct cvsroot *root)
                    102: {
                    103:        if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
1.14      joris     104:                return (CVS_EX_PROTO);
1.1       jfb       105:        return (0);
                    106: }
                    107:
                    108: /*
                    109:  * cvs_status_file()
                    110:  *
                    111:  * Get the status of a single file.
                    112:  */
                    113: int
1.2       jfb       114: cvs_status_file(CVSFILE *cfp, void *arg)
1.1       jfb       115: {
1.5       jfb       116:        int ret;
1.15    ! jfb       117:        char *repo, fpath[MAXPATHLEN];
1.1       jfb       118:        RCSFILE *rf;
                    119:        struct cvs_ent *entp;
                    120:        struct cvsroot *root;
                    121:
1.5       jfb       122:        ret = 0;
1.1       jfb       123:        rf = NULL;
1.5       jfb       124:        root = CVS_DIR_ROOT(cfp);
                    125:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       126:
1.6       jfb       127:        if (cfp->cf_type == DT_DIR) {
1.15    ! jfb       128:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
        !           129:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
        !           130:                            CVS_FILE_NAME(cfp));
        !           131:                else
        !           132:                        ret = cvs_senddir(root, cfp);
1.6       jfb       133:                return (ret);
                    134:        }
1.1       jfb       135:
1.5       jfb       136:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.2       jfb       137:        entp = cvs_ent_getent(fpath);
1.1       jfb       138:
1.15    ! jfb       139:        if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
        !           140:                cvs_ent_free(entp);
        !           141:                return (-1);
        !           142:        }
        !           143:
        !           144:        switch (cfp->cf_cvstat) {
        !           145:        case CVS_FST_UNKNOWN:
        !           146:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
        !           147:                    CVS_FILE_NAME(cfp));
        !           148:                break;
        !           149:        case CVS_FST_UPTODATE:
        !           150:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
        !           151:                    CVS_FILE_NAME(cfp));
        !           152:                break;
        !           153:        case CVS_FST_MODIFIED:
        !           154:                ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
        !           155:                    CVS_FILE_NAME(cfp));
        !           156:                if (ret == 0)
        !           157:                        ret = cvs_sendfile(root, fpath);
        !           158:        default:
        !           159:                break;
        !           160:        }
        !           161:
        !           162:        if (entp != NULL)
        !           163:                cvs_ent_free(entp);
        !           164:        return (ret);
        !           165: }
        !           166:
        !           167: int
        !           168: cvs_status_local(CVSFILE *cfp, void *arg)
        !           169: {
        !           170:        char *repo, numbuf[64], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
        !           171:        RCSFILE *rf;
        !           172:        struct cvs_ent *entp;
        !           173:        struct cvsroot *root;
        !           174:
        !           175:        if (cfp->cf_type == DT_DIR)
        !           176:                return (0);
        !           177:
        !           178:        root = CVS_DIR_ROOT(cfp);
        !           179:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       180:
1.15    ! jfb       181:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
        !           182:        entp = cvs_ent_getent(fpath);
1.1       jfb       183:
1.15    ! jfb       184:        if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
        !           185:                cvs_log(LP_WARN, "I know nothing about %s", fpath);
        !           186:                return (0);
        !           187:        }
1.1       jfb       188:
1.15    ! jfb       189:        snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
        !           190:            root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.1       jfb       191:
1.15    ! jfb       192:        rf = rcs_open(rcspath, RCS_READ);
        !           193:        if (rf == NULL) {
        !           194:                if (entp != NULL)
        !           195:                        cvs_ent_free(entp);
        !           196:                return (-1);
1.1       jfb       197:        }
1.5       jfb       198:
1.15    ! jfb       199:        cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
        !           200:            CVS_FILE_NAME(cfp), cvs_statstr[cfp->cf_cvstat]);
        !           201:
        !           202:        rcsnum_tostr(entp->ce_rev, numbuf, sizeof(numbuf));
        !           203:        cvs_printf("   Working revision:    %s %s\n", numbuf, "date here");
        !           204:        rcsnum_tostr(rf->rf_head, numbuf, sizeof(numbuf));
        !           205:        cvs_printf("   Repository revision: %s %s\n", numbuf, rcspath);
        !           206:        cvs_printf("   Sticky Tag:          %s\n", "(none)");
        !           207:        cvs_printf("   Sticky Date:         %s\n", "(none)");
        !           208:        cvs_printf("   Sticky Options:      %s\n", "(none)");
        !           209:
        !           210:        rcs_close(rf);
        !           211:
1.5       jfb       212:        if (entp != NULL)
                    213:                cvs_ent_free(entp);
1.15    ! jfb       214:        return (0);
1.1       jfb       215: }