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

1.23    ! joris       1: /*     $OpenBSD: watch.c,v 1.22 2011/12/27 13:59:01 nicm Exp $ */
1.1       xsa         2: /*
1.15      xsa         3:  * Copyright (c) 2005-2007 Xavier Santolaria <xsa@openbsd.org>
1.1       xsa         4:  *
1.14      xsa         5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       xsa        16:  */
                     17:
1.17      otto       18: #include <string.h>
                     19: #include <unistd.h>
1.1       xsa        20:
                     21: #include "cvs.h"
1.14      xsa        22: #include "remote.h"
1.1       xsa        23:
1.15      xsa        24: #define W_COMMIT       0x01
                     25: #define W_EDIT         0x02
                     26: #define W_UNEDIT       0x04
                     27: #define W_ADD          0x08
                     28: #define W_REMOVE       0x10
                     29: #define W_ON           0x20
                     30: #define W_OFF          0x40
                     31: #define W_ALL          (W_EDIT|W_COMMIT|W_UNEDIT)
                     32:
                     33: static void    cvs_watch_local(struct cvs_file *);
1.14      xsa        34: static void    cvs_watchers_local(struct cvs_file *);
1.1       xsa        35:
1.15      xsa        36: struct cvs_cmd cvs_cmd_watch = {
1.20      tobias     37:        CVS_OP_WATCH, CVS_USE_WDIR, "watch",
1.21      ragge      38:        { { 0 }, { 0 } },
1.15      xsa        39:        "Set watches",
                     40:        "on | off | add | remove [-lR] [-a action] [file ...]",
                     41:        "a:lR",
                     42:        NULL,
                     43:        cvs_watch
                     44: };
                     45:
1.1       xsa        46: struct cvs_cmd cvs_cmd_watchers = {
1.20      tobias     47:        CVS_OP_WATCHERS, CVS_USE_WDIR, "watchers",
1.21      ragge      48:        { { 0 }, { 0 } },
1.4       joris      49:        "See who is watching a file",
                     50:        "[-lR] [file ...]",
                     51:        "lR",
                     52:        NULL,
1.14      xsa        53:        cvs_watchers
1.1       xsa        54: };
                     55:
1.14      xsa        56: int
1.15      xsa        57: cvs_watch(int argc, char **argv)
                     58: {
                     59:        int ch, flags;
                     60:        struct cvs_recursion cr;
1.22      nicm       61:        int watch_req = 0;
                     62:        int watch_aflags = 0;
1.15      xsa        63:
                     64:        if (argc < 2)
                     65:                fatal("%s", cvs_cmd_watch.cmd_synopsis);
                     66:
                     67:        if (strcmp(argv[1], "on") == 0)
                     68:                watch_req |= W_ON;
                     69:        else if (strcmp(argv[1], "off") == 0)
                     70:                watch_req |= W_OFF;
                     71:        else if (strcmp(argv[1], "add") == 0)
                     72:                watch_req |= W_ADD;
                     73:        else if (strcmp(argv[1], "remove") == 0)
                     74:                watch_req |= W_REMOVE;
                     75:        else
                     76:                fatal("%s", cvs_cmd_watch.cmd_synopsis);
                     77:
                     78:        --argc;
                     79:        ++argv;
                     80:
                     81:        flags = CR_RECURSE_DIRS;
                     82:
                     83:        while ((ch = getopt(argc, argv, cvs_cmd_watch.cmd_opts)) != -1) {
                     84:                switch (ch) {
                     85:                case 'a':
                     86:                        if (!(watch_req & (W_ADD|W_REMOVE)))
                     87:                                fatal("%s", cvs_cmd_watch.cmd_synopsis);
                     88:
                     89:                        if (strcmp(optarg, "edit") == 0)
                     90:                                watch_aflags |= W_EDIT;
                     91:                        else if (strcmp(optarg, "unedit") == 0)
                     92:                                watch_aflags |= W_UNEDIT;
                     93:                        else if (strcmp(optarg, "commit") == 0)
                     94:                                watch_aflags |= W_COMMIT;
                     95:                        else if (strcmp(optarg, "all") == 0)
                     96:                                watch_aflags |= W_ALL;
                     97:                        else if (strcmp(optarg, "none") == 0)
                     98:                                watch_aflags &= ~W_ALL;
                     99:                        else
                    100:                                fatal("%s", cvs_cmd_watch.cmd_synopsis);
1.18      tobias    101:                        break;
1.15      xsa       102:                case 'l':
                    103:                        flags &= ~CR_RECURSE_DIRS;
                    104:                        break;
                    105:                case 'R':
1.19      tobias    106:                        flags |= CR_RECURSE_DIRS;
1.15      xsa       107:                        break;
                    108:                default:
                    109:                        fatal("%s", cvs_cmd_watch.cmd_synopsis);
                    110:                }
                    111:        }
                    112:
                    113:        argc -= optind;
                    114:        argv += optind;
                    115:
                    116:        if (watch_aflags == 0)
                    117:                watch_aflags |= W_ALL;
                    118:
                    119:        cr.enterdir = NULL;
                    120:        cr.leavedir = NULL;
                    121:
1.23    ! joris     122:        if (cvsroot_is_remote()) {
1.16      joris     123:                cvs_client_connect_to_server();
1.15      xsa       124:                cr.fileproc = cvs_client_sendfile;
                    125:
                    126:                if (watch_req & (W_ADD|W_REMOVE)) {
                    127:                        if (watch_aflags & W_EDIT)
                    128:                                cvs_client_send_request("Argument -a edit");
                    129:
                    130:                        if (watch_aflags & W_UNEDIT)
                    131:                                cvs_client_send_request("Argument -a unedit");
                    132:
                    133:                        if (watch_aflags & W_COMMIT)
                    134:                                cvs_client_send_request("Argument -a commit");
                    135:
                    136:                        if (!(watch_aflags & W_ALL))
                    137:                                cvs_client_send_request("Argument -a none");
                    138:                }
                    139:
                    140:                if (!(flags & CR_RECURSE_DIRS))
                    141:                        cvs_client_send_request("Argument -l");
                    142:        } else {
                    143:                cr.fileproc = cvs_watch_local;
                    144:        }
                    145:
                    146:        cr.flags = flags;
                    147:
                    148:        cvs_file_run(argc, argv, &cr);
                    149:
1.23    ! joris     150:        if (cvsroot_is_remote()) {
1.15      xsa       151:                cvs_client_send_files(argv, argc);
                    152:                cvs_client_senddir(".");
                    153:
                    154:                if (watch_req & (W_ADD|W_REMOVE))
                    155:                        cvs_client_send_request("watch-%s",
                    156:                            (watch_req & W_ADD) ? "add" : "remove");
                    157:                else
                    158:                        cvs_client_send_request("watch-%s",
                    159:                            (watch_req & W_ON) ? "on" : "off");
                    160:
                    161:                cvs_client_get_responses();
                    162:        }
                    163:
                    164:        return (0);
                    165: }
                    166:
                    167: int
