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

1.40    ! xsa         1: /*     $OpenBSD: status.c,v 1.39 2005/07/10 13:58:19 xsa 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>
1.23      xsa        31: #include <fcntl.h>
1.1       jfb        32: #include <stdio.h>
                     33: #include <stdlib.h>
1.23      xsa        34: #include <string.h>
1.1       jfb        35: #include <unistd.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:
1.31      xsa        45: /* Keep this sorted as it is now. See file.h for status values. */
1.1       jfb        46: const char *cvs_statstr[] = {
                     47:        "Unknown",
1.15      jfb        48:        "Up-to-date",
1.1       jfb        49:        "Locally Modified",
1.29      xsa        50:        "Locally Added",
                     51:        "Locally Removed",
                     52:        "Unresolved Conflict",
1.1       jfb        53:        "Patched",
1.16      jfb        54:        "Needs Checkout",
1.1       jfb        55: };
1.33      xsa        56:
1.1       jfb        57:
1.22      jfb        58: static int cvs_status_init      (struct cvs_cmd *, int, char **, int *);
                     59: static int cvs_status_remote    (CVSFILE *, void *);
                     60: static int cvs_status_local     (CVSFILE *, void *);
                     61: static int cvs_status_pre_exec (struct cvsroot *);
                     62:
                     63: struct cvs_cmd cvs_cmd_status = {
                     64:        CVS_OP_STATUS, CVS_REQ_STATUS, "status",
                     65:        { "st", "stat" },
                     66:        "Display status information on checked out files",
                     67:        "[-lRv]",
                     68:        "lRv",
                     69:        NULL,
                     70:        CF_SORT | CF_IGNORE | CF_RECURSE,
                     71:        cvs_status_init,
                     72:        cvs_status_pre_exec,
1.20      jfb        73:        cvs_status_remote,
1.22      jfb        74:        cvs_status_local,
                     75:        NULL,
                     76:        NULL,
1.10      joris      77:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     78: };
1.1       jfb        79:
1.10      joris      80: static int verbose = 0;
1.1       jfb        81:
1.22      jfb        82: static int
                     83: cvs_status_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        84: {
1.10      joris      85:        int ch;
1.1       jfb        86:
1.22      jfb        87:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1       jfb        88:                switch (ch) {
1.7       jfb        89:                case 'l':
1.22      jfb        90:                        cmd->file_flags &= ~CF_RECURSE;
1.7       jfb        91:                        break;
                     92:                case 'R':
1.22      jfb        93:                        cmd->file_flags |= CF_RECURSE;
1.7       jfb        94:                        break;
                     95:                case 'v':
                     96:                        verbose = 1;
                     97:                        break;
1.1       jfb        98:                default:
1.14      joris      99:                        return (CVS_EX_USAGE);
1.1       jfb       100:                }
                    101:        }
                    102:
1.10      joris     103:        *arg = optind;
                    104:        return (0);
                    105: }
1.1       jfb       106:
1.22      jfb       107: static int
                    108: cvs_status_pre_exec(struct cvsroot *root)
1.10      joris     109: {
1.26      xsa       110:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    111:                if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
                    112:                        return (CVS_EX_PROTO);
                    113:        }
                    114:
1.1       jfb       115:        return (0);
                    116: }
                    117:
                    118: /*
1.20      jfb       119:  * cvs_status_remote()
1.1       jfb       120:  *
                    121:  * Get the status of a single file.
                    122:  */
1.22      jfb       123: static int
1.20      jfb       124: cvs_status_remote(CVSFILE *cfp, void *arg)
1.1       jfb       125: {
1.5       jfb       126:        int ret;
1.15      jfb       127:        char *repo, fpath[MAXPATHLEN];
1.1       jfb       128:        RCSFILE *rf;
                    129:        struct cvsroot *root;
                    130:
1.5       jfb       131:        ret = 0;
1.1       jfb       132:        rf = NULL;
1.5       jfb       133:        root = CVS_DIR_ROOT(cfp);
                    134:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       135:
1.6       jfb       136:        if (cfp->cf_type == DT_DIR) {
1.15      jfb       137:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
                    138:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    139:                            CVS_FILE_NAME(cfp));
                    140:                else
                    141:                        ret = cvs_senddir(root, cfp);
1.21      joris     142:
                    143:                if (ret == -1)
                    144:                        ret = CVS_EX_PROTO;
                    145:
1.6       jfb       146:                return (ret);
                    147:        }
1.1       jfb       148:
1.5       jfb       149:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.1       jfb       150:
1.21      joris     151:        if (cvs_sendentry(root, cfp) < 0)
                    152:                return (CVS_EX_PROTO);
1.15      jfb       153:
                    154:        switch (cfp->cf_cvstat) {
                    155:        case CVS_FST_UNKNOWN:
1.20      jfb       156:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cfp->cf_name);
1.15      jfb       157:                break;
                    158:        case CVS_FST_UPTODATE:
1.20      jfb       159:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cfp->cf_name);
1.15      jfb       160:                break;
1.17      joris     161:        case CVS_FST_ADDED:
1.15      jfb       162:        case CVS_FST_MODIFIED:
1.20      jfb       163:                ret = cvs_sendreq(root, CVS_REQ_MODIFIED, cfp->cf_name);
1.15      jfb       164:                if (ret == 0)
                    165:                        ret = cvs_sendfile(root, fpath);
                    166:        default:
                    167:                break;
                    168:        }
                    169:
1.21      joris     170:        if (ret == -1)
                    171:                ret = CVS_EX_PROTO;
                    172:
1.15      jfb       173:        return (ret);
                    174: }
                    175:
