Annotation of src/usr.bin/cvs/tag.c, Revision 1.51
1.51 ! xsa 1: /* $OpenBSD: tag.c,v 1.50 2006/11/09 09:24:28 xsa Exp $ */
1.1 jfb 2: /*
1.45 xsa 3: * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1 jfb 4: *
1.45 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.
1.1 jfb 8: *
1.45 xsa 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 jfb 16: */
17:
1.36 xsa 18: #include "includes.h"
1.1 jfb 19:
20: #include "cvs.h"
21: #include "log.h"
1.50 xsa 22: #include "remote.h"
1.1 jfb 23:
1.45 xsa 24: void cvs_tag_local(struct cvs_file *);
25:
26: static int tag_del(struct cvs_file *);
27: static int tag_add(struct cvs_file *);
28:
1.50 xsa 29: static int tag_delete = 0;
30: static int tag_force_move = 0;
1.45 xsa 31: static char *tag = NULL;
32: static char *tag_date = NULL;
33: static char *tag_name = NULL;
34: static char *tag_oldname = NULL;
1.7 joris 35:
1.17 jfb 36: struct cvs_cmd cvs_cmd_tag = {
1.47 joris 37: CVS_OP_TAG, 0, "tag",
1.17 jfb 38: { "ta", "freeze" },
39: "Add a symbolic tag to checked out version of files",
1.40 xsa 40: "[-bcdFflR] [-D date | -r rev] tag [file ...]",
1.17 jfb 41: "bcD:dFflRr:",
42: NULL,
1.45 xsa 43: cvs_tag
1.17 jfb 44: };
45:
1.45 xsa 46: int
47: cvs_tag(int argc, char **argv)
1.1 jfb 48: {
1.45 xsa 49: int ch, flags;
1.49 reyk 50: char *arg = ".";
1.45 xsa 51: struct cvs_recursion cr;
1.1 jfb 52:
1.45 xsa 53: flags = CR_RECURSE_DIRS;
1.1 jfb 54:
1.45 xsa 55: while ((ch = getopt(argc, argv, cvs_cmd_tag.cmd_opts)) != -1) {
1.1 jfb 56: switch (ch) {
1.45 xsa 57: case 'D':
58: tag_date = optarg;
1.1 jfb 59: break;
60: case 'd':
1.45 xsa 61: tag_delete = 1;
1.3 jfb 62: break;
1.46 xsa 63: case 'F':
64: tag_force_move = 1;
65: break;
1.1 jfb 66: case 'l':
1.45 xsa 67: flags &= ~CR_RECURSE_DIRS;
1.17 jfb 68: break;
69: case 'R':
1.1 jfb 70: break;
71: case 'r':
1.14 jfb 72: tag_oldname = optarg;
1.1 jfb 73: break;
74: default:
1.45 xsa 75: fatal("%s", cvs_cmd_tag.cmd_synopsis);
1.1 jfb 76: }
77: }
78:
79: argc -= optind;
80: argv += optind;
81:
1.40 xsa 82: if (argc == 0)
1.45 xsa 83: fatal("%s", cvs_cmd_tag.cmd_synopsis);
84:
85: tag_name = argv[0];
86: argc--;
87: argv++;
1.15 jfb 88:
1.38 xsa 89: if (!rcs_sym_check(tag_name))
90: fatal("tag `%s' must not contain the characters `%s'",
1.15 jfb 91: tag_name, RCS_SYM_INVALCHAR);
1.1 jfb 92:
1.45 xsa 93: if (tag_oldname != NULL) {
94: if (tag_delete == 1)
95: tag_oldname = NULL;
96: else
97: tag = tag_oldname;
98: }
99:
100: if (tag_date != NULL) {
101: if (tag_delete == 1)
102: tag_date = NULL;
103: else
104: tag = tag_date;
105: }
106:
107: if (tag_oldname != NULL && tag_date != NULL)
108: fatal("-r and -D options are mutually exclusive");
109:
110: cr.enterdir = NULL;
111: cr.leavedir = NULL;
1.50 xsa 112:
113: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
114: cr.fileproc = cvs_client_sendfile;
115:
116: if (tag_delete == 1)
117: cvs_client_send_request("Argument -d");
118:
119: if (tag_force_move == 1)
120: cvs_client_send_request("Argument -F");
121:
122: if (!(flags & CR_RECURSE_DIRS))
123: cvs_client_send_request("Argument -l");
124:
125: if (tag_oldname != NULL)
126: cvs_client_send_request("Argument -r%s", tag_oldname);
127:
128: cvs_client_send_request("Argument %s", tag_name);
129: } else {
130: cr.fileproc = cvs_tag_local;
131: }
132:
1.45 xsa 133: cr.flags = flags;
1.1 jfb 134:
1.49 reyk 135: if (argc > 0)
136: cvs_file_run(argc, argv, &cr);
137: else
138: cvs_file_run(1, &arg, &cr);
1.50 xsa 139:
140: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
141: cvs_client_send_files(argv, argc);
142: cvs_client_senddir(".");
143: cvs_client_send_request("tag");
144: cvs_client_get_responses();
145: }
1.3 jfb 146:
1.7 joris 147: return (0);
148: }
149:
1.45 xsa 150: void
151: cvs_tag_local(struct cvs_file *cf)
1.7 joris 152: {
1.45 xsa 153: cvs_log(LP_TRACE, "cvs_tag_local(%s)", cf->file_path);
1.17 jfb 154:
1.45 xsa 155: if (cf->file_type == CVS_DIR) {
156: if (verbosity > 1) {
157: cvs_log(LP_NOTICE, "%s %s",
158: (tag_delete == 1) ? "Untagging" : "Tagging",
159: cf->file_path);
160: }
161: return;
162: }
1.40 xsa 163:
1.45 xsa 164: cvs_file_classify(cf, tag, 0);
1.7 joris 165:
1.45 xsa 166: if (tag_delete == 1) {
167: if (tag_del(cf) == 0) {
168: if (verbosity > 0)
169: cvs_printf("D %s\n", cf->file_path);
1.21 xsa 170:
1.45 xsa 171: rcs_write(cf->file_rcs);
172: }
173: return;
174: }
1.21 xsa 175:
1.45 xsa 176: switch(cf->file_status) {
177: case FILE_ADDED:
178: if (verbosity > 1) {
179: cvs_log(LP_NOTICE,
180: "couldn't tag added but un-commited file `%s'",
181: cf->file_path);
1.35 joris 182: }
1.45 xsa 183: return;
184: case FILE_REMOVED:
185: if (verbosity > 1) {
186: cvs_log(LP_NOTICE,
187: "skipping removed but un-commited file `%s'",
188: cf->file_path);
189: }
190: return;
191: case FILE_CHECKOUT:
192: case FILE_MODIFIED:
193: case FILE_UPTODATE:
194: if (tag_add(cf) == 0) {
195: if (verbosity > 0)
196: cvs_printf("T %s\n", cf->file_path);
1.1 jfb 197:
1.45 xsa 198: rcs_write(cf->file_rcs);
1.35 joris 199: }
1.45 xsa 200: break;
201: default:
202: break;
1.1 jfb 203: }
204: }
205:
1.14 jfb 206: static int
1.45 xsa 207: tag_del(struct cvs_file *cf)
1.1 jfb 208: {
1.45 xsa 209: if (cf->file_rcs == NULL)
210: return (-1);
1.1 jfb 211:
1.45 xsa 212: if (cvs_noexec == 1)
1.35 joris 213: return (0);
1.1 jfb 214:
1.45 xsa 215: return (rcs_sym_remove(cf->file_rcs, tag_name));
1.14 jfb 216: }
217:
218: static int
1.45 xsa 219: tag_add(struct cvs_file *cf)
1.14 jfb 220: {
1.46 xsa 221: char revbuf[16], trevbuf[16];
222: RCSNUM *trev;
223: struct rcs_sym *sym;
1.14 jfb 224:
1.45 xsa 225: if (cf->file_rcs == NULL) {
1.23 xsa 226: if (verbosity > 1)
1.45 xsa 227: cvs_log(LP_NOTICE, "cannot find revision "
228: "control file for `%s'", cf->file_name);
229: return (-1);
1.14 jfb 230: }
1.1 jfb 231:
1.45 xsa 232: if (cvs_noexec == 1)
1.32 xsa 233: return (0);
1.1 jfb 234:
1.46 xsa 235: trev = rcs_sym_getrev(cf->file_rcs, tag_name);
236: if (trev != NULL) {
237: if (rcsnum_cmp(cf->file_rcsrev, trev, 0) == 0) {
238: rcsnum_free(trev);
239: return (-1);
240: }
241: (void)rcsnum_tostr(trev, trevbuf, sizeof(trevbuf));
242:
243: if (tag_force_move == 0) {
244: cvs_printf("W %s : %s ", cf->file_path, tag_name);
245: cvs_printf("already exists on version %s", trevbuf);
246: cvs_printf(" : NOT MOVING tag to version %s\n", revbuf);
247:
248: return (-1);
249: } else if (tag_force_move == 1) {
250: sym = rcs_sym_get(cf->file_rcs, tag_name);
251: rcsnum_cpy(cf->file_rcsrev, sym->rs_num, 0);
252: cf->file_rcs->rf_flags &= ~RCS_SYNCED;
253:
254: return (0);
255: }
256: }
257:
1.45 xsa 258: if (rcs_sym_add(cf->file_rcs, tag_name, cf->file_rcsrev) == -1) {
259: if (rcs_errno != RCS_ERR_DUPENT) {
1.46 xsa 260: (void)rcsnum_tostr(cf->file_rcsrev, revbuf,
261: sizeof(revbuf));
1.45 xsa 262: cvs_log(LP_NOTICE,
263: "failed to set tag %s to revision %s in %s",
264: tag_name, revbuf, cf->file_rcs->rf_path);
1.39 xsa 265: }
1.45 xsa 266: return (-1);
1.1 jfb 267: }
1.17 jfb 268:
1.14 jfb 269: return (0);
1.1 jfb 270: }