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

Annotation of src/usr.bin/cvs/watch.c, Revision 1.11

1.11    ! xsa         1: /*     $OpenBSD: watch.c,v 1.10 2005/12/31 13:27:51 xsa Exp $  */
1.1       xsa         2: /*
                      3:  * Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
1.7       moritz      4:  * Copyright (c) 2005 Moritz Jodeit <moritz@openbsd.org>
1.1       xsa         5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  *
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. The name of the author may not be used to endorse or promote products
                     14:  *    derived from this software without specific prior written permission.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     17:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     18:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     19:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     20:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     21:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     22:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     23:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     24:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     25:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
1.11    ! xsa        28: #include "includes.h"
1.1       xsa        29:
                     30: #include "cvs.h"
                     31: #include "log.h"
                     32: #include "proto.h"
                     33:
1.5       xsa        34: static int     cvs_watch_init(struct cvs_cmd *, int, char **, int *);
1.7       moritz     35: static int     cvs_watch_pre_exec(struct cvsroot *);
1.5       xsa        36: static int     cvs_watch_remote(CVSFILE *, void*);
                     37: static int     cvs_watch_local(CVSFILE *, void*);
1.1       xsa        38:
1.7       moritz     39: static int     cvs_watchers_init(struct cvs_cmd *, int, char **, int *);
1.5       xsa        40: static int     cvs_watchers_local(CVSFILE *, void*);
1.1       xsa        41:
                     42:
                     43: struct cvs_cmd cvs_cmd_watch = {
                     44:        CVS_OP_WATCH, CVS_REQ_NOOP, "watch",
                     45:        {},
1.3       xsa        46:        "Set watches",
1.1       xsa        47:        "on | off | add | remove [-lR] [-a action] [file ...]",
                     48:        "a:lR",
                     49:        NULL,
1.7       moritz     50:        CF_SORT | CF_IGNORE | CF_RECURSE,
1.1       xsa        51:        cvs_watch_init,
1.7       moritz     52:        cvs_watch_pre_exec,
1.1       xsa        53:        cvs_watch_remote,
                     54:        cvs_watch_local,
                     55:        NULL,
                     56:        NULL,
1.7       moritz     57:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
1.1       xsa        58: };
                     59:
                     60: struct cvs_cmd cvs_cmd_watchers = {
1.4       joris      61:        CVS_OP_WATCHERS, CVS_REQ_WATCHERS, "watchers",
                     62:        {},
                     63:        "See who is watching a file",
                     64:        "[-lR] [file ...]",
                     65:        "lR",
                     66:        NULL,
1.7       moritz     67:        CF_SORT | CF_IGNORE | CF_RECURSE,
                     68:        cvs_watchers_init,
1.4       joris      69:        NULL,
1.7       moritz     70:        cvs_watch_remote,
1.4       joris      71:        cvs_watchers_local,
                     72:        NULL,
                     73:        NULL,
1.6       xsa        74:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
1.1       xsa        75: };
                     76:
                     77:
1.7       moritz     78: static char *aoptstr = NULL;
                     79: static int watchreq = 0;
1.1       xsa        80:
                     81: static int
                     82: cvs_watch_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
                     83: {
                     84:        int ch;
1.4       joris      85:
1.7       moritz     86:        if (argc < 2)
                     87:                return (CVS_EX_USAGE);
                     88:
                     89:        if (strcmp(argv[1], "on") == 0)
                     90:                watchreq = CVS_REQ_WATCH_ON;
                     91:        else if (strcmp(argv[1], "off") == 0)
                     92:                watchreq = CVS_REQ_WATCH_OFF;
                     93:        else if (strcmp(argv[1], "add") == 0)
                     94:                watchreq = CVS_REQ_WATCH_ADD;
                     95:        else if (strcmp(argv[1], "remove") == 0)
                     96:                watchreq = CVS_REQ_WATCH_REMOVE;
                     97:        else
                     98:                return (CVS_EX_USAGE);
                     99:
                    100:        cmd->cmd_req = watchreq;
                    101:        optind = 2;
                    102:
1.1       xsa       103:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
                    104:                switch (ch) {
                    105:                case 'a':
1.2       xsa       106:                        /*
1.7       moritz    107:                         * Only `watch add | remove' support the -a option.
                    108:                         * Check which command has been issued.
1.2       xsa       109:                         */
1.10      xsa       110:                        if ((watchreq != CVS_REQ_WATCH_ADD) &&
                    111:                            (watchreq != CVS_REQ_WATCH_REMOVE))
1.7       moritz    112:                                return (CVS_EX_USAGE);
1.10      xsa       113:                        if ((strcmp(optarg, "commit") != 0) &&
                    114:                            (strcmp(optarg, "edit") != 0) &&
                    115:                            (strcmp(optarg, "unedit") != 0) &&
                    116:                            (strcmp(optarg, "all") != 0) &&
                    117:                            (strcmp(optarg, "none") != 0))
