[BACK]Return to annotate.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/annotate.c, Revision 1.6

1.6     ! xsa         1: /*     $OpenBSD: annotate.c,v 1.5 2005/03/30 17:43:04 joris Exp $      */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     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
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27: #include <sys/param.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 "rcs.h"
                     40: #include "log.h"
                     41: #include "proto.h"
                     42:
                     43:
1.5       joris      44: int cvs_annotate_file(CVSFILE *, void *);
                     45: int cvs_annotate_prune(CVSFILE *, void *);
                     46: int cvs_annotate_options(char *, int, char **, int *);
                     47: int cvs_annotate_sendflags(struct cvsroot *);
                     48:
                     49: struct cvs_cmd_info cvs_annotate = {
                     50:        cvs_annotate_options,
                     51:        cvs_annotate_sendflags,
                     52:        cvs_annotate_file,
                     53:        NULL, NULL,
                     54:        CF_SORT | CF_RECURSE | CF_IGNORE | CF_NOSYMS,
                     55:        CVS_REQ_ANNOTATE,
                     56:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     57: };
1.1       jfb        58:
1.5       joris      59: static char *date, *rev;
                     60: static int usehead;
1.1       jfb        61:
                     62: int
1.5       joris      63: cvs_annotate_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        64: {
1.5       joris      65:        int ch;
1.1       jfb        66:
1.4       jfb        67:        usehead = 0;
1.1       jfb        68:        date = NULL;
                     69:        rev = NULL;
                     70:
1.4       jfb        71:        while ((ch = getopt(argc, argv, "D:flRr:")) != -1) {
1.1       jfb        72:                switch (ch) {
                     73:                case 'D':
                     74:                        date = optarg;
                     75:                        break;
1.4       jfb        76:                case 'f':
                     77:                        usehead = 1;
                     78:                        break;
1.1       jfb        79:                case 'l':
1.5       joris      80:                        cvs_annotate.file_flags &= ~CF_RECURSE;
1.1       jfb        81:                        break;
                     82:                case 'R':
1.5       joris      83:                        cvs_annotate.file_flags |= CF_RECURSE;
1.1       jfb        84:                        break;
                     85:                case 'r':
1.4       jfb        86:                        rev = optarg;
1.1       jfb        87:                        break;
                     88:                default:
                     89:                        return (EX_USAGE);
                     90:                }
                     91:        }
                     92:
1.4       jfb        93:        if ((date != NULL) && (rev != NULL)) {
                     94:                cvs_log(LP_ERR,
                     95:                    "the -D and -d arguments are mutually exclusive");
                     96:                return (EX_USAGE);
                     97:        }
                     98:
1.5       joris      99:        *arg = optind;
                    100:        return (0);
                    101: }
1.1       jfb       102:
1.5       joris     103: int
                    104: cvs_annotate_sendflags(struct cvsroot *root)
                    105: {
                    106:        if (usehead && (cvs_sendarg(root, "-f", 0) < 0))
1.6     ! xsa       107:                return (-1);
1.2       jfb       108:
1.5       joris     109:        if (rev != NULL) {
                    110:                if ((cvs_sendarg(root, "-r", 0) < 0) ||
                    111:                    (cvs_sendarg(root, rev, 0) < 0))
1.6     ! xsa       112:                        return (-1);
1.1       jfb       113:        }
                    114:
1.5       joris     115:        if (date != NULL) {
                    116:                if ((cvs_sendarg(root, "-D", 0) < 0) ||
                    117:                    (cvs_sendarg(root, date, 0) < 0))
1.6     ! xsa       118:                        return (-1);
1.1       jfb       119:        }
                    120:
                    121:        return (0);
                    122: }
                    123:
                    124: /*
                    125:  * cvs_annotate_file()
                    126:  *
                    127:  * Annotate a single file.
                    128:  */
                    129: int
                    130: cvs_annotate_file(CVSFILE *cf, void *arg)
                    131: {
1.2       jfb       132:        int ret;
1.1       jfb       133:        char fpath[MAXPATHLEN];
                    134:        struct cvsroot *root;
                    135:        struct cvs_ent *entp;
                    136:
1.2       jfb       137:        ret = 0;
                    138:        root = CVS_DIR_ROOT(cf);
1.1       jfb       139:
1.3       jfb       140:        if (cf->cf_type == DT_DIR) {
                    141:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    142:                        if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    143:                                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    144:                                    CVS_FILE_NAME(cf));
                    145:                        else
                    146:                                ret = cvs_senddir(root, cf);
                    147:                }
                    148:
1.2       jfb       149:                return (ret);
1.1       jfb       150:        }
                    151:
1.2       jfb       152:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.1       jfb       153:        entp = cvs_ent_getent(fpath);
                    154:
                    155:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.2       jfb       156:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
                    157:                        cvs_ent_free(entp);
                    158:                        return (-1);
                    159:                }
                    160:
1.1       jfb       161:                switch (cf->cf_cvstat) {
1.2       jfb       162:                case CVS_FST_UNKNOWN:
                    163:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    164:                            CVS_FILE_NAME(cf));
                    165:                        break;
1.1       jfb       166:                case CVS_FST_UPTODATE:
1.2       jfb       167:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
                    168:                            CVS_FILE_NAME(cf));
1.1       jfb       169:                        break;
                    170:                case CVS_FST_ADDED:
                    171:                case CVS_FST_MODIFIED:
1.2       jfb       172:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
1.1       jfb       173:                            CVS_FILE_NAME(cf));
                    174:                        break;
                    175:                default:
1.2       jfb       176:                        break;
                    177:                }
                    178:        } else {
                    179:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    180:                        cvs_printf("? %s\n", fpath);
                    181:                        return (0);
1.1       jfb       182:                }
                    183:        }
                    184:
                    185:        if (entp != NULL)
                    186:                cvs_ent_free(entp);
1.2       jfb       187:        return (ret);
1.1       jfb       188: }