home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / src / status.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  7KB  |  338 lines

  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 1.4 kit.
  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.     NULL
  30. };
  31.  
  32. int
  33. status (argc, argv)
  34.     int argc;
  35.     char **argv;
  36. {
  37.     int c;
  38.     int err = 0;
  39.  
  40.     if (argc == -1)
  41.     usage (status_usage);
  42.  
  43.     optind = 1;
  44.     while ((c = getopt (argc, argv, "vlR")) != -1)
  45.     {
  46.     switch (c)
  47.     {
  48.         case 'v':
  49.         long_format = 1;
  50.         break;
  51.         case 'l':
  52.         local = 1;
  53.         break;
  54.         case 'R':
  55.         local = 0;
  56.         break;
  57.         case '?':
  58.         default:
  59.         usage (status_usage);
  60.         break;
  61.     }
  62.     }
  63.     argc -= optind;
  64.     argv += optind;
  65.  
  66.     wrap_setup ();
  67.  
  68. #ifdef CLIENT_SUPPORT
  69.     if (client_active) {
  70.       start_server ();
  71.  
  72.       ign_setup ();
  73.  
  74.       if (long_format)
  75.     send_arg("-v");
  76.       if (local)
  77.     send_arg("-l");
  78.  
  79.       send_file_names (argc, argv, SEND_EXPAND_WILD);
  80.       /* XXX This should only need to send file info; the file
  81.      contents themselves will not be examined.  */
  82.       send_files (argc, argv, local, 0);
  83.  
  84.       send_to_server ("status\012", 0);
  85.       err = get_responses_and_close ();
  86.  
  87.       return err;
  88.     }
  89. #endif
  90.  
  91.     /* start the recursion processor */
  92.     err = start_recursion (status_fileproc, (FILESDONEPROC) NULL,
  93.                status_dirproc, (DIRLEAVEPROC) NULL, NULL,
  94.                argc, argv, local,
  95.                W_LOCAL, 0, 1, (char *) NULL, 1);
  96.  
  97.     return (err);
  98. }
  99.  
  100. /*
  101.  * display the status of a file
  102.  */
  103. /* ARGSUSED */
  104. static int
  105. status_fileproc (callerdat, finfo)
  106.     void *callerdat;
  107.     struct file_info *finfo;
  108. {
  109.     Ctype status;
  110.     char *sstat;
  111.     Vers_TS *vers;
  112.  
  113.     status = Classify_File (finfo, (char *) NULL, (char *) NULL, (char *) NULL,
  114.                 1, 0, &vers, 0);
  115.     switch (status)
  116.     {
  117.     case T_UNKNOWN:
  118.         sstat = "Unknown";
  119.         break;
  120.     case T_CHECKOUT:
  121.         sstat = "Needs Checkout";
  122.         break;
  123. #ifdef SERVER_SUPPORT
  124.     case T_PATCH:
  125.         sstat = "Needs Patch";
  126.         break;
  127. #endif
  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 (vers->ts_conflict)
  139.         sstat = "Unresolved Conflict";
  140.         else
  141.         sstat = "Locally Modified";
  142.         break;
  143.     case T_REMOVE_ENTRY:
  144.         sstat = "Entry Invalid";
  145.         break;
  146.     case T_UPTODATE:
  147.         sstat = "Up-to-date";
  148.         break;
  149.     case T_NEEDS_MERGE:
  150.         sstat = "Needs Merge";
  151.         break;
  152.     default:
  153.         sstat = "Classify Error";
  154.         break;
  155.     }
  156.  
  157.     cvs_output ("\
  158. ===================================================================\n", 0);
  159.     if (vers->ts_user == NULL)
  160.     {
  161.     cvs_output ("File: no file ", 0);
  162.     cvs_output (finfo->file, 0);
  163.     cvs_output ("\t\tStatus: ", 0);
  164.     cvs_output (sstat, 0);
  165.     cvs_output ("\n\n", 0);
  166.     }
  167.     else
  168.     {
  169.     char *buf;
  170.     buf = xmalloc (strlen (finfo->file) + strlen (sstat) + 80);
  171.     sprintf (buf, "File: %-17s\tStatus: %s\n\n", finfo->file, sstat);
  172.     cvs_output (buf, 0);
  173.     free (buf);
  174.     }
  175.  
  176.     if (vers->vn_user == NULL)
  177.     {
  178.     cvs_output ("   Working revision:\tNo entry for ", 0);
  179.     cvs_output (finfo->file, 0);
  180.     cvs_output ("\n", 0);
  181.     }
  182.     else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
  183.     cvs_output ("   Working revision:\tNew file!\n", 0);
  184. #ifdef SERVER_SUPPORT
  185.     else if (server_active)
  186.     {
  187.     cvs_output ("   Working revision:\t", 0);
  188.     cvs_output (vers->vn_user, 0);
  189.     cvs_output ("\n", 0);
  190.     }
  191. #endif
  192.     else
  193.     {
  194.     cvs_output ("   Working revision:\t", 0);
  195.     cvs_output (vers->vn_user, 0);
  196.     cvs_output ("\t", 0);
  197.     cvs_output (vers->ts_rcs, 0);
  198.     cvs_output ("\n", 0);
  199.     }
  200.  
  201.     if (vers->vn_rcs == NULL)
  202.     cvs_output ("   Repository revision:\tNo revision control file\n", 0);
  203.     else
  204.     {
  205.     cvs_output ("   Repository revision:\t", 0);
  206.     cvs_output (vers->vn_rcs, 0);
  207.     cvs_output ("\t", 0);
  208.     cvs_output (vers->srcfile->path, 0);
  209.     cvs_output ("\n", 0);
  210.     }
  211.  
  212.     if (vers->entdata)
  213.     {
  214.     Entnode *edata;
  215.  
  216.     edata = vers->entdata;
  217.     if (edata->tag)
  218.     {
  219.         if (vers->vn_rcs == NULL)
  220.         {
  221.         cvs_output ("   Sticky Tag:\t\t", 0);
  222.         cvs_output (edata->tag, 0);
  223.         cvs_output (" - MISSING from RCS file!\n", 0);
  224.         }
  225.         else
  226.         {
  227.         if (isdigit (edata->tag[0]))
  228.         {
  229.             cvs_output ("   Sticky Tag:\t\t", 0);
  230.             cvs_output (edata->tag, 0);
  231.             cvs_output ("\n", 0);
  232.         }
  233.         else
  234.         {
  235.             char *branch = NULL;
  236.  
  237.             if (RCS_isbranch (finfo->rcs, edata->tag))
  238.             branch = RCS_whatbranch(finfo->rcs, edata->tag);
  239.  
  240.             cvs_output ("   Sticky Tag:\t\t", 0);
  241.             cvs_output (edata->tag, 0);
  242.             cvs_output (" (", 0);
  243.             cvs_output (branch ? "branch" : "revision", 0);
  244.             cvs_output (": ", 0);
  245.             cvs_output (branch ? branch : vers->vn_rcs, 0);
  246.             cvs_output (")\n", 0);
  247.  
  248.             if (branch)
  249.             free (branch);
  250.         }
  251.         }
  252.     }
  253.     else if (!really_quiet)
  254.         cvs_output ("   Sticky Tag:\t\t(none)\n", 0);
  255.  
  256.     if (edata->date)
  257.     {
  258.         cvs_output ("   Sticky Date:\t\t", 0);
  259.         cvs_output (edata->date, 0);
  260.         cvs_output ("\n", 0);
  261.     }
  262.     else if (!really_quiet)
  263.         cvs_output ("   Sticky Date:\t\t(none)\n", 0);
  264.  
  265.     if (edata->options && edata->options[0])
  266.     {
  267.         cvs_output ("   Sticky Options:\t", 0);
  268.         cvs_output (edata->options, 0);
  269.         cvs_output ("\n", 0);
  270.     }
  271.     else if (!really_quiet)
  272.         cvs_output ("   Sticky Options:\t(none)\n", 0);
  273.  
  274.     if (long_format && vers->srcfile)
  275.     {
  276.         List *symbols = RCS_symbols(vers->srcfile);
  277.  
  278.         cvs_output ("\n   Existing Tags:\n", 0);
  279.         if (symbols)
  280.         {
  281.         xrcsnode = finfo->rcs;
  282.         (void) walklist (symbols, tag_list_proc, NULL);
  283.         }
  284.         else
  285.         cvs_output ("\tNo Tags Exist\n", 0);
  286.     }
  287.     }
  288.  
  289.     cvs_output ("\n", 0);
  290.     freevers_ts (&vers);
  291.     return (0);
  292. }
  293.  
  294. /*
  295.  * Print a warm fuzzy message
  296.  */
  297. /* ARGSUSED */
  298. static Dtype
  299. status_dirproc (callerdat, dir, repos, update_dir, entries)
  300.     void *callerdat;
  301.     char *dir;
  302.     char *repos;
  303.     char *update_dir;
  304.     List *entries;
  305. {
  306.     if (!quiet)
  307.     error (0, 0, "Examining %s", update_dir);
  308.     return (R_PROCESS);
  309. }
  310.  
  311. /*
  312.  * Print out a tag and its type
  313.  */
  314. static int
  315. tag_list_proc (p, closure)
  316.     Node *p;
  317.     void *closure;
  318. {
  319.     char *branch = NULL;
  320.     char *buf;
  321.  
  322.     if (RCS_isbranch (xrcsnode, p->key))
  323.     branch = RCS_whatbranch(xrcsnode, p->key) ;
  324.  
  325.     buf = xmalloc (80 + strlen (p->key)
  326.            + (branch ? strlen (branch) : strlen (p->data)));
  327.     sprintf (buf, "\t%-25.25s\t(%s: %s)\n", p->key,
  328.          branch ? "branch" : "revision",
  329.          branch ? branch : p->data);
  330.     cvs_output (buf, 0);
  331.     free (buf);
  332.  
  333.     if (branch)
  334.     free (branch);
  335.  
  336.     return (0);
  337. }
  338.