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

1.30    ! xsa         1: /*     $OpenBSD: status.c,v 1.29 2005/07/06 09:52:16 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:
                     45:
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: };
                     56:
                     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.30    ! xsa       180:        char buf[MAXNAMLEN], fpath[MAXPATHLEN], numbuf[64], rcspath[MAXPATHLEN];
1.28      xsa       181:        char *repo;
1.15      jfb       182:        RCSFILE *rf;
                    183:        struct cvsroot *root;
                    184:
1.22      jfb       185:        if (cf->cf_type == DT_DIR)
1.15      jfb       186:                return (0);
                    187:
1.22      jfb       188:        root = CVS_DIR_ROOT(cf);
                    189:        repo = CVS_DIR_REPO(cf);
1.1       jfb       190:
1.22      jfb       191:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1       jfb       192:
1.22      jfb       193:        len = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
                    194:            root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
                    195:        if (len == -1 || len >= (int)sizeof(rcspath)) {
1.18      xsa       196:                errno = ENAMETOOLONG;
                    197:                cvs_log(LP_ERRNO, "%s", rcspath);
1.21      joris     198:                return (CVS_EX_DATA);
1.18      xsa       199:        }
1.1       jfb       200:
1.30    ! xsa       201:        if (cf->cf_cvstat != CVS_FST_UNKNOWN) {
        !           202:                rf = rcs_open(rcspath, RCS_READ);
        !           203:                if (rf == NULL)
        !           204:                        return (CVS_EX_DATA);
        !           205:        }
1.5       jfb       206:
1.16      jfb       207:        buf[0] = '\0';
1.30    ! xsa       208:        if (cf->cf_cvstat == CVS_FST_LOST || cf->cf_cvstat == CVS_FST_UNKNOWN)
1.27      xsa       209:                strlcpy(buf, "no file ", sizeof(buf));
1.22      jfb       210:        strlcat(buf, cf->cf_name, sizeof(buf));
1.16      jfb       211:
1.28      xsa       212:        cvs_printf(CVS_STATUS_SEP "\nFile: %-17s\tStatus: %s\n\n",
1.22      jfb       213:            buf, cvs_statstr[cf->cf_cvstat]);
1.16      jfb       214:
1.22      jfb       215:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    216:                snprintf(buf, sizeof(buf), "No entry for %s", cf->cf_name);
1.16      jfb       217:        } else {
1.24      joris     218:                snprintf(buf, sizeof(buf), "%s",
                    219:                    rcsnum_tostr(cf->cf_lrev, buf, sizeof(buf)));
1.16      jfb       220:        }
1.15      jfb       221:
1.28      xsa       222:        cvs_printf("   Working revision:\t%s\n", buf);
1.30    ! xsa       223:
        !           224:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
        !           225:                snprintf(buf, sizeof(buf), "%s", "No revision control file\n");
        !           226:        } else {
        !           227:                snprintf(buf, sizeof(buf), "%s\t%s",
        !           228:                    rcsnum_tostr(rf->rf_head, numbuf, sizeof(numbuf)),
        !           229:                    rcspath);
        !           230:        }
        !           231:
        !           232:        cvs_printf("   Repository revision:\t%s\n", buf);
        !           233:
        !           234:        /* If the file is unknown, no other output is needed after this. */
        !           235:        if (cf->cf_cvstat == CVS_FST_UNKNOWN)
        !           236:                return (0);
        !           237:
1.28      xsa       238:        cvs_printf("   Sticky Tag:\t\t%s\n",
1.22      jfb       239:            cf->cf_tag == NULL ? "(none)" : cf->cf_tag);
1.28      xsa       240:        cvs_printf("   Sticky Date:\t\t%s\n", "(none)");
                    241:        cvs_printf("   Sticky Options:\t%s\n",
1.22      jfb       242:            cf->cf_opts == NULL ? "(none)" : cf->cf_opts);
1.15      jfb       243:
1.25      xsa       244:        cvs_printf("\n");
1.15      jfb       245:        rcs_close(rf);
                    246:
                    247:        return (0);
1.1       jfb       248: }