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

1.12    ! joris       1: /*     $OpenBSD: status.c,v 1.11 2005/04/03 17:32:50 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>
                     31: #include <stdio.h>
                     32: #include <fcntl.h>
                     33: #include <stdlib.h>
                     34: #include <unistd.h>
                     35: #include <string.h>
                     36: #include <sysexits.h>
                     37:
                     38: #include "cvs.h"
                     39: #include "log.h"
                     40: #include "proto.h"
                     41:
                     42:
                     43: const char *cvs_statstr[] = {
                     44:        "Unknown",
                     45:        "Up to date",
                     46:        "Locally Modified",
                     47:        "Added",
                     48:        "Removed",
                     49:        "Conflict",
                     50:        "Patched",
                     51: };
                     52:
                     53:
1.10      joris      54: int cvs_status_file(CVSFILE *, void *);
                     55: int cvs_status_options(char *, int, char **, int *);
                     56: int cvs_status_sendflags(struct cvsroot *);
                     57:
                     58: struct cvs_cmd_info cvs_status = {
                     59:        cvs_status_options,
                     60:        cvs_status_sendflags,
                     61:        cvs_status_file,
                     62:        NULL, NULL,
                     63:        CF_SORT | CF_IGNORE | CF_RECURSE,
                     64:        CVS_REQ_STATUS,
                     65:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     66: };
1.1       jfb        67:
1.10      joris      68: static int verbose = 0;
1.1       jfb        69:
                     70: int
1.10      joris      71: cvs_status_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        72: {
1.10      joris      73:        int ch;
1.1       jfb        74:
1.10      joris      75:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        76:                switch (ch) {
1.7       jfb        77:                case 'l':
1.10      joris      78:                        cvs_status.file_flags &= ~CF_RECURSE;
1.7       jfb        79:                        break;
                     80:                case 'R':
1.10      joris      81:                        cvs_status.file_flags |= CF_RECURSE;
1.7       jfb        82:                        break;
                     83:                case 'v':
                     84:                        verbose = 1;
                     85:                        break;
1.1       jfb        86:                default:
1.12    ! joris      87:                        return (1);
1.1       jfb        88:                }
                     89:        }
                     90:
1.10      joris      91:        *arg = optind;
                     92:        return (0);
                     93: }
1.1       jfb        94:
1.10      joris      95: int
                     96: cvs_status_sendflags(struct cvsroot *root)
                     97: {
                     98:        if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
1.11      xsa        99:                return (-1);
1.1       jfb       100:        return (0);
                    101: }
                    102:
                    103: /*
                    104:  * cvs_status_file()
                    105:  *
                    106:  * Get the status of a single file.
                    107:  */
                    108: int
1.2       jfb       109: cvs_status_file(CVSFILE *cfp, void *arg)
1.1       jfb       110: {
1.5       jfb       111:        int ret;
1.2       jfb       112:        char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.1       jfb       113:        RCSFILE *rf;
                    114:        struct cvs_ent *entp;
                    115:        struct cvsroot *root;
                    116:
1.5       jfb       117:        ret = 0;
1.1       jfb       118:        rf = NULL;
1.5       jfb       119:        root = CVS_DIR_ROOT(cfp);
                    120:        repo = CVS_DIR_REPO(cfp);
1.1       jfb       121:
1.6       jfb       122:        if (cfp->cf_type == DT_DIR) {
                    123:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    124:                        if (cfp->cf_cvstat == CVS_FST_UNKNOWN)
                    125:                                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    126:                                    CVS_FILE_NAME(cfp));
                    127:                        else
                    128:                                ret = cvs_senddir(root, cfp);
                    129:                }
                    130:
                    131:                return (ret);
                    132:        }
1.1       jfb       133:
1.5       jfb       134:        cvs_file_getpath(cfp, fpath, sizeof(fpath));
1.2       jfb       135:        entp = cvs_ent_getent(fpath);
1.1       jfb       136:
                    137:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.5       jfb       138:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
1.1       jfb       139:                        cvs_ent_free(entp);
                    140:                        return (-1);
                    141:                }
                    142:
1.5       jfb       143:                switch (cfp->cf_cvstat) {
                    144:                case CVS_FST_UNKNOWN:
                    145:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    146:                            CVS_FILE_NAME(cfp));
                    147:                        break;
                    148:                case CVS_FST_UPTODATE:
                    149:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
                    150:                            CVS_FILE_NAME(cfp));
                    151:                        break;
                    152:                case CVS_FST_MODIFIED:
                    153:                        ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
1.2       jfb       154:                            CVS_FILE_NAME(cfp));
1.5       jfb       155:                        if (ret == 0)
                    156:                                ret = cvs_sendfile(root, fpath);
                    157:                default:
                    158:                        break;
                    159:                }
                    160:        } else {
                    161:                if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
                    162:                        cvs_log(LP_WARN, "I know nothing about %s", fpath);
                    163:                        return (0);
                    164:                }
1.1       jfb       165:
                    166:                snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.2       jfb       167:                    root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
1.1       jfb       168:
1.8       jfb       169:                rf = rcs_open(rcspath, RCS_READ);
1.1       jfb       170:                if (rf == NULL) {
1.9       tedu      171:                        if (entp != NULL)
                    172:                                cvs_ent_free(entp);
1.1       jfb       173:                        return (-1);
                    174:                }
                    175:
                    176:                rcs_close(rf);
                    177:        }
1.5       jfb       178:
                    179:        if (entp != NULL)
                    180:                cvs_ent_free(entp);
                    181:        return (ret);
1.1       jfb       182: }