Annotation of src/usr.bin/cvs/status.c, Revision 1.58
1.58 ! joris 1: /* $OpenBSD: status.c,v 1.57 2006/05/27 03:30:31 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.57 joris 105: cvs_file_classify(cf);
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:
120: cvs_printf("File: %-17s\tStatus: %s\n\n", cf->file_name, status);
121:
122: if (cf->file_ent == NULL) {
123: l = snprintf(buf, sizeof(buf),
124: "No entry for %s", cf->file_name);
125: if (l == -1 || l >= (int)sizeof(buf))
126: fatal("cvs_status_local: overflow");
127: } else if (cf->file_status == FILE_ADDED) {
128: len = strlcpy(buf, "New file!", sizeof(buf));
129: if (len >= sizeof(buf))
130: fatal("cvs_status_local: truncation");
1.16 jfb 131: } else {
1.57 joris 132: rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
1.35 xsa 133:
1.57 joris 134: if (cf->file_ent->ce_conflict == NULL) {
135: ctime_r(&(cf->file_ent->ce_mtime), timebuf);
136: if (timebuf[strlen(timebuf) - 1] == '\n')
137: timebuf[strlen(timebuf) - 1] = '\0';
138: } else {
139: len = strlcpy(timebuf, cf->file_ent->ce_conflict,
140: sizeof(timebuf));
141: if (len >= sizeof(timebuf))
142: fatal("cvs_status_local: truncation");
143: }
1.35 xsa 144:
1.57 joris 145: l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf, timebuf);
146: if (l == -1 || l >= (int)sizeof(buf))
147: fatal("cvs_status_local: overflow");
1.16 jfb 148: }
1.32 joris 149:
1.28 xsa 150: cvs_printf(" Working revision:\t%s\n", buf);
1.30 xsa 151:
1.57 joris 152: buf[0] = '\0';
153: if (cf->file_rcs == NULL) {
154: len = strlcat(buf, "No revision control file", sizeof(buf));
155: if (len >= sizeof(buf))
156: fatal("cvs_status_local: truncation");
1.30 xsa 157: } else {
1.57 joris 158: rcsnum_tostr(cf->file_rcs->rf_head, revbuf, sizeof(revbuf));
159: l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf,
160: cf->file_rpath);
161: if (l == -1 || l >= (int)sizeof(buf))
162: fatal("cvs_status_local: overflow");
1.30 xsa 163: }
164:
165: cvs_printf(" Repository revision:\t%s\n", buf);
166:
1.57 joris 167: if (cf->file_ent != NULL) {
168: if (cf->file_ent->ce_tag != NULL)
169: cvs_printf(" Sticky Tag:\t%s\n",
170: cf->file_ent->ce_tag);
171: if (cf->file_ent->ce_opts != NULL)
172: cvs_printf(" Sticky Options:\t%s\n",
173: cf->file_ent->ce_opts);
1.41 xsa 174: }
1.15 jfb 175:
1.25 xsa 176: cvs_printf("\n");
1.1 jfb 177: }