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

  1. #ifndef lint
  2. static char rcsid[] = "$Id: checkout.c,v 1.19 89/11/19 23:40:30 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.  * Create Version
  12.  *
  13.  *    "checkout" creates a "version" of an RCS repository.  This version
  14.  *    is owned totally by the user and is actually an independent
  15.  *    copy, to be dealt with as seen fit.  Once "checkout" has been called
  16.  *    in a given directory, it never needs to be called again.  The
  17.  *    user can keep up-to-date by calling "update" when he feels like it;
  18.  *    this will supply him with a merge of his own modifications
  19.  *    and the changes made in the RCS original.  See "update" for details.
  20.  *
  21.  *    "checkout" can be given a list of directories or files to be updated
  22.  *    and in the case of a directory, will recursivley create any
  23.  *    sub-directories that exist in the repository.
  24.  *
  25.  *    When the user is satisfied with his own modifications, the
  26.  *    present version can be committed by "commit"; this keeps the present
  27.  *    version in tact, usually.
  28.  *
  29.  *    The call is
  30.  *        cvs checkout [options] <module-name>...
  31.  *
  32.  *    And the options supported are:
  33.  *        -f        Forces the symbolic tag specified with
  34.  *                the -r option to match in the RCS file, else
  35.  *                the RCS file is not extracted.
  36.  *        -Q        Causes "update" to be really quiet.
  37.  *        -q        Causes "update" and tag mis-matches to
  38.  *                be quiet; "update" just doesn't print a
  39.  *                message as it chdirs down a level.
  40.  *        -c        Cat's the modules file, sorted, to stdout.
  41.  *        -n        Causes "update" to *not* run any checkout prog.
  42.  *        -l        Only updates the local directory, not recursive.
  43.  *        -p        Prunes empty directories after checking them out
  44.  *        -r tag        Checkout revision 'tag', subject to the
  45.  *                setting of the -f option.
  46.  *        -D date-string    Checkout the most recent file equal to or
  47.  *                before the specifed date.
  48.  *
  49.  *    "checkout" creates a directory ./CVS.adm, in which it keeps its
  50.  *    administration, in two files, Repository and Entries.
  51.  *    The first contains the name of the repository.  The second
  52.  *    contains one line for each registered file,
  53.  *    consisting of the version number it derives from,
  54.  *    its time stamp at derivation time and its name.  Both files
  55.  *    are normal files and can be edited by the user, if necessary (when
  56.  *    the repository is moved, e.g.)
  57.  */
  58.  
  59. #include "cvs.h"
  60.  
  61. extern int update_prune_dirs;
  62. extern int update_recursive;
  63. extern int run_module_prog;
  64. extern DBM *open_module();
  65.  
  66. checkout(argc, argv)
  67.     int argc;
  68.     char *argv[];
  69. {
  70.     register int i;
  71.     int c;
  72.     DBM *db;
  73.     int cat = 0, err = 0;
  74.  
  75.     if (argc == -1)
  76.     checkout_usage();
  77.     optind = 1;
  78.     while ((c = getopt(argc, argv, "nflpQqcr:D:")) != -1) {
  79.     switch (c) {
  80.     case 'n':
  81.         run_module_prog = 0;
  82.         break;
  83.     case 'Q':
  84.         really_quiet = 1;
  85.         /* FALL THROUGH */
  86.     case 'q':
  87.         quiet = 1;
  88.         break;
  89.     case 'l':
  90.         update_recursive = 0;
  91.         break;
  92.     case 'p':
  93.         update_prune_dirs = 1;
  94.         break;
  95.     case 'c':
  96.         cat = 1;
  97.         break;
  98.     case 'f':
  99.         force_tag_match = 1;
  100.         break;
  101.     case 'r':
  102.         (void) strcpy(Tag, optarg);
  103.         break;
  104.     case 'D':
  105.         Make_Date(optarg, Date);
  106.         break;
  107.     case '?':
  108.     default:
  109.         checkout_usage();
  110.         break;
  111.     }
  112.     }
  113.     argc -= optind;
  114.     argv += optind;
  115.     if ((!cat && argc == 0) || (cat && argc != 0) || (Tag[0] && Date[0]))
  116.     checkout_usage();
  117.     if (cat) {
  118.     cat_module();
  119.     exit(0);
  120.     }
  121.     db = open_module();
  122.     for (i = 0; i < argc; i++)
  123.     err += do_module(db, argv[i], CHECKOUT, "Updating");
  124.     close_module(db);
  125.     exit(err);
  126. }
  127.  
  128. Build_Dirs_and_chdir(dir)
  129.     char *dir;
  130. {
  131.     FILE *fp;
  132.     char path[MAXPATHLEN];
  133.     char *slash;
  134.     char *cp;
  135.  
  136.     (void) strcpy(path, dir);
  137.     for (cp = path; (slash = index_sep(cp)) != NULL; cp = slash+1) {
  138.     *slash = '\0';
  139.     (void) mkdir(cp, 0777);
  140.     if (chdir(cp) < 0) {
  141.         warn(1, "cannot chdir to %s", cp);
  142.         return (1);
  143.     }
  144.     if (!isfile(CVSADM)) {
  145.         (void) sprintf(Repository, "%s%c%s", CVSroot, DIRSEP, path);
  146.         Create_Admin(Repository, DFLT_RECORD);
  147.         fp = open_file(CVSADM_ENTSTAT, "w+");
  148.         (void) fclose(fp);
  149.     }
  150.     *slash = DIRSEP;
  151.     }
  152.     (void) mkdir(cp, 0777);
  153.     if (chdir(cp) < 0) {
  154.     warn(1, "cannot chdir to %s", cp);
  155.     return (1);
  156.     }
  157.     return (0);
  158. }
  159.  
  160. static
  161. checkout_usage()
  162. {
  163.     (void) fprintf(stderr,
  164.     "Usage: %s %s [-Qqlfnp] [-c] [-r tag|-D date] modules...\n",
  165.            progname, command);
  166.     exit(1);
  167. }
  168.