/contrib/cvs/src/status.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 357 lines · 274 code · 39 blank · 44 comment · 44 complexity · 2b5766f0430903f036df9e9ad1cdc22a MD5 · raw file

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