Annotation of src/usr.bin/cvs/status.c, Revision 1.63
1.63 ! xsa 1: /* $OpenBSD: status.c,v 1.62 2006/06/01 20:00:52 joris Exp $ */
1.1 jfb 2: /*
1.57 joris 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1 jfb 4: *
1.57 joris 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.57 joris 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.51 xsa 18: #include "includes.h"
1.1 jfb 19:
20: #include "cvs.h"
21: #include "log.h"
22: #include "proto.h"
23:
1.57 joris 24: int cvs_status(int, char **);
25: void cvs_status_local(struct cvs_file *);
1.22 jfb 26:
27: struct cvs_cmd cvs_cmd_status = {
28: CVS_OP_STATUS, CVS_REQ_STATUS, "status",
29: { "st", "stat" },
30: "Display status information on checked out files",
31: "[-lRv]",
1.57 joris 32: "lRv:",
1.22 jfb 33: NULL,
1.57 joris 34: cvs_status
1.10 joris 35: };
1.1 jfb 36:
1.57 joris 37: #define CVS_STATUS_SEP \
38: "==================================================================="
1.1 jfb 39:
1.57 joris 40: const char *status_tab[] = {
41: "Unknown",
42: "Locally Added",
43: "Locally Removed",
44: "Locally Modified",
45: "Up-to-date",
46: "Needs Checkout",
47: "Needs Checkout",
48: "Needs Merge",
49: "Needs Patch",
50: "Entry Invalid",
51: "Unresolved Conflict",
52: "Classifying error",
53: };
54:
55: int
56: cvs_status(int argc, char **argv)
1.1 jfb 57: {
1.58 joris 58: int ch, flags;
1.57 joris 59: char *arg = ".";
60: struct cvs_recursion cr;
1.1 jfb 61:
1.58 joris 62: flags = CR_REPO | CR_RECURSE_DIRS;
63:
1.57 joris 64: while ((ch = getopt(argc, argv, cvs_cmd_status.cmd_opts)) != -1) {
1.1 jfb 65: switch (ch) {
1.7 jfb 66: case 'l':
1.58 joris 67: flags &= ~CR_RECURSE_DIRS;
1.7 jfb 68: break;
69: case 'R':
70: break;
71: case 'v':
72: break;
1.1 jfb 73: default:
1.57 joris 74: fatal("%s", cvs_cmd_status.cmd_synopsis);
1.1 jfb 75: }
76: }
77:
1.57 joris 78: argc -= optind;
79: argv += optind;
1.1 jfb 80:
1.57 joris 81: cr.enterdir = NULL;
82: cr.leavedir = NULL;
83: cr.local = cvs_status_local;
84: cr.remote = NULL;
1.58 joris 85: cr.flags = flags;
1.57 joris 86:
87: if (argc > 0)
88: cvs_file_run(argc, argv, &cr);
89: else
90: cvs_file_run(1, &arg, &cr);
1.26 xsa 91:
1.1 jfb 92: return (0);
93: }
94:
1.57 joris 95: void
96: cvs_status_local(struct cvs_file *cf)
1.1 jfb 97: {
1.57 joris 98: int l;
99: size_t len;
100: const char *status;
101: char buf[128], timebuf[32], revbuf[32];
1.1 jfb 102:
1.57 joris 103: cvs_log(LP_TRACE, "cvs_status_local(%s)", cf->file_path);
1.1 jfb 104:
1.61 joris 105: cvs_file_classify(cf, NULL, 1);
1.15 jfb 106:
1.57 joris 107: if (cf->file_type == CVS_DIR) {
1.33 xsa 108: if (verbosity > 1)
1.57 joris 109: cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
110: return;
1.33 xsa 111: }
1.15 jfb 112:
1.57 joris 113: cvs_printf("%s\n", CVS_STATUS_SEP);
1.5 jfb 114:
1.57 joris 115: status = status_tab[cf->file_status];
116: if (cf->file_status == FILE_MODIFIED &&
117: cf->file_ent->ce_conflict != NULL)
118: status = "File had conflicts on merge";
119:
1.63 ! xsa 120: if (cf->file_status == FILE_LOST ||
! 121: cf->file_status == FILE_UNKNOWN ||
! 122: cf->file_rcs->rf_inattic == 1) {
! 123: l = snprintf(buf, sizeof(buf), "no file %s\t", cf->file_name);
! 124: if (l == -1 || l >= (int)sizeof(buf))
! 125: fatal("cvs_status_local: overflow");
! 126: } else
! 127: if (strlcpy(buf, cf->file_name, sizeof(buf)) >= sizeof(buf))
! 128: fatal("cvs_status_local: overflow");
! 129:
! 130: cvs_printf("File: %-17s\tStatus: %s\n\n", buf, status);
1.57 joris 131:
132: if (cf->file_ent == NULL) {
133: l = snprintf(buf, sizeof(buf),
134: "No entry for %s", cf->file_name);
135: if (l == -1 || l >= (int)sizeof(buf))
136: fatal("cvs_status_local: overflow");
137: } else if (cf->file_status == FILE_ADDED) {
138: len = strlcpy(buf, "New file!", sizeof(buf));
139: if (len >= sizeof(buf))
140: fatal("cvs_status_local: truncation");
1.16 jfb 141: } else {
1.57 joris 142: rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
1.35 xsa 143:
1.57 joris 144: if (cf->file_ent->ce_conflict == NULL) {
145: ctime_r(&(cf->file_ent->ce_mtime), timebuf);
146: if (timebuf[strlen(timebuf) - 1] == '\n')
147: timebuf[strlen(timebuf) - 1] = '\0';
148: } else {
149: len = strlcpy(timebuf, cf->file_ent->ce_conflict,
150: sizeof(timebuf));
151: if (len >= sizeof(timebuf))
152: fatal("cvs_status_local: truncation");
153: }
1.35 xsa 154:
1.57 joris 155: l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf, timebuf);
156: if (l == -1 || l >= (int)sizeof(buf))
157: fatal("cvs_status_local: overflow");
1.16 jfb 158: }
1.32 joris 159:
1.28 xsa 160: cvs_printf(" Working revision:\t%s\n", buf);
1.30 xsa 161:
1.57 joris 162: buf[0] = '\0';
163: if (cf->file_rcs == NULL) {
164: len = strlcat(buf, "No revision control file", sizeof(buf));
165: if (len >= sizeof(buf))
166: fatal("cvs_status_local: truncation");
1.30 xsa 167: } else {
1.62 joris 168: rcsnum_tostr(rcs_head_get(cf->file_rcs),
169: revbuf, sizeof(revbuf));
1.57 joris 170: l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf,
171: cf->file_rpath);
172: if (l == -1 || l >= (int)sizeof(buf))
173: fatal("cvs_status_local: overflow");
1.30 xsa 174: }
175:
176: cvs_printf(" Repository revision:\t%s\n", buf);
177:
1.57 joris 178: if (cf->file_ent != NULL) {
179: if (cf->file_ent->ce_tag != NULL)
1.60 xsa 180: cvs_printf(" Sticky Tag:\t\t%s\n",
1.57 joris 181: cf->file_ent->ce_tag);
1.60 xsa 182: else if (verbosity > 0)
183: cvs_printf(" Sticky Tag:\t\t(none)\n");
184:
1.57 joris 185: if (cf->file_ent->ce_opts != NULL)
186: cvs_printf(" Sticky Options:\t%s\n",
187: cf->file_ent->ce_opts);
1.60 xsa 188: else if (verbosity > 0)
189: cvs_printf(" Sticky Options:\t(none)\n");
1.41 xsa 190: }
1.15 jfb 191:
1.25 xsa 192: cvs_printf("\n");
1.1 jfb 193: }