home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / collect_.c < prev    next >
C/C++ Source or Header  |  1992-01-19  |  9KB  |  304 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: collect_sets.c,v 1.15.1.1 91/01/29 07:16:13 berliner Exp $";
  3. #endif 
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Collect Sets
  12.  *
  13.  *    Collects the interesting file names from the administration and
  14.  *    the repository in a number of variables:
  15.  *                            solved by:
  16.  *        Clist    conflict-ridden            (user)
  17.  *        Glist    modified, needs merging        (update)
  18.  *        Mlist    modified, needs checking in    (commit)
  19.  *        Olist    needs checking out        (update)
  20.  *        Alist    to be added            (commit)
  21.  *        Rlist    to be removed            (commit)
  22.  *        Wlist    remove entry            (update)
  23.  *        Llist    locked list            (commit)
  24.  *        Blist    branch list            (commit)
  25.  *        Dlist    directory list            (update)
  26.  *
  27.  *    Returns non-zero on error.
  28.  */
  29.  
  30. #include "cvs.h"
  31.  
  32. extern char update_dir[];
  33.  
  34. Collect_Sets(argc, argv)
  35.     int argc;
  36.     char *argv[];
  37. {
  38.     register int i;
  39.     char tmp[MAXPATHLEN], update_user[MAXPATHLEN];
  40.     int ret = 0;
  41.  
  42.     /*
  43.      * By default, a call here must wipe the slate clean
  44.      */
  45.     Clist[0] = Glist[0] = Mlist[0] = Olist[0] = Dlist[0] = '\0';
  46.     Alist[0] = Rlist[0] = Wlist[0] = Llist[0] = Blist[0] = '\0';
  47.     for (i = 0; i < argc; i++) {
  48.     (void) strcpy(User, argv[i]);
  49.     if (update_dir[0] != '\0')
  50.         (void) sprintf(update_user, "%s%c%s", update_dir, DIRSEP, User);
  51.     else
  52.         (void) strcpy(update_user, User);
  53.     if (force_tag_match && (Tag[0] != '\0' || Date[0] != '\0'))
  54.         Locate_RCS();
  55.     else
  56.         (void) sprintf(Rcs, "%s%c%s%s", Repository, DIRSEP, User, RCSEXT);
  57.     if (isdir(User)) {        /* just a directory -- add to Dlist */
  58.         (void) strcat(Dlist, " ");
  59.         (void) strcat(Dlist, User);
  60.         continue;
  61.     }
  62.     Version_TS(Rcs, Tag, User);
  63.     if (VN_User[0] == '\0') {
  64.         /*
  65.          * No entry available, TS_Rcs is invalid
  66.          */
  67.         if (VN_Rcs[0] == '\0') {
  68.         /*
  69.          * There is no RCS file either
  70.          */
  71.         if (TS_User[0] == '\0')    { /* there is no user file */
  72.             if (!force_tag_match || !isfile(Rcs)) {
  73.             warn(0, "nothing known about %s", update_user);
  74.             ret++;
  75.             }
  76.         } else {        /* there is a user file */
  77.             if (!force_tag_match) {
  78.             warn(0, "use `cvs add' to create entry for %s",
  79.                  update_user);
  80.             ret++;
  81.             }
  82.         }
  83.         } else {
  84.         /*
  85.          * There is an RCS file
  86.          */
  87.         if (TS_User[0] == '\0') {
  88.             /*
  89.              * There is no user file; ad it to the Olist
  90.              */
  91.             (void) strcat(Olist, " ");
  92.             (void) strcat(Olist, User);
  93.         } else {
  94.             /*
  95.              * There is a user file; print a warning and add it
  96.              * to the conflict list, Clist, only if it is indeed
  97.              * different from what we plan to extract
  98.              */
  99.             No_Difference(0);
  100.             if (strcmp(TS_Rcs, TS_User) == 0) {
  101.             (void) strcat(Olist, " ");
  102.             (void) strcat(Olist, User);
  103.             } else {
  104.             warn(0, "move away %s; it is in the way",
  105.                  update_user);
  106.             (void) strcat(Clist, " ");
  107.             (void) strcat(Clist, User);
  108.             ret++;
  109.             }
  110.         }
  111.         }
  112.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  113.         /*
  114.          * An entry for a new-born file; TS_Rcs is dummy
  115.          */
  116.         if (TS_User[0] == '\0') {
  117.         /*
  118.          * There is no user file, but there should be one;
  119.          * add it to the remove entry list.
  120.          */
  121.         warn(0, "warning: new-born %s has disappeared", update_user);
  122.         (void) strcat(Wlist, " ");
  123.         (void) strcat(Wlist, User);
  124.         } else {
  125.         /*
  126.          * There is a user file
  127.          */
  128.         if (VN_Rcs[0] == '\0') {
  129.             /*
  130.              * There is no RCS file, so add it to the add entry list
  131.              */
  132.             (void) strcat(Alist, " ");
  133.             (void) strcat(Alist, User);
  134.         } else {
  135.             /*
  136.              * There is an RCS file, so someone else must have
  137.              * checked one in behind our back; added to the conflict
  138.              * list
  139.              */
  140.             warn(0, "conflict: %s created independently by second party",
  141.              update_user);
  142.             (void) strcat(Clist, " ");
  143.             (void) strcat(Clist, User);
  144.             ret++;
  145.         }
  146.         }
  147.     } else if (VN_User[0] == '-') {
  148.         /*
  149.          * An entry for a removed file, TS_Rcs is invalid
  150.          */
  151.         if (TS_User[0] == '\0') {
  152.         /*
  153.          * There is no user file (as it should be)
  154.          */
  155.         (void) sprintf(tmp, "-%s", VN_Rcs);
  156.         if (strcmp(tmp, "-") == 0) {
  157.             /*
  158.              * There is no RCS file; this is all-right, but it
  159.              * has been removed independently by a second party;
  160.              * added to the remove entry list.
  161.              */
  162.             (void) strcat(Wlist, " ");
  163.             (void) strcat(Wlist, User);
  164.         } else if (strcmp(tmp, VN_User) == 0) {
  165.             /*
  166.              * The RCS file is the same version as the user file,
  167.              * and that's OK; added to the to be removed list
  168.              */
  169.             (void) strcat(Rlist, " ");
  170.             (void) strcat(Rlist, User);
  171.         } else {
  172.             /*
  173.              * The RCS file is a newer version than the user file;
  174.              * and this is defintely not OK; make it a conflict.
  175.              */
  176.             warn(0, "conflict: removed %s was modified by second party",
  177.              update_user);
  178.             (void) strcat(Clist, " ");
  179.             (void) strcat(Clist, User);
  180.             ret++;
  181.         }
  182.         } else {
  183.         /*
  184.          * The user file shouldn't be there
  185.          */
  186.         warn(0, "%s should be removed and is still there", update_user);
  187.         ret++;
  188.         }
  189.     } else {
  190.         /*
  191.          * A normal entry, TS_Rcs is valid
  192.          */
  193.         if (VN_Rcs[0] == '\0') {
  194.         /*
  195.          * There is no RCS file
  196.          */
  197.         if (TS_User[0] == '\0') {
  198.             /*
  199.              * There is no user file, so just remove the entry
  200.              */
  201.             warn(0, "warning: %s is not (any longer) pertinent",
  202.              update_user);
  203.             (void) strcat(Wlist, " ");
  204.             (void) strcat(Wlist, User);
  205.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  206.             /*
  207.              * The user file is still unmodified, so just remove it
  208.              * from the entry list
  209.              */
  210.             if (!force_tag_match || !isfile(Rcs)) {
  211.             warn(0, "%s is no longer in the repository",
  212.                  update_user);
  213.             (void) strcat(Wlist, " ");
  214.             (void) strcat(Wlist, User);
  215.             }
  216.         } else {
  217.             /*
  218.              * The user file has been modified and since it is no
  219.              * longer in the repository, a conflict is raised
  220.              */
  221.             if (!force_tag_match) {
  222.             Locate_RCS();
  223.             (void) No_Difference(0);
  224.             if (strcmp(TS_User, TS_Rcs) == 0) {
  225.                 warn(0,
  226.         "warning: %s is not (any longer) pertinent",
  227.                  update_user);
  228.                 (void) strcat(Wlist, " ");
  229.                 (void) strcat(Wlist, User);
  230.             } else {
  231.                 warn(0,
  232.         "conflict: %s is modified but no longer in the repository",
  233.                  update_user);
  234.                 (void) strcat(Clist, " ");
  235.                 (void) strcat(Clist, User);
  236.                 ret++;
  237.             }
  238.             }
  239.         }
  240.         } else if (strcmp(VN_Rcs, VN_User) == 0) {
  241.         /*
  242.          * The RCS file is the same version as the user file
  243.          */
  244.         if (TS_User[0] == '\0') {
  245.             /*
  246.              * There is no user file, so note that it was lost
  247.              * and extract a new version
  248.              */
  249.             if (strcmp(command, "checkout") != 0 &&
  250.             strcmp(command, "co") != 0 &&
  251.             strcmp(command, "get") != 0)
  252.             warn(0, "warning: %s was lost", update_user);
  253.             (void) strcat(Olist, " ");
  254.             (void) strcat(Olist, User);
  255.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  256.             /*
  257.              * The user file is still unmodified, so nothing
  258.              * special at all to do -- no lists updated
  259.              */
  260.         } else {
  261.             /*
  262.              * The user file appears to have been modified, but
  263.              * we call No_Difference to verify that it really
  264.              * has been modified -- it updates the Mlist,
  265.              * if necessary.
  266.              */
  267.             (void) No_Difference(0);
  268.         }
  269.         } else {
  270.         /*
  271.          * The RCS file is a newer version than the user file
  272.          */
  273.         if (TS_User[0] == '\0') {
  274.             /*
  275.              * There is no user file, so just get it
  276.              */
  277.             if (strcmp(command, "checkout") != 0 &&
  278.             strcmp(command, "co") != 0 &&
  279.             strcmp(command, "get") != 0)
  280.             warn(0, "warning: %s was lost", update_user);
  281.             (void) strcat(Olist, " ");
  282.             (void) strcat(Olist, User);
  283.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  284.             /*
  285.              * The user file is still unmodified, so just get it
  286.              * as well
  287.              */
  288.             (void) strcat(Olist, " ");
  289.             (void) strcat(Olist, User);
  290.         } else {
  291.             /*
  292.              * The user file appears to have been modified; we call
  293.              * No_Difference to verify this for us, and it updates
  294.              * Glist if it has really been modified, and Olist if
  295.              * it hasn't
  296.              */
  297.             (void) No_Difference(1);
  298.         }
  299.         }
  300.     }
  301.     }
  302.     return (ret);
  303. }
  304.