]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/cvs/src/status.c
This commit was generated by cvs2svn to compensate for changes in r48743,
[FreeBSD/FreeBSD.git] / contrib / cvs / src / status.c
1 /*
2  * Copyright (c) 1992, Brian Berliner and Jeff Polk
3  * Copyright (c) 1989-1992, Brian Berliner
4  * 
5  * You may distribute under the terms of the GNU General Public License as
6  * specified in the README file that comes with the CVS source distribution.
7  * 
8  * Status Information
9  */
10
11 #include "cvs.h"
12
13 static Dtype status_dirproc PROTO ((void *callerdat, char *dir,
14                                     char *repos, char *update_dir,
15                                     List *entries));
16 static int status_fileproc PROTO ((void *callerdat, struct file_info *finfo));
17 static int tag_list_proc PROTO((Node * p, void *closure));
18
19 static int local = 0;
20 static int long_format = 0;
21 static RCSNode *xrcsnode;
22
23 static const char *const status_usage[] =
24 {
25     "Usage: %s %s [-vlR] [files...]\n",
26     "\t-v\tVerbose format; includes tag information for the file\n",
27     "\t-l\tProcess this directory only (not recursive).\n",
28     "\t-R\tProcess directories recursively.\n",
29     "(Specify the --help global option for a list of other help options)\n",
30     NULL
31 };
32
33 int
34 cvsstatus (argc, argv)
35     int argc;
36     char **argv;
37 {
38     int c;
39     int err = 0;
40
41     if (argc == -1)
42         usage (status_usage);
43
44     optind = 0;
45     while ((c = getopt (argc, argv, "+vlR")) != -1)
46     {
47         switch (c)
48         {
49             case 'v':
50                 long_format = 1;
51                 break;
52             case 'l':
53                 local = 1;
54                 break;
55             case 'R':
56                 local = 0;
57                 break;
58             case '?':
59             default:
60                 usage (status_usage);
61                 break;
62         }
63     }
64     argc -= optind;
65     argv += optind;
66
67     wrap_setup ();
68
69 #ifdef CLIENT_SUPPORT
70     if (client_active) {
71       start_server ();
72
73       ign_setup ();
74
75       if (long_format)
76         send_arg("-v");
77       if (local)
78         send_arg("-l");
79
80       send_file_names (argc, argv, SEND_EXPAND_WILD);
81
82       /* For a while, we tried setting SEND_NO_CONTENTS here so this
83          could be a fast operation.  That prevents the
84          server from updating our timestamp if the timestamp is
85          changed but the file is unmodified.  Worse, it is user-visible
86          (shows "locally modified" instead of "up to date" if
87          timestamp is changed but file is not).  And there is no good
88          workaround (you might not want to run "cvs update"; "cvs -n
89          update" doesn't update CVS/Entries; "cvs diff --brief" or
90          something perhaps could be made to work but somehow that
91          seems nonintuitive to me even if so).  Given that timestamps
92          seem to have the potential to get munged for any number of
93          reasons, it seems better to not rely too much on them.  */
94
95       send_files (argc, argv, local, 0, 0);
96
97       send_to_server ("status\012", 0);
98       err = get_responses_and_close ();
99
100       return err;
101     }
102 #endif
103
104     /* start the recursion processor */
105     err = start_recursion (status_fileproc, (FILESDONEPROC) NULL,
106                            status_dirproc, (DIRLEAVEPROC) NULL, NULL,
107                            argc, argv, local,
108                            W_LOCAL, 0, 1, (char *) NULL, 1);
109
110     return (err);
111 }
112
113 /*
114  * display the status of a file
115  */
116 /* ARGSUSED */
117 static int
118 status_fileproc (callerdat, finfo)
119     void *callerdat;
120     struct file_info *finfo;
121 {
122     Ctype status;
123     char *sstat;
124     Vers_TS *vers;
125
126     status = Classify_File (finfo, (char *) NULL, (char *) NULL, (char *) NULL,
127                             1, 0, &vers, 0);
128     sstat = "Classify Error";
129     switch (status)
130     {
131         case T_UNKNOWN:
132             sstat = "Unknown";
133             break;
134         case T_CHECKOUT:
135             sstat = "Needs Checkout";
136             break;
137 #ifdef SERVER_SUPPORT
138         case T_PATCH:
139             sstat = "Needs Patch";
140             break;
141 #endif
142         case T_CONFLICT:
143             /* I _think_ that "unresolved" is correct; that if it has
144                been resolved then the status will change.  But I'm not
145                sure about that.  */
146             sstat = "Unresolved Conflict";
147             break;
148         case T_ADDED:
149             sstat = "Locally Added";
150             break;
151         case T_REMOVED:
152             sstat = "Locally Removed";
153             break;
154         case T_MODIFIED:
155             if (vers->ts_conflict)
156                 sstat = "File had conflicts on merge";
157             else
158                 sstat = "Locally Modified";
159             break;
160         case T_REMOVE_ENTRY:
161             sstat = "Entry Invalid";
162             break;
163         case T_UPTODATE:
164             sstat = "Up-to-date";
165             break;
166         case T_NEEDS_MERGE:
167             sstat = "Needs Merge";
168             break;
169         case T_TITLE:
170             /* I don't think this case can occur here.  Just print
171                "Classify Error".  */
172             break;
173     }
174
175     cvs_output ("\
176 ===================================================================\n", 0);
177     if (vers->ts_user == NULL)
178     {
179         cvs_output ("File: no file ", 0);
180         cvs_output (finfo->file, 0);
181         cvs_output ("\t\tStatus: ", 0);
182         cvs_output (sstat, 0);
183         cvs_output ("\n\n", 0);
184     }
185     else
186     {
187         char *buf;
188         buf = xmalloc (strlen (finfo->file) + strlen (sstat) + 80);
189         sprintf (buf, "File: %-17s\tStatus: %s\n\n", finfo->file, sstat);
190         cvs_output (buf, 0);
191         free (buf);
192     }
193
194     if (vers->vn_user == NULL)
195     {
196         cvs_output ("   Working revision:\tNo entry for ", 0);
197         cvs_output (finfo->file, 0);
198         cvs_output ("\n", 0);
199     }
200     else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
201         cvs_output ("   Working revision:\tNew file!\n", 0);
202 #ifdef SERVER_SUPPORT
203     else if (server_active)
204     {
205         cvs_output ("   Working revision:\t", 0);
206         cvs_output (vers->vn_user, 0);
207         cvs_output ("\n", 0);
208     }
209 #endif
210     else
211     {
212         cvs_output ("   Working revision:\t", 0);
213         cvs_output (vers->vn_user, 0);
214         cvs_output ("\t", 0);
215         cvs_output (vers->ts_rcs, 0);
216         cvs_output ("\n", 0);
217     }
218
219     if (vers->vn_rcs == NULL)
220         cvs_output ("   Repository revision:\tNo revision control file\n", 0);
221     else
222     {
223         cvs_output ("   Repository revision:\t", 0);
224         cvs_output (vers->vn_rcs, 0);
225         cvs_output ("\t", 0);
226         cvs_output (vers->srcfile->path, 0);
227         cvs_output ("\n", 0);
228     }
229
230     if (vers->entdata)
231     {
232         Entnode *edata;
233
234         edata = vers->entdata;
235         if (edata->tag)
236         {
237             if (vers->vn_rcs == NULL)
238             {
239                 cvs_output ("   Sticky Tag:\t\t", 0);
240                 cvs_output (edata->tag, 0);
241                 cvs_output (" - MISSING from RCS file!\n", 0);
242             }
243             else
244             {
245                 if (isdigit (edata->tag[0]))
246                 {
247                     cvs_output ("   Sticky Tag:\t\t", 0);
248                     cvs_output (edata->tag, 0);
249                     cvs_output ("\n", 0);
250                 }
251                 else
252                 {
253                     char *branch = NULL;
254
255                     if (RCS_nodeisbranch (finfo->rcs, edata->tag))
256                         branch = RCS_whatbranch(finfo->rcs, edata->tag);
257
258                     cvs_output ("   Sticky Tag:\t\t", 0);
259                     cvs_output (edata->tag, 0);
260                     cvs_output (" (", 0);
261                     cvs_output (branch ? "branch" : "revision", 0);
262                     cvs_output (": ", 0);
263                     cvs_output (branch ? branch : vers->vn_rcs, 0);
264                     cvs_output (")\n", 0);
265
266                     if (branch)
267                         free (branch);
268                 }
269             }
270         }
271         else if (!really_quiet)
272             cvs_output ("   Sticky Tag:\t\t(none)\n", 0);
273
274         if (edata->date)
275         {
276             cvs_output ("   Sticky Date:\t\t", 0);
277             cvs_output (edata->date, 0);
278             cvs_output ("\n", 0);
279         }
280         else if (!really_quiet)
281             cvs_output ("   Sticky Date:\t\t(none)\n", 0);
282
283         if (edata->options && edata->options[0])
284         {
285             cvs_output ("   Sticky Options:\t", 0);
286             cvs_output (edata->options, 0);
287             cvs_output ("\n", 0);
288         }
289         else if (!really_quiet)
290             cvs_output ("   Sticky Options:\t(none)\n", 0);
291
292         if (long_format && vers->srcfile)
293         {
294             List *symbols = RCS_symbols(vers->srcfile);
295
296             cvs_output ("\n   Existing Tags:\n", 0);
297             if (symbols)
298             {
299                 xrcsnode = finfo->rcs;
300                 (void) walklist (symbols, tag_list_proc, NULL);
301             }
302             else
303                 cvs_output ("\tNo Tags Exist\n", 0);
304         }
305     }
306
307     cvs_output ("\n", 0);
308     freevers_ts (&vers);
309     return (0);
310 }
311
312 /*
313  * Print a warm fuzzy message
314  */
315 /* ARGSUSED */
316 static Dtype
317 status_dirproc (callerdat, dir, repos, update_dir, entries)
318     void *callerdat;
319     char *dir;
320     char *repos;
321     char *update_dir;
322     List *entries;
323 {
324     if (!quiet)
325         error (0, 0, "Examining %s", update_dir);
326     return (R_PROCESS);
327 }
328
329 /*
330  * Print out a tag and its type
331  */
332 static int
333 tag_list_proc (p, closure)
334     Node *p;
335     void *closure;
336 {
337     char *branch = NULL;
338     char *buf;
339
340     if (RCS_nodeisbranch (xrcsnode, p->key))
341         branch = RCS_whatbranch(xrcsnode, p->key) ;
342
343     buf = xmalloc (80 + strlen (p->key)
344                    + (branch ? strlen (branch) : strlen (p->data)));
345     sprintf (buf, "\t%-25s\t(%s: %s)\n", p->key,
346              branch ? "branch" : "revision",
347              branch ? branch : p->data);
348     cvs_output (buf, 0);
349     free (buf);
350
351     if (branch)
352         free (branch);
353
354     return (0);
355 }