1.14      xsa       168: cvs_watchers(int argc, char **argv)
1.1       xsa       169: {
                    170:        int ch;
1.14      xsa       171:        int flags;
                    172:        struct cvs_recursion cr;
1.4       joris     173:
1.14      xsa       174:        flags = CR_RECURSE_DIRS;
1.7       moritz    175:
1.14      xsa       176:        while ((ch = getopt(argc, argv, cvs_cmd_watchers.cmd_opts)) != -1) {
1.1       xsa       177:                switch (ch) {
                    178:                case 'l':
1.14      xsa       179:                        flags &= ~CR_RECURSE_DIRS;
1.1       xsa       180:                        break;
                    181:                case 'R':
1.19      tobias    182:                        flags |= CR_RECURSE_DIRS;
1.1       xsa       183:                        break;
                    184:                default:
1.14      xsa       185:                        fatal("%s", cvs_cmd_watchers.cmd_synopsis);
1.1       xsa       186:                }
                    187:        }
                    188:
1.14      xsa       189:        argc -= optind;
                    190:        argv += optind;
                    191:
                    192:        if (argc == 0)
                    193:                fatal("%s", cvs_cmd_watchers.cmd_synopsis);
1.1       xsa       194:
1.14      xsa       195:        cr.enterdir = NULL;
                    196:        cr.leavedir = NULL;
1.1       xsa       197:
1.23    ! joris     198:        if (cvsroot_is_remote()) {
1.16      joris     199:                cvs_client_connect_to_server();
1.14      xsa       200:                cr.fileproc = cvs_client_sendfile;
                    201:
                    202:                if (!(flags & CR_RECURSE_DIRS))
                    203:                        cvs_client_send_request("Argument -l");
                    204:        } else {
                    205:                cr.fileproc = cvs_watchers_local;
1.7       moritz    206:        }
1.9       joris     207:
1.14      xsa       208:        cr.flags = flags;
1.1       xsa       209:
1.14      xsa       210:        cvs_file_run(argc, argv, &cr);
1.1       xsa       211:
1.23    ! joris     212:        if (cvsroot_is_remote()) {
1.14      xsa       213:                cvs_client_send_files(argv, argc);
                    214:                cvs_client_senddir(".");
                    215:                cvs_client_send_request("watchers");
                    216:                cvs_client_get_responses();
1.6       xsa       217:        }
                    218:
1.9       joris     219:        return (0);
1.15      xsa       220: }
                    221:
                    222: static void
                    223: cvs_watch_local(struct cvs_file *cf)
                    224: {
1.1       xsa       225: }
1.7       moritz    226:
1.14      xsa       227: static void
                    228: cvs_watchers_local(struct cvs_file *cf)
1.1       xsa       229: {
                    230: }