1.1       xsa       118:                                return (CVS_EX_USAGE);
1.8       joris     119:                        aoptstr = xstrdup(optarg);
1.1       xsa       120:                        break;
                    121:                case 'l':
                    122:                        cmd->file_flags &= ~CF_RECURSE;
                    123:                        break;
                    124:                case 'R':
                    125:                        cmd->file_flags |= CF_RECURSE;
                    126:                        break;
                    127:                default:
                    128:                        return (CVS_EX_USAGE);
                    129:                }
                    130:        }
                    131:
                    132:        *arg = optind;
                    133:        return (CVS_EX_OK);
                    134: }
                    135:
                    136:
                    137: /*
1.7       moritz    138:  * cvs_watch_pre_exec()
1.1       xsa       139:  *
                    140:  */
                    141: static int
1.7       moritz    142: cvs_watch_pre_exec(struct cvsroot *root)
1.1       xsa       143: {
1.7       moritz    144:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.10      xsa       145:                if ((watchreq != CVS_REQ_WATCH_ADD) &&
                    146:                    (watchreq != CVS_REQ_WATCH_REMOVE))
1.7       moritz    147:                        return (CVS_EX_OK);
                    148:
                    149:                if (aoptstr == NULL || strcmp(aoptstr, "all") == 0) {
                    150:                        /* Defaults to: edit, unedit, commit */
1.9       joris     151:                        cvs_sendarg(root, "-a", 0);
                    152:                        cvs_sendarg(root, "edit", 0);
                    153:                        cvs_sendarg(root, "-a", 0);
                    154:                        cvs_sendarg(root, "unedit", 0);
                    155:                        cvs_sendarg(root, "-a", 0);
                    156:                        cvs_sendarg(root, "commit", 0);
1.7       moritz    157:                } else {
1.9       joris     158:                        cvs_sendarg(root, "-a", 0);
                    159:                        cvs_sendarg(root, aoptstr, 0);
1.7       moritz    160:                }
                    161:        }
1.9       joris     162:
1.8       joris     163:        xfree(aoptstr);
1.7       moritz    164:
1.1       xsa       165:        return (CVS_EX_OK);
                    166: }
                    167:
                    168:
                    169: /*
                    170:  * cvs_watch_local()
                    171:  *
                    172:  */
                    173: static int
1.6       xsa       174: cvs_watch_local(CVSFILE *cf, void *arg)
1.1       xsa       175: {
                    176:        return (CVS_EX_OK);
                    177: }
                    178:
                    179:
                    180: /*
1.7       moritz    181:  * cvs_watch_remote()
1.1       xsa       182:  *
                    183:  */
                    184: static int
1.7       moritz    185: cvs_watch_remote(CVSFILE *cf, void *arg)
1.1       xsa       186: {
1.6       xsa       187:        struct cvsroot *root;
                    188:
                    189:        root = CVS_DIR_ROOT(cf);
                    190:
                    191:        if (cf->cf_type == DT_DIR) {
                    192:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
1.9       joris     193:                        cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.6       xsa       194:                else
1.9       joris     195:                        cvs_senddir(root, cf);
                    196:                return (0);
1.6       xsa       197:        }
                    198:
1.9       joris     199:        cvs_sendentry(root, cf);
1.6       xsa       200:
                    201:        switch (cf->cf_cvstat) {
                    202:        case CVS_FST_UNKNOWN:
1.9       joris     203:                cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.6       xsa       204:                break;
                    205:        case CVS_FST_UPTODATE:
1.9       joris     206:                cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.6       xsa       207:                break;
                    208:        case CVS_FST_ADDED:
                    209:        case CVS_FST_MODIFIED:
1.9       joris     210:                cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.6       xsa       211:                break;
                    212:        default:
                    213:                break;
                    214:        }
                    215:
1.9       joris     216:        return (0);
1.1       xsa       217: }
1.7       moritz    218:
                    219:
                    220: /*
                    221:  * cvs_watchers_init()
                    222:  *
                    223:  */
                    224: static int
                    225: cvs_watchers_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
                    226: {
                    227:        int ch;
                    228:
                    229:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
                    230:                switch (ch) {
                    231:                case 'l':
                    232:                        cmd->file_flags &= ~CF_RECURSE;
                    233:                        break;
                    234:                case 'R':
                    235:                        cmd->file_flags |= CF_RECURSE;
                    236:                        break;
                    237:                default:
                    238:                        return (CVS_EX_USAGE);
                    239:                }
                    240:        }
                    241:
                    242:        *arg = optind;
                    243:        return (CVS_EX_OK);
                    244: }
                    245:
1.4       joris     246:
1.1       xsa       247: /*
                    248:  * cvs_watchers_local()
                    249:  *
                    250:  */
                    251: static int
1.6       xsa       252: cvs_watchers_local(CVSFILE *cf, void *arg)
1.1       xsa       253: {
                    254:        return (CVS_EX_OK);
                    255: }