2 * Copyright (c) 1992, Brian Berliner and Jeff Polk
3 * Copyright (c) 1989-1992, Brian Berliner
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 source distribution.
10 * "checkout" creates a "version" of an RCS repository. This version is owned
11 * totally by the user and is actually an independent copy, to be dealt with
12 * as seen fit. Once "checkout" has been called in a given directory, it
13 * never needs to be called again. The user can keep up-to-date by calling
14 * "update" when he feels like it; this will supply him with a merge of his
15 * own modifications and the changes made in the RCS original. See "update"
18 * "checkout" can be given a list of directories or files to be updated and in
19 * the case of a directory, will recursivley create any sub-directories that
20 * exist in the repository.
22 * When the user is satisfied with his own modifications, the present version
23 * can be committed by "commit"; this keeps the present version in tact,
26 * The call is cvs checkout [options] <module-name>...
28 * "checkout" creates a directory ./CVS, in which it keeps its administration,
29 * in two files, Repository and Entries. The first contains the name of the
30 * repository. The second contains one line for each registered file,
31 * consisting of the version number it derives from, its time stamp at
32 * derivation time and its name. Both files are normal files and can be
33 * edited by the user, if necessary (when the repository is moved, e.g.)
38 static char *findslash (char *start, char *p);
39 static int checkout_proc (int argc, char **argv, char *where,
40 char *mwhere, char *mfile, int shorten,
41 int local_specified, char *omodule,
44 static const char *const checkout_usage[] =
46 "Usage:\n %s %s [-ANPRcflnps] [-r rev] [-D date] [-d dir]\n",
47 " [-j rev1] [-j rev2] [-k kopt] modules...\n",
48 "\t-A\tReset any sticky tags/date/kopts.\n",
49 "\t-N\tDon't shorten module paths if -d specified.\n",
50 "\t-P\tPrune empty directories.\n",
51 "\t-R\tProcess directories recursively.\n",
52 "\t-c\t\"cat\" the module database.\n",
53 "\t-f\tForce a head revision match if tag/date not found.\n",
54 "\t-l\tLocal directory only, not recursive\n",
55 "\t-n\tDo not run module program (if any).\n",
56 "\t-p\tCheck out files to standard output (avoids stickiness).\n",
57 "\t-s\tLike -c, but include module status.\n",
58 "\t-r rev\tCheck out revision or tag. (implies -P) (is sticky)\n",
59 "\t-D date\tCheck out revisions as of date. (implies -P) (is sticky)\n",
60 "\t-d dir\tCheck out into dir instead of module name.\n",
61 "\t-k kopt\tUse RCS kopt -k option on checkout. (is sticky)\n",
62 "\t-j rev\tMerge in changes made between current revision and rev.\n",
63 "(Specify the --help global option for a list of other help options)\n",
67 static const char *const export_usage[] =
69 "Usage: %s %s [-NRfln] [-r rev] [-D date] [-d dir] [-k kopt] module...\n",
70 "\t-N\tDon't shorten module paths if -d specified.\n",
71 "\t-f\tForce a head revision match if tag/date not found.\n",
72 "\t-l\tLocal directory only, not recursive\n",
73 "\t-R\tProcess directories recursively (default).\n",
74 "\t-n\tDo not run module program (if any).\n",
75 "\t-r rev\tExport revision or tag.\n",
76 "\t-D date\tExport revisions as of date.\n",
77 "\t-d dir\tExport into dir instead of module name.\n",
78 "\t-k kopt\tUse RCS kopt -k option on checkout.\n",
79 "(Specify the --help global option for a list of other help options)\n",
83 static int checkout_prune_dirs;
84 static int force_tag_match;
89 static int tag_validated;
91 static char *join_rev1;
92 static char *join_rev2;
93 static int join_tags_validated;
94 static char *preload_update_dir;
95 static char *history_name;
96 static enum mtype m_type;
99 checkout (int argc, char **argv)
104 int cat = 0, err = 0, status = 0;
105 int run_module_prog = 1;
110 const char *const *valid_usage;
112 /* initialize static options */
119 tag = date = join_rev1 = join_rev2 = preload_update_dir = NULL;
121 tag_validated = join_tags_validated = 0;
125 * A smaller subset of options are allowed for the export command, which
126 * is essentially like checkout, except that it hard-codes certain
127 * options to be default (like -kv) and takes care to remove the CVS
128 * directory when it has done its duty
130 if (strcmp (cvs_cmd_name, "export") == 0)
133 valid_options = "+Nnk:d:flRQqr:D:";
134 valid_usage = export_usage;
139 valid_options = "+ANnk:d:flRpQqcsr:D:j:P";
140 valid_usage = checkout_usage;
150 while ((c = getopt (argc, argv, valid_options)) != -1)
163 options = RCS_check_kflag (optarg);
170 #ifdef SERVER_SUPPORT
171 /* The CVS 1.5 client sends these options (in addition to
172 Global_option requests), so we must ignore them. */
176 "-q or -Q must be specified before \"%s\"",
186 checkout_prune_dirs = 1;
190 run_module_prog = 0; /* don't run module prog when piping */
191 noexec = 1; /* so no locks will be created */
209 checkout_prune_dirs = 1;
212 date = Make_Date (optarg);
213 checkout_prune_dirs = 1;
217 error (1, 0, "only two -j options can be specified");
235 if (cat && argc != 0)
236 error (1, 0, "-c and -s must not get any arguments");
238 if (!cat && argc == 0)
239 error (1, 0, "must specify at least one module or directory");
241 if (where && pipeout)
242 error (1, 0, "-d and -p are mutually exclusive");
244 if (m_type == EXPORT)
247 error (1, 0, "must specify a tag or date");
249 if (tag && isdigit ((unsigned char) tag[0]))
250 error (1, 0, "tag `%s' must be a symbolic tag", tag);
253 #ifdef SERVER_SUPPORT
254 if (server_active && where != NULL)
256 server_pathname_check (where);
260 if (!cat && !pipeout && !safe_location( where )) {
261 error(1, 0, "Cannot check out files into the repository itself");
264 #ifdef CLIENT_SUPPORT
265 if (current_parsed_root->isremote)
273 expand_modules = (!cat && !pipeout
274 && supported_request ("expand-modules"));
278 /* This is done here because we need to read responses
279 from the server before we send the command checkout or
282 client_expand_modules (argc, argv, local);
285 if (!run_module_prog)
291 if (!force_tag_match)
297 if (checkout_prune_dirs && m_type == CHECKOUT)
299 client_prune_dirs = checkout_prune_dirs;
303 option_with_arg ("-d", where);
306 if (options != NULL && options[0] != '\0')
308 option_with_arg ("-r", tag);
310 client_senddate (date);
311 if (join_rev1 != NULL)
312 option_with_arg ("-j", join_rev1);
313 if (join_rev2 != NULL)
314 option_with_arg ("-j", join_rev2);
319 client_send_expansions (local, where, 1);
324 for (i = 0; i < argc; ++i)
326 client_nonexpanded_setup ();
329 send_to_server (m_type == EXPORT ? "export\012" : "co\012", 0);
330 return get_responses_and_close ();
332 #endif /* CLIENT_SUPPORT */
347 /* If we've specified something like "cvs co foo/bar baz/quux"
348 don't try to shorten names. There are a few cases in which we
349 could shorten (e.g. "cvs co foo/bar foo/baz"), but we don't
350 handle those yet. Better to have an extra directory created
351 than the thing checked out under the wrong directory name. */
357 /* If we will be calling history_write, work out the name to pass
367 history_name = xmalloc (strlen (tag) + strlen (date) + 2);
368 sprintf (history_name, "%s:%s", tag, date);
373 for (i = 0; i < argc; i++)
374 err += do_module (db, argv[i], m_type, "Updating", checkout_proc,
375 where, shorten, local, run_module_prog, !pipeout,
383 if (history_name != tag && history_name != date && history_name != NULL)
388 /* FIXME: This is and emptydir_name are in checkout.c for historical
389 reasons, probably want to move them. */
392 * safe_location ( char *where )
394 * Return true if where is a safe destination for a checkout.
397 * where The requested destination directory.
400 * current_parsed_root->directory
401 * current_parsed_root->isremote
402 * Used to locate our CVSROOT.
405 * true If we are running in client mode or if where is not located
406 * within the CVSROOT.
410 * Exits with a fatal error message when various events occur, such as not
411 * being able to resolve a path or failing ot chdir to a path.
414 safe_location (char *where)
421 TRACE( TRACE_FUNCTION, "safe_location( where=%s )",
422 where ? where : "(null)" );
424 #ifdef CLIENT_SUPPORT
425 /* Don't compare remote CVSROOTs to our destination directory. */
426 if ( current_parsed_root->isremote ) return 1;
427 #endif /* CLIENT_SUPPORT */
429 /* set current - even if where is set we'll need to cd back... */
432 error (1, errno, "could not get working directory");
434 hardpath = xresolvepath ( current_parsed_root->directory );
436 /* if where is set, set current to as much of where as exists,
441 char *where_this_pass = xstrdup (where);
444 if (CVS_CHDIR (where_this_pass) != -1)
447 free (where_this_pass);
448 where_this_pass = xgetwd();
449 if (where_this_pass == NULL)
450 error (1, errno, "could not get working directory");
452 if (CVS_CHDIR (current) == -1)
454 "could not restore directory to `%s'", current);
457 current = where_this_pass;
460 else if (errno == ENOENT)
462 /* where_this_pass - last_component (where_this_pass) */
465 /* It's okay to cast out the const below since we know we
466 * allocated where_this_pass and have control of it.
468 if ((parent = (char *)last_component (where_this_pass))
471 /* strip the last_component */
478 * && last_component (where_this_pass) == where_this_pass
479 * means we've tried all the parent diretories and not one
480 * exists, so there is no need to test any portion of where
481 * - it is all being created.
483 free (where_this_pass);
488 /* we don't know how to handle other errors, so fail */
490 could not change directory to requested checkout directory `%s'",
493 } /* where != NULL */
495 hardpath_len = strlen (hardpath);
496 if (strlen (current) >= hardpath_len
497 && strncmp (current, hardpath, hardpath_len) == 0)
499 if (/* Current is a subdirectory of hardpath. */
500 current[hardpath_len] == '/'
502 /* Current is hardpath itself. */
503 || current[hardpath_len] == '\0')
506 /* It isn't a problem. For example, current is
507 "/foo/cvsroot-bar" and hardpath is "/foo/cvsroot". */
519 /* What to put in CVS/Repository. */
521 /* The path to the directory. */
524 struct dir_to_build *next;
527 static int build_dirs_and_chdir (struct dir_to_build *list,
530 static void build_one_dir (char *, char *, int);
533 build_one_dir (char *repository, char *dirpath, int sticky)
539 if (m_type == EXPORT)
540 error (1, 0, "cannot export into a working directory");
542 else if (m_type == CHECKOUT)
544 /* I suspect that this check could be omitted. */
545 if (!isdir (repository))
546 error (1, 0, "there is no repository %s", repository);
548 if (Create_Admin (".", dirpath, repository,
549 sticky ? tag : (char *) NULL,
550 sticky ? date : (char *) NULL,
552 /* FIXME? This is a guess. If it is important
553 for nonbranch to be set correctly here I
554 think we need to write it one way now and
555 then rewrite it later via WriteTag, once
556 we've had a chance to call RCS_nodeisbranch
563 fp = open_file (CVSADM_ENTSTAT, "w+");
564 if (fclose (fp) == EOF)
565 error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
566 #ifdef SERVER_SUPPORT
568 server_set_entstat (dirpath, repository);
575 * process_module calls us back here so we do the actual checkout stuff
579 checkout_proc (int argc, char **argv, char *where_orig, char *mwhere, char *mfile, int shorten, int local_specified, char *omodule, char *msg)
586 char *oldupdate = NULL;
590 (void) fprintf (stderr,
591 "%s-> checkout_proc (%s, %s, %s, %d, %d, %s, %s)\n",
593 where_orig ? where_orig : "(null)",
594 mwhere ? mwhere : "(null)",
595 mfile ? mfile : "(null)",
596 shorten, local_specified,
597 omodule ? omodule : "(null)",
602 * OK, so we're doing the checkout! Our args are as follows:
603 * argc,argv contain either dir or dir followed by a list of files
604 * where contains where to put it (if supplied by checkout)
605 * mwhere contains the module name or -d from module file
606 * mfile says do only that part of the module
607 * shorten = 1 says shorten as much as possible
608 * omodule is the original arg to do_module()
611 /* Set up the repository (maybe) for the bottom directory.
612 Allocate more space than we need so we don't need to keep
613 reallocating this string. */
614 repository = xmalloc (strlen (current_parsed_root->directory)
616 + (mfile == NULL ? 0 : strlen (mfile))
618 (void) sprintf (repository, "%s/%s",
619 current_parsed_root->directory, argv[0]);
620 Sanitize_Repository_Name (repository);
623 /* save the original value of preload_update_dir */
624 if (preload_update_dir != NULL)
625 oldupdate = xstrdup (preload_update_dir);
628 /* Allocate space and set up the where variable. We allocate more
629 space than necessary here so that we don't have to keep
630 reallocaing it later on. */
632 where = xmalloc (strlen (argv[0])
633 + (mfile == NULL ? 0 : strlen (mfile))
634 + (mwhere == NULL ? 0 : strlen (mwhere))
635 + (where_orig == NULL ? 0 : strlen (where_orig))
638 /* Yes, this could be written in a less verbose way, but in this
639 form it is quite easy to read.
641 FIXME? The following code that sets should probably be moved
642 to do_module in modules.c, since there is similar code in
643 patch.c and rtag.c. */
647 if (where_orig != NULL)
649 /* If the user has specified a directory with `-d' on the
650 command line, use it preferentially, even over the `-d'
651 flag in the modules file. */
653 (void) strcpy (where, where_orig);
655 else if (mwhere != NULL)
657 /* Second preference is the value of mwhere, which is from
658 the `-d' flag in the modules file. */
660 (void) strcpy (where, mwhere);
664 /* Third preference is the directory specified in argv[0]
665 which is this module'e directory in the repository. */
667 (void) strcpy (where, argv[0]);
672 /* Use the same preferences here, bug don't shorten -- that
673 is, tack on where_orig if it exists. */
677 if (where_orig != NULL)
679 (void) strcat (where, where_orig);
680 (void) strcat (where, "/");
683 /* If the -d flag in the modules file specified an absolute
684 directory, let the user override it with the command-line
687 if ((mwhere != NULL) && (! isabsolute (mwhere)))
688 (void) strcat (where, mwhere);
690 (void) strcat (where, argv[0]);
692 strip_trailing_slashes (where); /* necessary? */
695 /* At this point, the user may have asked for a single file or
696 directory from within a module. In that case, we should modify
697 where, repository, and argv as appropriate. */
701 /* The mfile variable can have one or more path elements. If
702 it has multiple elements, we want to tack those onto both
703 repository and where. The last element may refer to either
704 a file or directory. Here's what to do:
706 it refers to a directory
707 -> simply tack it on to where and repository
709 -> munge argv to contain `basename mfile` */
715 /* Paranoia check. */
717 if (mfile[strlen (mfile) - 1] == '/')
719 error (0, 0, "checkout_proc: trailing slash on mfile (%s)!",
724 /* Does mfile have multiple path elements? */
726 cp = strrchr (mfile, '/');
730 (void) strcat (repository, "/");
731 (void) strcat (repository, mfile);
732 (void) strcat (where, "/");
733 (void) strcat (where, mfile);
738 /* Now mfile is a single path element. */
740 path = xmalloc (strlen (repository) + strlen (mfile) + 5);
741 (void) sprintf (path, "%s/%s", repository, mfile);
744 /* It's a directory, so tack it on to repository and
745 where, as we did above. */
747 (void) strcat (repository, "/");
748 (void) strcat (repository, mfile);
749 (void) strcat (where, "/");
750 (void) strcat (where, mfile);
754 /* It's a file, which means we have to screw around with
764 if (preload_update_dir != NULL)
767 xrealloc (preload_update_dir,
768 strlen (preload_update_dir) + strlen (where) + 5);
769 strcat (preload_update_dir, "/");
770 strcat (preload_update_dir, where);
773 preload_update_dir = xstrdup (where);
776 * At this point, where is the directory we want to build, repository is
777 * the repository for the lowest level of the path.
779 * We need to tell build_dirs not only the path we want it to
780 * build, but also the repositories we want it to populate the
781 * path with. To accomplish this, we walk the path backwards, one
782 * pathname component at a time, constucting a linked list of
783 * struct dir_to_build.
787 * If we are sending everything to stdout, we can skip a whole bunch of
792 struct dir_to_build *head;
795 if (strncmp (repository, current_parsed_root->directory,
796 strlen (current_parsed_root->directory)) != 0)
798 internal error: %s doesn't start with %s in checkout_proc",
799 repository, current_parsed_root->directory);
801 /* We always create at least one directory, which corresponds to
802 the entire strings for WHERE and REPOSITORY. */
803 head = (struct dir_to_build *) xmalloc (sizeof (struct dir_to_build));
804 /* Special marker to indicate that we don't want build_dirs_and_chdir
805 to create the CVSADM directory for us. */
806 head->repository = NULL;
807 head->dirpath = xstrdup (where);
810 /* Make a copy of the repository name to play with. */
811 reposcopy = xstrdup (repository);
813 /* FIXME: this should be written in terms of last_component
814 instead of hardcoding '/'. This presumably affects OS/2,
815 NT, &c, if the user specifies '\'. Likewise for the call
817 cp = where + strlen (where);
820 struct dir_to_build *new;
822 cp = findslash (where, cp - 1);
824 break; /* we're done */
826 new = (struct dir_to_build *)
827 xmalloc (sizeof (struct dir_to_build));
828 new->dirpath = xmalloc (strlen (where));
830 /* If the user specified an absolute path for where, the
831 last path element we create should be the top-level
836 strncpy (new->dirpath, where, cp - where);
837 new->dirpath[cp - where] = '\0';
841 /* where should always be at least one character long. */
842 assert (where[0] != '\0');
843 strcpy (new->dirpath, "/");
848 /* Now figure out what repository directory to generate.
849 The most complete case would be something like this:
851 The modules file contains
854 The command issued was:
855 cvs co -d what/ever -N foo
857 The results in the CVS/Repository files should be:
858 . -> (don't touch CVS/Repository)
859 (I think this case might be buggy currently)
860 what -> (don't touch CVS/Repository)
861 ever -> . (same as "cd what/ever; cvs co -N foo")
862 bar -> Emptydir (generated dir -- not in repos)
863 baz -> quux (finally!) */
865 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
867 /* We can't walk up past CVSROOT. Instead, the
868 repository should be Emptydir. */
869 new->repository = emptydir_name ();
873 /* It's a directory in the repository! */
877 /* We'll always be below CVSROOT, but check for
879 rp = strrchr (reposcopy, '/');
882 "internal error: %s doesn't contain a slash",
886 new->repository = xmalloc (strlen (reposcopy) + 5);
887 (void) strcpy (new->repository, reposcopy);
889 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
891 /* Special case -- the repository name needs
892 to be "/path/to/repos/." (the trailing dot
893 is important). We might be able to get rid
894 of this after the we check out the other
895 code that handles repository names. */
896 (void) strcat (new->repository, "/.");
904 /* The top-level CVSADM directory should always be
905 current_parsed_root->directory. Create it, but only if WHERE is
906 relative. If WHERE is absolute, our current directory
907 may not have a thing to do with where the sources are
908 being checked out. If it does, build_dirs_and_chdir
909 will take care of creating adm files here. */
910 /* FIXME: checking where_is_absolute is a horrid kludge;
911 I suspect we probably can just skip the call to
912 build_one_dir whenever the -d command option was specified
915 if (!isabsolute (where) && top_level_admin && m_type == CHECKOUT)
917 /* It may be argued that we shouldn't set any sticky
918 bits for the top-level repository. FIXME? */
919 build_one_dir (current_parsed_root->directory, ".", argc <= 1);
921 #ifdef SERVER_SUPPORT
922 /* We _always_ want to have a top-level admin
923 directory. If we're running in client/server mode,
924 send a "Clear-static-directory" command to make
925 sure it is created on the client side. (See 5.10
926 in cvsclient.dvi to convince yourself that this is
927 OK.) If this is a duplicate command being sent, it
928 will be ignored on the client side. */
931 server_clear_entstat (".", current_parsed_root->directory);
936 /* Build dirs on the path if necessary and leave us in the
937 bottom directory (where if where was specified) doesn't
938 contain a CVS subdir yet, but all the others contain
939 CVS and Entries.Static files */
941 if (build_dirs_and_chdir (head, argc <= 1) != 0)
943 error (0, 0, "ignoring module %s", omodule);
948 /* set up the repository (or make sure the old one matches) */
949 if (!isfile (CVSADM))
953 if (!noexec && argc > 1)
955 /* I'm not sure whether this check is redundant. */
956 if (!isdir (repository))
957 error (1, 0, "there is no repository %s", repository);
959 Create_Admin (".", preload_update_dir, repository,
960 (char *) NULL, (char *) NULL, 0, 0,
962 fp = open_file (CVSADM_ENTSTAT, "w+");
963 if (fclose(fp) == EOF)
964 error(1, errno, "cannot close %s", CVSADM_ENTSTAT);
965 #ifdef SERVER_SUPPORT
967 server_set_entstat (where, repository);
972 /* I'm not sure whether this check is redundant. */
973 if (!isdir (repository))
974 error (1, 0, "there is no repository %s", repository);
976 Create_Admin (".", preload_update_dir, repository, tag, date,
978 /* FIXME? This is a guess. If it is important
979 for nonbranch to be set correctly here I
980 think we need to write it one way now and
981 then rewrite it later via WriteTag, once
982 we've had a chance to call RCS_nodeisbranch
984 0, 0, m_type == CHECKOUT);
991 if (m_type == EXPORT)
992 error (1, 0, "cannot export into working directory");
994 /* get the contents of the previously existing repository */
995 repos = Name_Repository ((char *) NULL, preload_update_dir);
996 if (fncmp (repository, repos) != 0)
998 error (0, 0, "existing repository %s does not match %s",
1000 error (0, 0, "ignoring module %s", omodule);
1010 * If we are going to be updating to stdout, we need to cd to the
1011 * repository directory so the recursion processor can use the current
1012 * directory as the place to find repository information
1016 if ( CVS_CHDIR (repository) < 0)
1018 error (0, errno, "cannot chdir to %s", repository);
1023 if (tag != NULL && !tag_validated)
1025 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag, NULL);
1031 which = W_LOCAL | W_REPOS;
1032 if (tag != NULL && !tag_validated)
1034 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag,
1040 if (tag != NULL || date != NULL || join_rev1 != NULL)
1043 if (! join_tags_validated)
1045 if (join_rev1 != NULL)
1046 tag_check_valid_join (join_rev1, argc - 1, argv + 1, 0, aflag,
1048 if (join_rev2 != NULL)
1049 tag_check_valid_join (join_rev2, argc - 1, argv + 1, 0, aflag,
1051 join_tags_validated = 1;
1055 * if we are going to be recursive (building dirs), go ahead and call the
1056 * update recursion processor. We will be recursive unless either local
1057 * only was specified, or we were passed arguments
1059 if (!(local_specified || argc > 1))
1062 history_write (m_type == CHECKOUT ? 'O' : 'E', preload_update_dir,
1063 history_name, where, repository);
1064 err += do_update ( 0, (char **) NULL, options, tag, date,
1065 force_tag_match, 0 /* !local */ ,
1066 1 /* update -d */ , aflag, checkout_prune_dirs,
1067 pipeout, which, join_rev1, join_rev2,
1068 preload_update_dir, m_type == CHECKOUT,
1078 /* we are only doing files, so register them */
1079 entries = Entries_Open (0, NULL);
1080 for (i = 1; i < argc; i++)
1084 struct file_info finfo;
1086 memset (&finfo, 0, sizeof finfo);
1087 finfo.file = argv[i];
1088 /* Shouldn't be used, so set to arbitrary value. */
1089 finfo.update_dir = NULL;
1090 finfo.fullname = argv[i];
1091 finfo.repository = repository;
1092 finfo.entries = entries;
1093 /* The rcs slot is needed to get the options from the RCS
1095 finfo.rcs = RCS_parse (finfo.file, repository);
1097 vers = Version_TS (&finfo, options, tag, date,
1098 force_tag_match, 0);
1099 if (vers->ts_user == NULL)
1101 line = xmalloc (strlen (finfo.file) + 15);
1102 (void) sprintf (line, "Initial %s", finfo.file);
1103 Register (entries, finfo.file,
1104 vers->vn_rcs ? vers->vn_rcs : "0",
1105 line, vers->options, vers->tag,
1106 vers->date, (char *) 0);
1109 freevers_ts (&vers);
1110 freercsnode (&finfo.rcs);
1113 Entries_Close (entries);
1116 /* Don't log "export", just regular "checkouts" */
1117 if (m_type == CHECKOUT && !pipeout)
1118 history_write ('O', preload_update_dir, history_name, where,
1121 /* go ahead and call update now that everything is set */
1122 err += do_update ( argc - 1, argv + 1, options, tag, date,
1123 force_tag_match, local_specified, 1 /* update -d */,
1124 aflag, checkout_prune_dirs, pipeout, which, join_rev1,
1125 join_rev2, preload_update_dir, m_type == CHECKOUT,
1128 free (preload_update_dir);
1129 preload_update_dir = oldupdate;
1136 findslash (char *start, char *p)
1140 if (*p == '/') return p;
1141 if (p == start) break;
1147 /* Return a newly malloc'd string containing a pathname for CVSNULLREPOS,
1148 and make sure that it exists. If there is an error creating the
1149 directory, give a fatal error. Otherwise, the directory is guaranteed
1150 to exist when we return. */
1152 emptydir_name (void)
1156 repository = xmalloc (strlen (current_parsed_root->directory)
1157 + sizeof (CVSROOTADM)
1158 + sizeof (CVSNULLREPOS)
1160 (void) sprintf (repository, "%s/%s/%s", current_parsed_root->directory,
1161 CVSROOTADM, CVSNULLREPOS);
1162 if (!isfile (repository))
1165 omask = umask (cvsumask);
1166 if (CVS_MKDIR (repository, 0777) < 0)
1167 error (1, errno, "cannot create %s", repository);
1168 (void) umask (omask);
1173 /* Build all the dirs along the path to DIRS with CVS subdirs with appropriate
1174 * repositories. If DIRS->repository is NULL or the directory already exists,
1175 * do not create a CVSADM directory for that subdirectory; just CVS_CHDIR into
1176 * it. Frees all storage used by DIRS.
1179 * 1. Parent directories will be listed in DIRS before their children.
1180 * 2. At most a single directory will need to be changed at one time. In
1181 * other words, if we are in /a/b/c, and our final destination is
1182 * /a/b/c/d/e/f, then we will build d, then d/e, then d/e/f.
1185 * dirs Simple list composed of dir_to_build structures, listing
1186 * information about directories to build.
1187 * sticky Passed to build_one_dir to tell it whether there are any sticky
1188 * tags or dates to be concerned with.
1191 * 1 on error, 0 otherwise.
1194 * The only nonfatal error this function may return is if the CHDIR fails.
1197 build_dirs_and_chdir (struct dir_to_build *dirs, int sticky)
1200 struct dir_to_build *nextdir;
1202 while (dirs != NULL)
1204 const char *dir = last_component (dirs->dirpath);
1207 made_dir = !mkdir_if_needed (dir);
1208 if (made_dir) Subdir_Register (NULL, NULL, dir);
1210 if (CVS_CHDIR (dir) < 0)
1212 error (0, errno, "cannot chdir to %s", dir);
1216 if (dirs->repository != NULL)
1219 build_one_dir (dirs->repository, dirs->dirpath, sticky);
1220 free (dirs->repository);
1222 nextdir = dirs->next;
1223 free (dirs->dirpath);
1229 while (dirs != NULL)
1231 if (dirs->repository != NULL)
1232 free (dirs->repository);
1233 nextdir = dirs->next;
1234 free (dirs->dirpath);