Annotation of src/usr.bin/cvs/status.c, Revision 1.90
1.90 ! joris 1: /* $OpenBSD: status.c,v 1.89 2009/01/14 00:23:30 joris Exp $ */
1.1 jfb 2: /*
1.57 joris 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.81 xsa 4: * Copyright (c) 2005-2008 Xavier Santolaria <xsa@openbsd.org>
1.1 jfb 5: *
1.57 joris 6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 jfb 9: *
1.57 joris 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 jfb 17: */
18:
1.73 otto 19: #include <string.h>
1.87 tobias 20: #include <time.h>
1.73 otto 21: #include <unistd.h>
1.1 jfb 22:
23: #include "cvs.h"
1.68 joris 24: #include "remote.h"
1.1 jfb 25:
1.57 joris 26: void cvs_status_local(struct cvs_file *);
1.22 jfb 27:
1.64 xsa 28: static int show_sym = 0;
29:
1.22 jfb 30: struct cvs_cmd cvs_cmd_status = {
1.80 tobias 31: CVS_OP_STATUS, CVS_USE_WDIR, "status",
1.22 jfb 32: { "st", "stat" },
33: "Display status information on checked out files",
34: "[-lRv]",
1.64 xsa 35: "lRv",
1.22 jfb 36: NULL,
1.57 joris 37: cvs_status
1.10 joris 38: };
1.1 jfb 39:
1.57 joris 40: #define CVS_STATUS_SEP \
41: "==================================================================="
1.1 jfb 42:
1.57 joris 43: const char *status_tab[] = {
44: "Unknown",
45: "Locally Added",
46: "Locally Removed",
47: "Locally Modified",
48: "Up-to-date",
49: "Needs Checkout",
50: "Needs Checkout",
51: "Needs Merge",
52: "Needs Patch",
53: "Entry Invalid",
54: "Unresolved Conflict",
55: "Classifying error",
56: };
57:
58: int
59: cvs_status(int argc, char **argv)
1.1 jfb 60: {
1.58 joris 61: int ch, flags;
1.57 joris 62: char *arg = ".";
63: struct cvs_recursion cr;
1.1 jfb 64:
1.68 joris 65: flags = CR_RECURSE_DIRS;
1.58 joris 66:
1.57 joris 67: while ((ch = getopt(argc, argv, cvs_cmd_status.cmd_opts)) != -1) {
1.1 jfb 68: switch (ch) {
1.7 jfb 69: case 'l':
1.58 joris 70: flags &= ~CR_RECURSE_DIRS;
1.7 jfb 71: break;
72: case 'R':
1.79 tobias 73: flags |= CR_RECURSE_DIRS;
1.7 jfb 74: break;
75: case 'v':
1.64 xsa 76: show_sym = 1;
1.7 jfb 77: break;
1.1 jfb 78: default:
1.57 joris 79: fatal("%s", cvs_cmd_status.cmd_synopsis);
1.1 jfb 80: }
81: }
82:
1.57 joris 83: argc -= optind;
84: argv += optind;
1.1 jfb 85:
1.57 joris 86: cr.enterdir = NULL;
87: cr.leavedir = NULL;
1.68 joris 88:
89: if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
90: flags |= CR_REPO;
91: cr.fileproc = cvs_status_local;
92: } else {
1.69 joris 93: cvs_client_connect_to_server();
1.68 joris 94: if (!(flags & CR_RECURSE_DIRS))
95: cvs_client_send_request("Argument -l");
96: if (show_sym)
97: cvs_client_send_request("Argument -v");
98: cr.fileproc = cvs_client_sendfile;
99: }
100:
1.58 joris 101: cr.flags = flags;
1.57 joris 102:
103: if (argc > 0)
104: cvs_file_run(argc, argv, &cr);
105: else
106: cvs_file_run(1, &arg, &cr);
1.68 joris 107:
108: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
109: cvs_client_send_files(argv, argc);
110: cvs_client_senddir(".");
111: cvs_client_send_request("status");
112: cvs_client_get_responses();
113: }
1.26 xsa 114:
1.1 jfb 115: return (0);
116: }
117:
1.57 joris 118: void
119: cvs_status_local(struct cvs_file *cf)
1.1 jfb 120: {
1.57 joris 121: size_t len;
1.70 joris 122: RCSNUM *head;
1.57 joris 123: const char *status;
1.75 xsa 124: char buf[128], timebuf[CVS_TIME_BUFSZ], revbuf[CVS_REV_BUFSZ];
1.64 xsa 125: struct rcs_sym *sym;
1.1 jfb 126:
1.57 joris 127: cvs_log(LP_TRACE, "cvs_status_local(%s)", cf->file_path);
1.1 jfb 128:
1.77 joris 129: cvs_file_classify(cf, cvs_directory_tag);
1.15 jfb 130:
1.57 joris 131: if (cf->file_type == CVS_DIR) {
1.33 xsa 132: if (verbosity > 1)
1.57 joris 133: cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
134: return;
1.33 xsa 135: }
1.89 joris 136:
137: if (cf->file_status == FILE_UPTODATE && cf->fd == -1 &&
1.90 ! joris 138: !(cf->file_flags & FILE_USER_SUPPLIED))
1.89 joris 139: return;
1.15 jfb 140:
1.88 tobias 141: if (cf->file_rcs != NULL)
1.83 joris 142: head = rcs_head_get(cf->file_rcs);
1.88 tobias 143: else
1.83 joris 144: head = NULL;
1.78 tobias 145:
1.57 joris 146: cvs_printf("%s\n", CVS_STATUS_SEP);
1.5 jfb 147:
1.88 tobias 148: if (cf->file_rcs != NULL && head == NULL)
149: status = status_tab[FILE_UNKNOWN];
150: else
151: status = status_tab[cf->file_status];
152:
1.57 joris 153: if (cf->file_status == FILE_MODIFIED &&
154: cf->file_ent->ce_conflict != NULL)
155: status = "File had conflicts on merge";
156:
1.88 tobias 157: if (cf->fd == -1) {
1.71 xsa 158: (void)xsnprintf(buf, sizeof(buf), "no file %s\t",
159: cf->file_name);
1.63 xsa 160: } else
161: if (strlcpy(buf, cf->file_name, sizeof(buf)) >= sizeof(buf))
162: fatal("cvs_status_local: overflow");
163:
164: cvs_printf("File: %-17s\tStatus: %s\n\n", buf, status);
1.57 joris 165:
166: if (cf->file_ent == NULL) {
1.71 xsa 167: (void)xsnprintf(buf, sizeof(buf),
1.57 joris 168: "No entry for %s", cf->file_name);
1.88 tobias 169: } else if (cf->file_ent->ce_status == CVS_ENT_ADDED) {
1.57 joris 170: len = strlcpy(buf, "New file!", sizeof(buf));
171: if (len >= sizeof(buf))
172: fatal("cvs_status_local: truncation");
1.16 jfb 173: } else {
1.57 joris 174: rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
1.35 xsa 175:
1.57 joris 176: if (cf->file_ent->ce_conflict == NULL) {
177: ctime_r(&(cf->file_ent->ce_mtime), timebuf);
178: if (timebuf[strlen(timebuf) - 1] == '\n')
179: timebuf[strlen(timebuf) - 1] = '\0';
180: } else {
181: len = strlcpy(timebuf, cf->file_ent->ce_conflict,
182: sizeof(timebuf));
183: if (len >= sizeof(timebuf))
184: fatal("cvs_status_local: truncation");
185: }
1.35 xsa 186:
1.76 xsa 187: (void)strlcpy(buf, revbuf, sizeof(buf));
188: if (cvs_server_active == 0) {
189: (void)strlcat(buf, "\t", sizeof(buf));
190: (void)strlcat(buf, timebuf, sizeof(buf));
191: }
1.16 jfb 192: }
1.32 joris 193:
1.28 xsa 194: cvs_printf(" Working revision:\t%s\n", buf);
1.30 xsa 195:
1.57 joris 196: buf[0] = '\0';
1.88 tobias 197: if (cf->file_rcs == NULL) {
1.57 joris 198: len = strlcat(buf, "No revision control file", sizeof(buf));
1.88 tobias 199: if (len >= sizeof(buf))
200: fatal("cvs_status_local: truncation");
201: } else if (head == NULL) {
202: len = strlcat(buf, "No head revision", sizeof(buf));
1.57 joris 203: if (len >= sizeof(buf))
204: fatal("cvs_status_local: truncation");
1.30 xsa 205: } else {
1.70 joris 206: rcsnum_tostr(head, revbuf, sizeof(revbuf));
207: rcsnum_free(head);
1.71 xsa 208: (void)xsnprintf(buf, sizeof(buf), "%s\t%s", revbuf,
1.57 joris 209: cf->file_rpath);
1.30 xsa 210: }
211:
212: cvs_printf(" Repository revision:\t%s\n", buf);
213:
1.57 joris 214: if (cf->file_ent != NULL) {
215: if (cf->file_ent->ce_tag != NULL)
1.60 xsa 216: cvs_printf(" Sticky Tag:\t\t%s\n",
1.57 joris 217: cf->file_ent->ce_tag);
1.60 xsa 218: else if (verbosity > 0)
219: cvs_printf(" Sticky Tag:\t\t(none)\n");
1.81 xsa 220:
221: if (cf->file_ent->ce_date != -1) {
1.87 tobias 222: struct tm datetm;
1.81 xsa 223: char datetmp[CVS_TIME_BUFSZ];
224:
1.87 tobias 225: gmtime_r(&(cf->file_ent->ce_date), &datetm);
1.81 xsa 226: (void)strftime(datetmp, sizeof(datetmp),
1.87 tobias 227: CVS_DATE_FMT, &datetm);
1.81 xsa 228:
229: cvs_printf(" Sticky Date:\t\t%s\n", datetmp);
230: } else if (verbosity > 0)
231: cvs_printf(" Sticky Date:\t\t(none)\n");
1.60 xsa 232:
1.57 joris 233: if (cf->file_ent->ce_opts != NULL)
234: cvs_printf(" Sticky Options:\t%s\n",
235: cf->file_ent->ce_opts);
1.60 xsa 236: else if (verbosity > 0)
237: cvs_printf(" Sticky Options:\t(none)\n");
1.64 xsa 238: }
239:
1.86 joris 240: if (cf->file_rcs != NULL && show_sym == 1) {
1.64 xsa 241: cvs_printf("\n");
242: cvs_printf(" Existing Tags:\n");
243:
244: if (!TAILQ_EMPTY(&(cf->file_rcs->rf_symbols))) {
245: TAILQ_FOREACH(sym,
246: &(cf->file_rcs->rf_symbols), rs_list) {
247: (void)rcsnum_tostr(sym->rs_num, revbuf,
248: sizeof(revbuf));
249:
250: cvs_printf("\t%-25s\t(%s: %s)\n", sym->rs_name,
251: RCSNUM_ISBRANCH(sym->rs_num) ? "branch" :
252: "revision", revbuf);
253: }
254: } else
255: cvs_printf("\tNo Tags Exist\n");
1.41 xsa 256: }
1.15 jfb 257:
1.25 xsa 258: cvs_printf("\n");
1.1 jfb 259: }