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

  1. #ifndef lint
  2. static char rcsid[] = "$Id: join.c,v 1.4 89/11/19 23:40:36 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.  * Join
  12.  *
  13.  *    Do an implicit checkout and merge between RCS revisions in the
  14.  *    RCS file.  This is most always used after the "checkin" script
  15.  *    has added new revisions to files that have been locally modified.
  16.  *    A manual "join" command can be run on the files listed in the
  17.  *    "checkin" output to produce an "rcsmerge" of the current revision
  18.  *    and the specified vendor branch revision.
  19.  *
  20.  *    Need to be careful if the local user file has been checked out and
  21.  *    is modified.  Don't want to mess with it in this case.
  22.  */
  23.  
  24. #include "cvs.h"
  25.  
  26. extern char update_dir[];
  27. extern int force_tag_match;
  28.  
  29. join(argc, argv)
  30.     int argc;
  31.     char *argv[];
  32. {
  33.     register int i;
  34.     int c, err = 0;
  35.  
  36.     if (argc == -1)
  37.     join_usage();
  38.     optind = 1;
  39.     while ((c = getopt(argc, argv, "fQqD:r:")) != -1) {
  40.     switch (c) {
  41.     case 'Q':
  42.         really_quiet = 1;
  43.         /* FALL THROUGH */
  44.     case 'q':
  45.         quiet = 1;
  46.         break;
  47.     case 'f':
  48.         force_tag_match = 1;
  49.         break;
  50.     case 'D':
  51.         if (Tag[0] != '\0' || Date[0] != '\0')
  52.         error(0, "no more than one revision/date can be specified");
  53.         Make_Date(optarg, Date);
  54.         break;
  55.     case 'r':
  56.         if (Tag[0] != '\0' || Date[0] != '\0')
  57.         error(0, "no more than one revision/date can be specified");
  58.         (void) strcpy(Tag, optarg);
  59.         break;
  60.     case '?':
  61.     default:
  62.         join_usage();
  63.         break;
  64.     }
  65.     }
  66.     argc -= optind;
  67.     argv += optind;
  68.     if (argc < 1)
  69.     join_usage();
  70.     if (Tag[0] == '\0' && Date[0] == '\0')
  71.     error(0, "must specify one revision/date!");
  72.     Name_Repository();
  73.     Reader_Lock();
  74.     (void) Collect_Sets(argc, argv);
  75.     if (Clist[0] || Glist[0] || Mlist[0] || Alist[0] || Rlist[0] || Wlist[0])
  76.     error(0, "conflicts exist; cannot join a modified file");
  77.     if (Dlist[0])
  78.     error(0, "cannot join directories -%s", Dlist);
  79.     for (i = 0; i < argc; i++)
  80.     err += join_file(argv[i]);
  81.     Lock_Cleanup(0);
  82.     exit(err);
  83. }
  84.  
  85. /*
  86.  * Called for each file that is to be "join"ed.  Need to find out if the
  87.  * file is modified or not, and blow it off if it is.
  88.  */
  89. static
  90. join_file(file)
  91.     char *file;
  92. {
  93.     char vers[50];
  94.  
  95.     (void) strcpy(User, file);
  96.     (void) sprintf(Rcs, "%s%c%s%s", Repository, DIRSEP, User, RCSEXT);
  97.     Version_Number(Rcs, Tag, Date, vers);
  98.     if (vers[0] == '\0') {
  99.     if (!quiet)
  100.         warn(0, "cannot find revision %s for %s", Tag[0] ? Tag:Date, Rcs);
  101.     return (1);
  102.     }
  103.     (void) unlink(User);
  104.     Scratch_Entry(User);
  105.     (void) sprintf(prog, "%s -j%s %s %s", RCS_CO, vers, Rcs, User);
  106.     if (system(prog) != 0) {
  107.     if (!quiet)
  108.         warn(0, "co of revision %s for %s failed", VN_Rcs, Rcs);
  109.     return (1);
  110.     }
  111.     if (!really_quiet)
  112.     printf("J %s\n", User);
  113.     if (cvswrite == TRUE)
  114.     xchmod(User, 1);
  115.     Version_TS(Rcs, "", User);        /* For head */
  116.     (void) sprintf(TS_User, "joined %s", User);    /* To appear to be modified */
  117.     Register(User, VN_Rcs, TS_User);
  118.     return (0);
  119. }
  120.  
  121. static
  122. join_usage()
  123. {
  124.     (void) fprintf(stderr, "%s %s [-Qqf] [-r tag|-D date] files...\n",
  125.            progname, command);
  126.     exit(1);
  127. }
  128.