1.22      jfb       176: static int
                    177: cvs_status_local(CVSFILE *cf, void *arg)
1.15      jfb       178: {
1.22      jfb       179:        int len;
1.35      xsa       180:        size_t n;
                    181:        char buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
                    182:        char numbuf[64], timebuf[32];
1.15      jfb       183:        RCSFILE *rf;
                    184:
1.33      xsa       185:        if (cf->cf_type == DT_DIR) {
                    186:                if (verbosity > 1)
                    187:                        cvs_log(LP_INFO, "Examining %s", cf->cf_name);
1.15      jfb       188:                return (0);
1.33      xsa       189:        }
1.15      jfb       190:
1.22      jfb       191:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1       jfb       192:
1.40    ! xsa       193:        if (cvs_rcs_getpath(cf, rcspath, sizeof(rcspath)) == NULL)
1.21      joris     194:                return (CVS_EX_DATA);
1.1       jfb       195:
1.37      xsa       196:        if (cf->cf_cvstat != CVS_FST_UNKNOWN &&
                    197:            cf->cf_cvstat != CVS_FST_ADDED) {
1.30      xsa       198:                rf = rcs_open(rcspath, RCS_READ);
                    199:                if (rf == NULL)
                    200:                        return (CVS_EX_DATA);
                    201:        }
1.5       jfb       202:
1.16      jfb       203:        buf[0] = '\0';
1.30      xsa       204:        if (cf->cf_cvstat == CVS_FST_LOST || cf->cf_cvstat == CVS_FST_UNKNOWN)
1.27      xsa       205:                strlcpy(buf, "no file ", sizeof(buf));
1.22      jfb       206:        strlcat(buf, cf->cf_name, sizeof(buf));
1.16      jfb       207:
1.28      xsa       208:        cvs_printf(CVS_STATUS_SEP "\nFile: %-17s\tStatus: %s\n\n",
1.22      jfb       209:            buf, cvs_statstr[cf->cf_cvstat]);
1.16      jfb       210:
1.22      jfb       211:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.32      joris     212:                len = snprintf(buf, sizeof(buf), "No entry for %s",
                    213:                    cf->cf_name);
1.37      xsa       214:        } else if (cf->cf_cvstat == CVS_FST_ADDED) {
                    215:                len = snprintf(buf, sizeof(buf), "New file!");
1.16      jfb       216:        } else {
1.37      xsa       217:                rcsnum_tostr(cf->cf_lrev, numbuf, sizeof(numbuf));
                    218:                len = snprintf(buf, sizeof(buf), "%s", numbuf);
1.35      xsa       219:
                    220:                /* Display etime in local mode only. */
                    221:                if (cvs_cmdop != CVS_OP_SERVER) {
                    222:                        strlcat(buf, "\t", sizeof(buf));
                    223:
                    224:                        ctime_r(&(cf->cf_etime), timebuf);
                    225:                        n = strlen(timebuf);
                    226:                        if ((n > 0) && (timebuf[n - 1] == '\n'))
1.36      xsa       227:                                timebuf[--n] = '\0';
1.35      xsa       228:
                    229:                        strlcat(buf, timebuf, sizeof(buf));
                    230:                }
1.16      jfb       231:        }
1.32      joris     232:
1.34      joris     233:        if (len == -1 || len >= (int)sizeof(buf)) {
                    234:                if (rf != NULL)
                    235:                        rcs_close(rf);
1.32      joris     236:                return (CVS_EX_DATA);
1.34      joris     237:        }
1.15      jfb       238:
1.28      xsa       239:        cvs_printf("   Working revision:\t%s\n", buf);
1.30      xsa       240:
1.37      xsa       241:        if (cf->cf_cvstat == CVS_FST_UNKNOWN ||
                    242:            cf->cf_cvstat == CVS_FST_ADDED) {
                    243:                len = snprintf(buf, sizeof(buf), "No revision control file");
1.30      xsa       244:        } else {
1.34      joris     245:                len = snprintf(buf, sizeof(buf), "%s\t%s",
1.30      xsa       246:                    rcsnum_tostr(rf->rf_head, numbuf, sizeof(numbuf)),
                    247:                    rcspath);
1.34      joris     248:        }
                    249:
                    250:        if (len == -1 || len >= (int)sizeof(buf)) {
                    251:                if (rf != NULL)
                    252:                        rcs_close(rf);
                    253:                return (CVS_EX_DATA);
1.30      xsa       254:        }
                    255:
                    256:        cvs_printf("   Repository revision:\t%s\n", buf);
                    257:
                    258:        /* If the file is unknown, no other output is needed after this. */
1.37      xsa       259:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    260:                cvs_printf("\n");
1.30      xsa       261:                return (0);
1.37      xsa       262:        }
1.30      xsa       263:
1.38      xsa       264:        if (cf->cf_tag != NULL)
                    265:                cvs_printf("   Sticky Tag:\t\t%s\n", cf->cf_tag);
                    266:        else if (verbosity > 0)
                    267:                cvs_printf("   Sticky Tag:\t\t(none)\n");
                    268:
                    269:        /* XXX */
                    270:        if (verbosity > 0)
                    271:                cvs_printf("   Sticky Date:\t\t%s\n", "(none)");
                    272:
                    273:        if (cf->cf_opts != NULL)
                    274:                cvs_printf("   Sticky Options:\t%s\n", cf->cf_opts);
                    275:        else if (verbosity > 0)
                    276:                cvs_printf("   Sticky Options:\t(none)\n");
1.15      jfb       277:
1.25      xsa       278:        cvs_printf("\n");
1.15      jfb       279:        rcs_close(rf);
                    280:
                    281:        return (0);
1.1       jfb       282: }