Annotation of src/usr.bin/cvs/watch.c, Revision 1.15
1.15 ! xsa 1: /* $OpenBSD: watch.c,v 1.14 2007/01/02 13:51:13 xsa 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.11 xsa 18: #include "includes.h"
1.1 xsa 19:
20: #include "cvs.h"
21: #include "log.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: static int watch_req = 0;
! 37: static int watch_aflags = 0;
! 38:
! 39: struct cvs_cmd cvs_cmd_watch = {
! 40: CVS_OP_WATCH, 0, "watch",
! 41: { },
! 42: "Set watches",
! 43: "on | off | add | remove [-lR] [-a action] [file ...]",
! 44: "a:lR",
! 45: NULL,
! 46: cvs_watch
! 47: };
! 48:
1.1 xsa 49: struct cvs_cmd cvs_cmd_watchers = {
1.14 xsa 50: CVS_OP_WATCHERS, 0, "watchers",
51: { },
1.4 joris 52: "See who is watching a file",
53: "[-lR] [file ...]",
54: "lR",
55: NULL,
1.14 xsa 56: cvs_watchers
1.1 xsa 57: };
58:
1.14 xsa 59: int
1.15 ! xsa 60: cvs_watch(int argc, char **argv)
! 61: {
! 62: int ch, flags;
! 63: struct cvs_recursion cr;
! 64:
! 65: if (argc < 2)
! 66: fatal("%s", cvs_cmd_watch.cmd_synopsis);
! 67:
! 68: if (strcmp(argv[1], "on") == 0)
! 69: watch_req |= W_ON;
! 70: else if (strcmp(argv[1], "off") == 0)
! 71: watch_req |= W_OFF;
! 72: else if (strcmp(argv[1], "add") == 0)
! 73: watch_req |= W_ADD;
! 74: else if (strcmp(argv[1], "remove") == 0)
! 75: watch_req |= W_REMOVE;
! 76: else
! 77: fatal("%s", cvs_cmd_watch.cmd_synopsis);
! 78:
! 79: --argc;
! 80: ++argv;
! 81:
! 82: flags = CR_RECURSE_DIRS;
! 83:
! 84: while ((ch = getopt(argc, argv, cvs_cmd_watch.cmd_opts)) != -1) {
! 85: switch (ch) {
! 86: case 'a':
! 87: if (!(watch_req & (W_ADD|W_REMOVE)))
! 88: fatal("%s", cvs_cmd_watch.cmd_synopsis);
! 89:
! 90: if (strcmp(optarg, "edit") == 0)
! 91: watch_aflags |= W_EDIT;
! 92: else if (strcmp(optarg, "unedit") == 0)
! 93: watch_aflags |= W_UNEDIT;
! 94: else if (strcmp(optarg, "commit") == 0)
! 95: watch_aflags |= W_COMMIT;
! 96: else if (strcmp(optarg, "all") == 0)
! 97: watch_aflags |= W_ALL;
! 98: else if (strcmp(optarg, "none") == 0)
! 99: watch_aflags &= ~W_ALL;
! 100: else
! 101: fatal("%s", cvs_cmd_watch.cmd_synopsis);
! 102: case 'l':
! 103: flags &= ~CR_RECURSE_DIRS;
! 104: break;
! 105: case 'R':
! 106: break;
! 107: default:
! 108: fatal("%s", cvs_cmd_watch.cmd_synopsis);
! 109: }
! 110: }
! 111:
! 112: argc -= optind;
! 113: argv += optind;
! 114:
! 115: if (watch_aflags == 0)
! 116: watch_aflags |= W_ALL;
! 117:
! 118: cr.enterdir = NULL;
! 119: cr.leavedir = NULL;
! 120:
! 121: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
! 122: cr.fileproc = cvs_client_sendfile;
! 123:
! 124: if (watch_req & (W_ADD|W_REMOVE)) {
! 125: if (watch_aflags & W_EDIT)
! 126: cvs_client_send_request("Argument -a edit");
! 127:
! 128: if (watch_aflags & W_UNEDIT)
! 129: cvs_client_send_request("Argument -a unedit");
! 130:
! 131: if (watch_aflags & W_COMMIT)
! 132: cvs_client_send_request("Argument -a commit");
! 133:
! 134: if (!(watch_aflags & W_ALL))
! 135: cvs_client_send_request("Argument -a none");
! 136: }
! 137:
! 138: if (!(flags & CR_RECURSE_DIRS))
! 139: cvs_client_send_request("Argument -l");
! 140: } else {
! 141: cr.fileproc = cvs_watch_local;
! 142: }
! 143:
! 144: cr.flags = flags;
! 145:
! 146: cvs_file_run(argc, argv, &cr);
! 147:
! 148: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
! 149: cvs_client_send_files(argv, argc);
! 150: cvs_client_senddir(".");
! 151:
! 152: if (watch_req & (W_ADD|W_REMOVE))
! 153: cvs_client_send_request("watch-%s",
! 154: (watch_req & W_ADD) ? "add" : "remove");
! 155: else
! 156: cvs_client_send_request("watch-%s",
! 157: (watch_req & W_ON) ? "on" : "off");
! 158:
! 159: cvs_client_get_responses();
! 160: }
! 161:
! 162: return (0);
! 163: }
! 164:
! 165: int
1.14 xsa 166: cvs_watchers(int argc, char **argv)
1.1 xsa 167: {
168: int ch;
1.14 xsa 169: int flags;
170: struct cvs_recursion cr;
1.4 joris 171:
1.14 xsa 172: flags = CR_RECURSE_DIRS;
1.7 moritz 173:
1.14 xsa 174: while ((ch = getopt(argc, argv, cvs_cmd_watchers.cmd_opts)) != -1) {
1.1 xsa 175: switch (ch) {
176: case 'l':
1.14 xsa 177: flags &= ~CR_RECURSE_DIRS;
1.1 xsa 178: break;
179: case 'R':
180: break;
181: default:
1.14 xsa 182: fatal("%s", cvs_cmd_watchers.cmd_synopsis);
1.1 xsa 183: }
184: }
185:
1.14 xsa 186: argc -= optind;
187: argv += optind;
188:
189: if (argc == 0)
190: fatal("%s", cvs_cmd_watchers.cmd_synopsis);
1.1 xsa 191:
1.14 xsa 192: cr.enterdir = NULL;
193: cr.leavedir = NULL;
1.1 xsa 194:
1.14 xsa 195: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
196: cr.fileproc = cvs_client_sendfile;
197:
198: if (!(flags & CR_RECURSE_DIRS))
199: cvs_client_send_request("Argument -l");
200: } else {
201: cr.fileproc = cvs_watchers_local;
1.7 moritz 202: }
1.9 joris 203:
1.14 xsa 204: cr.flags = flags;
1.1 xsa 205:
1.14 xsa 206: cvs_file_run(argc, argv, &cr);
1.1 xsa 207:
1.14 xsa 208: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
209: cvs_client_send_files(argv, argc);
210: cvs_client_senddir(".");
211: cvs_client_send_request("watchers");
212: cvs_client_get_responses();
1.6 xsa 213: }
214:
1.9 joris 215: return (0);
1.15 ! xsa 216: }
! 217:
! 218: static void
! 219: cvs_watch_local(struct cvs_file *cf)
! 220: {
1.1 xsa 221: }
1.7 moritz 222:
1.14 xsa 223: static void
224: cvs_watchers_local(struct cvs_file *cf)
1.1 xsa 225: {
226: }