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

1.21    ! joris       1: /*     $OpenBSD: status.c,v 1.20 2005/04/27 04:54:46 jfb 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.16      jfb        54:        "Needs Checkout",
1.1       jfb        55: };
                     56:
                     57:
1.20      jfb        58: int cvs_status_remote    (CVSFILE *, void *);
1.15      jfb        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,
1.20      jfb        66:        cvs_status_remote,
1.10      joris      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: /*
1.20      jfb       109:  * cvs_status_remote()
1.1       jfb       110:  *
                    111:  * Get the status of a single file.
                    112:  */
                    113: int
1.20      jfb       114: cvs_status_remote(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 cvsroot *root;
                    120:
1.5       jfb       121:        ret = 0;
1.1       jfb       122:        rf = NULL;
1.5       jfb       123:        root = CVS_DIR_ROOT(cfp);
                    124:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       125:
1.6       jfb       126:        if (cfp->cf_type == DT_DIR) {
1.15      jfb       127:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
                    128:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    129:                            CVS_FILE_NAME(cfp));
                    130:                else
                    131:                        ret = cvs_senddir(root, cfp);
1.21    ! joris     132:
        !           133:                if (ret == -1)
        !           134:                        ret = CVS_EX_PROTO;
        !           135:
1.6       jfb       136:                return (ret);
                    137:        }
1.1       jfb       138:
1.5       jfb       139:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.1       jfb       140:
1.21    ! joris     141:        if (cvs_sendentry(root, cfp) < 0)
        !           142:                return (CVS_EX_PROTO);
1.15      jfb       143:
                    144:        switch (cfp->cf_cvstat) {
                    145:        case CVS_FST_UNKNOWN:
1.20      jfb       146:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cfp->cf_name);
1.15      jfb       147:                break;
                    148:        case CVS_FST_UPTODATE:
1.20      jfb       149:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cfp->cf_name);
1.15      jfb       150:                break;
1.17      joris     151:        case CVS_FST_ADDED:
1.15      jfb       152:        case CVS_FST_MODIFIED:
1.20      jfb       153:                ret = cvs_sendreq(root, CVS_REQ_MODIFIED, cfp->cf_name);
1.15      jfb       154:                if (ret == 0)
                    155:                        ret = cvs_sendfile(root, fpath);
                    156:        default:
                    157:                break;
                    158:        }
                    159:
1.21    ! joris     160:        if (ret == -1)
        !           161:                ret = CVS_EX_PROTO;
        !           162:
1.15      jfb       163:        return (ret);
                    164: }
                    165:
                    166: int
                    167: cvs_status_local(CVSFILE *cfp, void *arg)
                    168: {
1.18      xsa       169:        int l;
1.16      jfb       170:        char *repo, buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.15      jfb       171:        RCSFILE *rf;
                    172:        struct cvsroot *root;
                    173:
                    174:        if (cfp->cf_type == DT_DIR)
                    175:                return (0);
                    176:
                    177:        root = CVS_DIR_ROOT(cfp);
                    178:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       179:
1.15      jfb       180:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.1       jfb       181:
1.15      jfb       182:        if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
                    183:                cvs_log(LP_WARN, "I know nothing about %s", fpath);
                    184:                return (0);
                    185:        }
1.1       jfb       186:
1.18      xsa       187:        l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.15      jfb       188:            root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.18      xsa       189:        if (l == -1 || l >= (int)sizeof(rcspath)) {
                    190:                errno = ENAMETOOLONG;
                    191:                cvs_log(LP_ERRNO, "%s", rcspath);
1.21    ! joris     192:                return (CVS_EX_DATA);
1.18      xsa       193:        }
1.1       jfb       194:
1.15      jfb       195:        rf = rcs_open(rcspath, RCS_READ);
1.21    ! joris     196:        if (rf == NULL)
        !           197:                return (CVS_EX_DATA);
1.5       jfb       198:
1.16      jfb       199:        buf[0] = '\0';
                    200:        if (cfp->cf_cvstat == CVS_FST_LOST)
                    201:                strlcpy(buf, "No file ", sizeof(buf));
                    202:        strlcat(buf, CVS_FILE_NAME(cfp), sizeof(buf));
                    203:
1.15      jfb       204:        cvs_printf(CVS_STATUS_SEP "\nFile: %-18sStatus: %s\n\n",
1.16      jfb       205:            buf, cvs_statstr[cfp->cf_cvstat]);
                    206:
1.20      jfb       207:        if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
1.16      jfb       208:                snprintf(buf, sizeof(buf), "No entry for %s",
                    209:                    CVS_FILE_NAME(cfp));
                    210:        } else {
                    211:                snprintf(buf, sizeof(buf), "%s %s",
1.20      jfb       212:                    rcsnum_tostr(cfp->cf_lrev, buf, sizeof(buf)),
1.16      jfb       213:                    "date here");
                    214:        }
1.15      jfb       215:
1.16      jfb       216:        cvs_printf("   Working revision:    %s\n", buf);
                    217:        rcsnum_tostr(rf->rf_head, buf, sizeof(buf));
                    218:        cvs_printf("   Repository revision: %s %s\n", buf, rcspath);
1.15      jfb       219:        cvs_printf("   Sticky Tag:          %s\n", "(none)");
                    220:        cvs_printf("   Sticky Date:         %s\n", "(none)");
                    221:        cvs_printf("   Sticky Options:      %s\n", "(none)");
                    222:
                    223:        rcs_close(rf);
                    224:
                    225:        return (0);
1.1       jfb       226: }