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

1.27    ! xsa         1: /*     $OpenBSD: status.c,v 1.26 2005/06/30 15:24:53 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",
                     50:        "Added",
                     51:        "Removed",
                     52:        "Conflict",
                     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.16      jfb       180:        char *repo, buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.15      jfb       181:        RCSFILE *rf;
                    182:        struct cvsroot *root;
                    183:
1.22      jfb       184:        if (cf->cf_type == DT_DIR)
1.15      jfb       185:                return (0);
                    186:
1.22      jfb       187:        root = CVS_DIR_ROOT(cf);
                    188:        repo = CVS_DIR_REPO(cf);
1.1       jfb       189:
1.22      jfb       190:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1       jfb       191:
1.22      jfb       192:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.15      jfb       193:                cvs_log(LP_WARN, "I know nothing about %s", fpath);
                    194:                return (0);
                    195:        }
1.1       jfb       196:
1.22      jfb       197:        len = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
                    198:            root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
                    199:        if (len == -1 || len >= (int)sizeof(rcspath)) {
1.18      xsa       200:                errno = ENAMETOOLONG;
                    201:                cvs_log(LP_ERRNO, "%s", rcspath);
1.21      joris     202:                return (CVS_EX_DATA);
1.18      xsa       203:        }
1.1       jfb       204:
1.15      jfb       205:        rf = rcs_open(rcspath, RCS_READ);
1.21      joris     206:        if (rf == NULL)
                    207:                return (CVS_EX_DATA);
1.5       jfb       208:
1.16      jfb       209:        buf[0] = '\0';
1.22      jfb       210:        if (cf->cf_cvstat == CVS_FST_LOST)
1.27    ! xsa       211:                strlcpy(buf, "no file ", sizeof(buf));
1.22      jfb       212:        strlcat(buf, cf->cf_name, sizeof(buf));
1.16      jfb       213:
1.15      jfb       214:        cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
1.22      jfb       215:            buf, cvs_statstr[cf->cf_cvstat]);
1.16      jfb       216:
1.22      jfb       217:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    218:                snprintf(buf, sizeof(buf), "No entry for %s", cf->cf_name);
1.16      jfb       219:        } else {
1.24      joris     220:                snprintf(buf, sizeof(buf), "%s",
                    221:                    rcsnum_tostr(cf->cf_lrev, buf, sizeof(buf)));
1.16      jfb       222:        }
1.15      jfb       223:
1.16      jfb       224:        cvs_printf("   Working revision:    %s\n", buf);
                    225:        rcsnum_tostr(rf->rf_head, buf, sizeof(buf));
                    226:        cvs_printf("   Repository revision: %s %s\n", buf, rcspath);
1.22      jfb       227:        cvs_printf("   Sticky Tag:          %s\n",
                    228:            cf->cf_tag == NULL ? "(none)" : cf->cf_tag);
1.15      jfb       229:        cvs_printf("   Sticky Date:         %s\n", "(none)");
1.22      jfb       230:        cvs_printf("   Sticky Options:      %s\n",
                    231:            cf->cf_opts == NULL ? "(none)" : cf->cf_opts);
1.15      jfb       232:
1.25      xsa       233:        cvs_printf("\n");
1.15      jfb       234:        rcs_close(rf);
                    235:
                    236:        return (0);
1.1       jfb       237: }