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

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