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.)
43 static char *findslash PROTO((char *start, char *p));
44 static int checkout_proc PROTO((int argc, char **argv, char *where,
45 char *mwhere, char *mfile, int shorten,
46 int local_specified, char *omodule,
49 static const char *const checkout_usage[] =
51 "Usage:\n %s %s [-ANPRcflnps] [-r rev] [-D date] [-d dir]\n",
52 " [-j rev1] [-j rev2] [-k kopt] modules...\n",
53 "\t-A\tReset any sticky tags/date/kopts.\n",
54 "\t-N\tDon't shorten module paths if -d specified.\n",
55 "\t-P\tPrune empty directories.\n",
56 "\t-R\tProcess directories recursively.\n",
57 "\t-T\tCreate Template file from local repository for remote commit.\n",
58 "\t-c\t\"cat\" the module database.\n",
59 "\t-f\tForce a head revision match if tag/date not found.\n",
60 "\t-l\tLocal directory only, not recursive\n",
61 "\t-n\tDo not run module program (if any).\n",
62 "\t-p\tCheck out files to standard output (avoids stickiness).\n",
63 "\t-s\tLike -c, but include module status.\n",
64 "\t-r rev\tCheck out revision or tag. (implies -P) (is sticky)\n",
65 "\t-D date\tCheck out revisions as of date. (implies -P) (is sticky)\n",
66 "\t-d dir\tCheck out into dir instead of module name.\n",
67 "\t-k kopt\tUse RCS kopt -k option on checkout. (is sticky)\n",
68 "\t-j rev\tMerge in changes made between current revision and rev.\n",
69 "(Specify the --help global option for a list of other help options)\n",
73 static const char *const export_usage[] =
75 "Usage: %s %s [-NRfln] [-r rev] [-D date] [-d dir] [-k kopt] module...\n",
76 "\t-N\tDon't shorten module paths if -d specified.\n",
77 "\t-f\tForce a head revision match if tag/date not found.\n",
78 "\t-l\tLocal directory only, not recursive\n",
79 "\t-R\tProcess directories recursively (default).\n",
80 "\t-n\tDo not run module program (if any).\n",
81 "\t-r rev\tExport revision or tag.\n",
82 "\t-D date\tExport revisions as of date.\n",
83 "\t-d dir\tExport into dir instead of module name.\n",
84 "\t-k kopt\tUse RCS kopt -k option on checkout.\n",
85 "(Specify the --help global option for a list of other help options)\n",
89 static int checkout_prune_dirs;
90 static int force_tag_match;
95 static int tag_validated;
97 static char *join_rev1;
98 static char *join_rev2;
99 static int join_tags_validated;
100 static int pull_template;
101 static char *preload_update_dir;
102 static char *history_name;
103 static enum mtype m_type;
106 checkout (argc, argv)
113 int cat = 0, err = 0, status = 0;
114 int run_module_prog = 1;
119 const char *const *valid_usage;
121 /* initialize static options */
128 tag = date = join_rev1 = join_rev2 = preload_update_dir = NULL;
130 tag_validated = join_tags_validated = 0;
134 * A smaller subset of options are allowed for the export command, which
135 * is essentially like checkout, except that it hard-codes certain
136 * options to be default (like -kv) and takes care to remove the CVS
137 * directory when it has done its duty
139 if (strcmp (cvs_cmd_name, "export") == 0)
142 valid_options = "+Nnk:d:flRQqr:D:";
143 valid_usage = export_usage;
148 valid_options = "+ANnk:d:flRpTQqcsr:D:j:P";
149 valid_usage = checkout_usage;
159 while ((c = getopt (argc, argv, valid_options)) != -1)
172 options = RCS_check_kflag (optarg);
182 #ifdef SERVER_SUPPORT
183 /* The CVS 1.5 client sends these options (in addition to
184 Global_option requests), so we must ignore them. */
188 "-q or -Q must be specified before \"%s\"",
198 checkout_prune_dirs = 1;
202 run_module_prog = 0; /* don't run module prog when piping */
203 noexec = 1; /* so no locks will be created */
221 checkout_prune_dirs = 1;
224 date = Make_Date (optarg);
225 checkout_prune_dirs = 1;
229 error (1, 0, "only two -j options can be specified");
247 if (cat && argc != 0)
248 error (1, 0, "-c and -s must not get any arguments");
250 if (!cat && argc == 0)
251 error (1, 0, "must specify at least one module or directory");
253 if (where && pipeout)
254 error (1, 0, "-d and -p are mutually exclusive");
256 if (m_type == EXPORT)
259 error (1, 0, "must specify a tag or date");
261 if (tag && isdigit ((unsigned char) tag[0]))
262 error (1, 0, "tag `%s' must be a symbolic tag", tag);
265 #ifdef SERVER_SUPPORT
266 if (server_active && where != NULL)
268 server_pathname_check (where);
272 if (!cat && !pipeout && !safe_location( where )) {
273 error(1, 0, "Cannot check out files into the repository itself");
276 #ifdef CLIENT_SUPPORT
277 if (current_parsed_root->isremote)
285 expand_modules = (!cat && !pipeout
286 && supported_request ("expand-modules"));
290 /* This is done here because we need to read responses
291 from the server before we send the command checkout or
294 client_expand_modules (argc, argv, local);
297 if (!run_module_prog)
303 if (!force_tag_match)
309 if (checkout_prune_dirs && m_type == CHECKOUT)
311 client_prune_dirs = checkout_prune_dirs;
315 option_with_arg ("-d", where);
318 if (options != NULL && options[0] != '\0')
320 option_with_arg ("-r", tag);
322 client_senddate (date);
323 if (join_rev1 != NULL)
324 option_with_arg ("-j", join_rev1);
325 if (join_rev2 != NULL)
326 option_with_arg ("-j", join_rev2);
331 client_send_expansions (local, where, 1);
336 for (i = 0; i < argc; ++i)
338 client_nonexpanded_setup ();
341 send_to_server (m_type == EXPORT ? "export\012" : "co\012", 0);
342 return get_responses_and_close ();
344 #endif /* CLIENT_SUPPORT */
359 /* If we've specified something like "cvs co foo/bar baz/quux"
360 don't try to shorten names. There are a few cases in which we
361 could shorten (e.g. "cvs co foo/bar foo/baz"), but we don't
362 handle those yet. Better to have an extra directory created
363 than the thing checked out under the wrong directory name. */
369 /* If we will be calling history_write, work out the name to pass
379 history_name = xmalloc (strlen (tag) + strlen (date) + 2);
380 sprintf (history_name, "%s:%s", tag, date);
385 for (i = 0; i < argc; i++)
386 err += do_module (db, argv[i], m_type, "Updating", checkout_proc,
387 where, shorten, local, run_module_prog, !pipeout,
395 if (history_name != tag && history_name != date && history_name != NULL)
400 /* FIXME: This is and emptydir_name are in checkout.c for historical
401 reasons, probably want to move them. */
404 * safe_location ( char *where )
406 * Return true if where is a safe destination for a checkout.
409 * where The requested destination directory.
412 * current_parsed_root->directory
413 * current_parsed_root->isremote
414 * Used to locate our CVSROOT.
417 * true If we are running in client mode or if where is not located
418 * within the CVSROOT.
422 * Exits with a fatal error message when various events occur, such as not
423 * being able to resolve a path or failing ot chdir to a path.
426 safe_location (where)
430 char *where_location;
436 (void) fprintf (stderr, "%s-> safe_location( where=%s )\n",
438 where ? where : "(null)");
440 #ifdef CLIENT_SUPPORT
441 /* Don't compare remote CVSROOTs to our destination directory. */
442 if ( current_parsed_root->isremote ) return 1;
443 #endif /* CLIENT_SUPPORT */
445 /* set current - even if where is set we'll need to cd back... */
448 error (1, errno, "could not get working directory");
450 hardpath = xresolvepath ( current_parsed_root->directory );
452 /* if where is set, set current to where, where - last_component( where ),
453 * or fail, depending on whether the directories exist or not.
457 if( chdir( where ) != -1 )
460 where_location = xgetwd();
461 if( where_location == NULL )
462 error( 1, errno, "could not get working directory" );
464 if( chdir( current ) == -1 )
465 error( 1, errno, "could not change directory to `%s'", current );
468 current = where_location;
470 else if( errno == ENOENT )
472 if ( last_component( where ) != where )
474 /* where - last_component( where ) */
477 /* strip the last_component */
478 where_location = xstrdup (where);
479 /* It's okay to cast out the const below since we know we just
480 * allocated where_location and can do what we like with it.
482 parent = (char *)last_component (where_location);
485 if( chdir( where_location ) != -1 )
487 free( where_location );
488 where_location = xgetwd();
489 if( where_location == NULL )
490 error( 1, errno, "could not get working directory (nominally `%s')", where_location );
492 if( chdir( current ) == -1 )
493 error( 1, errno, "could not change directory to `%s'", current );
496 current = where_location;
500 error( 1, errno, "could not change directory to requested checkout directory `%s'", where_location );
502 /* else: ERRNO == ENOENT & last_component(where) == where
503 * for example, 'cvs co -d newdir module', where newdir hasn't
504 * been created yet, so leave current set to '.' and check that
509 error( 1, errno, "could not change directory to requested checkout directory `%s'", where );
512 hardpath_len = strlen (hardpath);
513 if (strlen (current) >= hardpath_len
514 && strncmp (current, hardpath, hardpath_len) == 0)
516 if (/* Current is a subdirectory of hardpath. */
517 current[hardpath_len] == '/'
519 /* Current is hardpath itself. */
520 || current[hardpath_len] == '\0')
523 /* It isn't a problem. For example, current is
524 "/foo/cvsroot-bar" and hardpath is "/foo/cvsroot". */
536 /* What to put in CVS/Repository. */
538 /* The path to the directory. */
541 /* If set, don't build the directory, just change to it.
542 The caller will also want to set REPOSITORY to NULL. */
545 struct dir_to_build *next;
548 static int build_dirs_and_chdir PROTO ((struct dir_to_build *list,
551 static void build_one_dir PROTO ((char *, char *, int));
554 build_one_dir (repository, dirpath, sticky)
563 if (m_type == EXPORT)
564 error (1, 0, "cannot export into a working directory");
566 else if (m_type == CHECKOUT)
568 /* I suspect that this check could be omitted. */
569 if (!isdir (repository))
570 error (1, 0, "there is no repository %s", repository);
572 if (Create_Admin (".", dirpath, repository,
573 sticky ? tag : (char *) NULL,
574 sticky ? date : (char *) NULL,
576 /* FIXME? This is a guess. If it is important
577 for nonbranch to be set correctly here I
578 think we need to write it one way now and
579 then rewrite it later via WriteTag, once
580 we've had a chance to call RCS_nodeisbranch
587 fp = open_file (CVSADM_ENTSTAT, "w+");
588 if (fclose (fp) == EOF)
589 error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
590 #ifdef SERVER_SUPPORT
592 server_set_entstat (dirpath, repository);
599 * process_module calls us back here so we do the actual checkout stuff
603 checkout_proc (argc, argv, where_orig, mwhere, mfile, shorten,
604 local_specified, omodule, msg)
620 char *oldupdate = NULL;
624 * OK, so we're doing the checkout! Our args are as follows:
625 * argc,argv contain either dir or dir followed by a list of files
626 * where contains where to put it (if supplied by checkout)
627 * mwhere contains the module name or -d from module file
628 * mfile says do only that part of the module
629 * shorten = 1 says shorten as much as possible
630 * omodule is the original arg to do_module()
633 /* Set up the repository (maybe) for the bottom directory.
634 Allocate more space than we need so we don't need to keep
635 reallocating this string. */
636 repository = xmalloc (strlen (current_parsed_root->directory)
638 + (mfile == NULL ? 0 : strlen (mfile))
640 (void) sprintf (repository, "%s/%s", current_parsed_root->directory, argv[0]);
641 Sanitize_Repository_Name (repository);
644 /* save the original value of preload_update_dir */
645 if (preload_update_dir != NULL)
646 oldupdate = xstrdup (preload_update_dir);
649 /* Allocate space and set up the where variable. We allocate more
650 space than necessary here so that we don't have to keep
651 reallocaing it later on. */
653 where = xmalloc (strlen (argv[0])
654 + (mfile == NULL ? 0 : strlen (mfile))
655 + (mwhere == NULL ? 0 : strlen (mwhere))
656 + (where_orig == NULL ? 0 : strlen (where_orig))
659 /* Yes, this could be written in a less verbose way, but in this
660 form it is quite easy to read.
662 FIXME? The following code that sets should probably be moved
663 to do_module in modules.c, since there is similar code in
664 patch.c and rtag.c. */
668 if (where_orig != NULL)
670 /* If the user has specified a directory with `-d' on the
671 command line, use it preferentially, even over the `-d'
672 flag in the modules file. */
674 (void) strcpy (where, where_orig);
676 else if (mwhere != NULL)
678 /* Second preference is the value of mwhere, which is from
679 the `-d' flag in the modules file. */
681 (void) strcpy (where, mwhere);
685 /* Third preference is the directory specified in argv[0]
686 which is this module'e directory in the repository. */
688 (void) strcpy (where, argv[0]);
693 /* Use the same preferences here, bug don't shorten -- that
694 is, tack on where_orig if it exists. */
698 if (where_orig != NULL)
700 (void) strcat (where, where_orig);
701 (void) strcat (where, "/");
704 /* If the -d flag in the modules file specified an absolute
705 directory, let the user override it with the command-line
708 if ((mwhere != NULL) && (! isabsolute (mwhere)))
709 (void) strcat (where, mwhere);
711 (void) strcat (where, argv[0]);
713 strip_trailing_slashes (where); /* necessary? */
716 /* At this point, the user may have asked for a single file or
717 directory from within a module. In that case, we should modify
718 where, repository, and argv as appropriate. */
722 /* The mfile variable can have one or more path elements. If
723 it has multiple elements, we want to tack those onto both
724 repository and where. The last element may refer to either
725 a file or directory. Here's what to do:
727 it refers to a directory
728 -> simply tack it on to where and repository
730 -> munge argv to contain `basename mfile` */
736 /* Paranoia check. */
738 if (mfile[strlen (mfile) - 1] == '/')
740 error (0, 0, "checkout_proc: trailing slash on mfile (%s)!",
745 /* Does mfile have multiple path elements? */
747 cp = strrchr (mfile, '/');
751 (void) strcat (repository, "/");
752 (void) strcat (repository, mfile);
753 (void) strcat (where, "/");
754 (void) strcat (where, mfile);
759 /* Now mfile is a single path element. */
761 path = xmalloc (strlen (repository) + strlen (mfile) + 5);
762 (void) sprintf (path, "%s/%s", repository, mfile);
765 /* It's a directory, so tack it on to repository and
766 where, as we did above. */
768 (void) strcat (repository, "/");
769 (void) strcat (repository, mfile);
770 (void) strcat (where, "/");
771 (void) strcat (where, mfile);
775 /* It's a file, which means we have to screw around with
785 if (preload_update_dir != NULL)
788 xrealloc (preload_update_dir,
789 strlen (preload_update_dir) + strlen (where) + 5);
790 strcat (preload_update_dir, "/");
791 strcat (preload_update_dir, where);
794 preload_update_dir = xstrdup (where);
797 * At this point, where is the directory we want to build, repository is
798 * the repository for the lowest level of the path.
800 * We need to tell build_dirs not only the path we want it to
801 * build, but also the repositories we want it to populate the
802 * path with. To accomplish this, we walk the path backwards, one
803 * pathname component at a time, constucting a linked list of
804 * struct dir_to_build.
808 * If we are sending everything to stdout, we can skip a whole bunch of
813 struct dir_to_build *head;
816 if (strncmp (repository, current_parsed_root->directory,
817 strlen (current_parsed_root->directory)) != 0)
819 internal error: %s doesn't start with %s in checkout_proc",
820 repository, current_parsed_root->directory);
822 /* We always create at least one directory, which corresponds to
823 the entire strings for WHERE and REPOSITORY. */
824 head = (struct dir_to_build *) xmalloc (sizeof (struct dir_to_build));
825 /* Special marker to indicate that we don't want build_dirs_and_chdir
826 to create the CVSADM directory for us. */
827 head->repository = NULL;
828 head->dirpath = xstrdup (where);
830 head->just_chdir = 0;
833 /* Make a copy of the repository name to play with. */
834 reposcopy = xstrdup (repository);
836 /* FIXME: this should be written in terms of last_component
837 instead of hardcoding '/'. This presumably affects OS/2,
838 NT, &c, if the user specifies '\'. Likewise for the call
840 cp = where + strlen (where);
843 struct dir_to_build *new;
845 cp = findslash (where, cp - 1);
847 break; /* we're done */
849 new = (struct dir_to_build *)
850 xmalloc (sizeof (struct dir_to_build));
851 new->dirpath = xmalloc (strlen (where));
853 /* If the user specified an absolute path for where, the
854 last path element we create should be the top-level
859 strncpy (new->dirpath, where, cp - where);
860 new->dirpath[cp - where] = '\0';
864 /* where should always be at least one character long. */
865 assert (where[0] != '\0');
866 strcpy (new->dirpath, "/");
871 /* If where consists of multiple pathname components,
872 then we want to just cd into it, without creating
873 directories or modifying CVS directories as we go.
874 In CVS 1.9 and earlier, the code actually does a
875 CVS_CHDIR up-front; I'm not going to try to go back
876 to that exact code but this is somewhat similar
878 if (where_orig != NULL
879 && cp - where < strlen (where_orig))
881 new->repository = NULL;
888 /* Now figure out what repository directory to generate.
889 The most complete case would be something like this:
891 The modules file contains
894 The command issued was:
895 cvs co -d what/ever -N foo
897 The results in the CVS/Repository files should be:
898 . -> (don't touch CVS/Repository)
899 (I think this case might be buggy currently)
900 what -> (don't touch CVS/Repository)
901 ever -> . (same as "cd what/ever; cvs co -N foo")
902 bar -> Emptydir (generated dir -- not in repos)
903 baz -> quux (finally!) */
905 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
907 /* We can't walk up past CVSROOT. Instead, the
908 repository should be Emptydir. */
909 new->repository = emptydir_name ();
913 /* It's a directory in the repository! */
917 /* We'll always be below CVSROOT, but check for
919 rp = strrchr (reposcopy, '/');
922 "internal error: %s doesn't contain a slash",
926 new->repository = xmalloc (strlen (reposcopy) + 5);
927 (void) strcpy (new->repository, reposcopy);
929 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
931 /* Special case -- the repository name needs
932 to be "/path/to/repos/." (the trailing dot
933 is important). We might be able to get rid
934 of this after the we check out the other
935 code that handles repository names. */
936 (void) strcat (new->repository, "/.");
944 /* The top-level CVSADM directory should always be
945 current_parsed_root->directory. Create it, but only if WHERE is
946 relative. If WHERE is absolute, our current directory
947 may not have a thing to do with where the sources are
948 being checked out. If it does, build_dirs_and_chdir
949 will take care of creating adm files here. */
950 /* FIXME: checking is_absolute (where) is a horrid kludge;
951 I suspect we probably can just skip the call to
952 build_one_dir whenever the -d command option was specified
955 if (!isabsolute (where) && top_level_admin && m_type == CHECKOUT)
957 /* It may be argued that we shouldn't set any sticky
958 bits for the top-level repository. FIXME? */
959 build_one_dir (current_parsed_root->directory, ".", argc <= 1);
961 #ifdef SERVER_SUPPORT
962 /* We _always_ want to have a top-level admin
963 directory. If we're running in client/server mode,
964 send a "Clear-static-directory" command to make
965 sure it is created on the client side. (See 5.10
966 in cvsclient.dvi to convince yourself that this is
967 OK.) If this is a duplicate command being sent, it
968 will be ignored on the client side. */
971 server_clear_entstat (".", current_parsed_root->directory);
976 /* Build dirs on the path if necessary and leave us in the
977 bottom directory (where if where was specified) doesn't
978 contain a CVS subdir yet, but all the others contain
979 CVS and Entries.Static files */
981 if (build_dirs_and_chdir (head, argc <= 1) != 0)
983 error (0, 0, "ignoring module %s", omodule);
988 /* set up the repository (or make sure the old one matches) */
989 if (!isfile (CVSADM))
993 if (!noexec && argc > 1)
995 /* I'm not sure whether this check is redundant. */
996 if (!isdir (repository))
997 error (1, 0, "there is no repository %s", repository);
999 Create_Admin (".", preload_update_dir, repository,
1000 (char *) NULL, (char *) NULL, 0, 0,
1001 m_type == CHECKOUT);
1002 fp = open_file (CVSADM_ENTSTAT, "w+");
1003 if (fclose(fp) == EOF)
1004 error(1, errno, "cannot close %s", CVSADM_ENTSTAT);
1005 #ifdef SERVER_SUPPORT
1007 server_set_entstat (where, repository);
1012 /* I'm not sure whether this check is redundant. */
1013 if (!isdir (repository))
1014 error (1, 0, "there is no repository %s", repository);
1016 Create_Admin (".", preload_update_dir, repository, tag, date,
1018 /* FIXME? This is a guess. If it is important
1019 for nonbranch to be set correctly here I
1020 think we need to write it one way now and
1021 then rewrite it later via WriteTag, once
1022 we've had a chance to call RCS_nodeisbranch
1024 0, 0, m_type == CHECKOUT);
1031 if (m_type == EXPORT)
1032 error (1, 0, "cannot export into working directory");
1034 /* get the contents of the previously existing repository */
1035 repos = Name_Repository ((char *) NULL, preload_update_dir);
1036 if (fncmp (repository, repos) != 0)
1038 error (0, 0, "existing repository %s does not match %s",
1040 error (0, 0, "ignoring module %s", omodule);
1050 * If we are going to be updating to stdout, we need to cd to the
1051 * repository directory so the recursion processor can use the current
1052 * directory as the place to find repository information
1056 if ( CVS_CHDIR (repository) < 0)
1058 error (0, errno, "cannot chdir to %s", repository);
1063 if (tag != NULL && !tag_validated)
1065 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag, NULL);
1071 which = W_LOCAL | W_REPOS;
1072 if (tag != NULL && !tag_validated)
1074 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag,
1080 if (tag != NULL || date != NULL || join_rev1 != NULL)
1083 if (! join_tags_validated)
1085 if (join_rev1 != NULL)
1086 tag_check_valid_join (join_rev1, argc - 1, argv + 1, 0, aflag,
1088 if (join_rev2 != NULL)
1089 tag_check_valid_join (join_rev2, argc - 1, argv + 1, 0, aflag,
1091 join_tags_validated = 1;
1095 * if we are going to be recursive (building dirs), go ahead and call the
1096 * update recursion processor. We will be recursive unless either local
1097 * only was specified, or we were passed arguments
1099 if (!(local_specified || argc > 1))
1102 history_write (m_type == CHECKOUT ? 'O' : 'E', preload_update_dir,
1103 history_name, where, repository);
1104 err += do_update (0, (char **) NULL, options, tag, date,
1105 force_tag_match, 0 /* !local */ ,
1106 1 /* update -d */ , aflag, checkout_prune_dirs,
1107 pipeout, which, join_rev1, join_rev2,
1108 preload_update_dir, pull_template, repository);
1117 /* we are only doing files, so register them */
1118 entries = Entries_Open (0, NULL);
1119 for (i = 1; i < argc; i++)
1123 struct file_info finfo;
1125 memset (&finfo, 0, sizeof finfo);
1126 finfo.file = argv[i];
1127 /* Shouldn't be used, so set to arbitrary value. */
1128 finfo.update_dir = NULL;
1129 finfo.fullname = argv[i];
1130 finfo.repository = repository;
1131 finfo.entries = entries;
1132 /* The rcs slot is needed to get the options from the RCS
1134 finfo.rcs = RCS_parse (finfo.file, repository);
1136 vers = Version_TS (&finfo, options, tag, date,
1137 force_tag_match, 0);
1138 if (vers->ts_user == NULL)
1140 line = xmalloc (strlen (finfo.file) + 15);
1141 (void) sprintf (line, "Initial %s", finfo.file);
1142 Register (entries, finfo.file,
1143 vers->vn_rcs ? vers->vn_rcs : "0",
1144 line, vers->options, vers->tag,
1145 vers->date, (char *) 0);
1148 freevers_ts (&vers);
1149 freercsnode (&finfo.rcs);
1152 Entries_Close (entries);
1155 /* Don't log "export", just regular "checkouts" */
1156 if (m_type == CHECKOUT && !pipeout)
1157 history_write ('O', preload_update_dir, history_name, where,
1160 /* go ahead and call update now that everything is set */
1161 err += do_update (argc - 1, argv + 1, options, tag, date,
1162 force_tag_match, local_specified, 1 /* update -d */,
1163 aflag, checkout_prune_dirs, pipeout, which, join_rev1,
1164 join_rev2, preload_update_dir, pull_template, repository);
1166 free (preload_update_dir);
1167 preload_update_dir = oldupdate;
1174 findslash (start, p)
1180 if (*p == '/') return p;
1181 if (p == start) break;
1187 /* Return a newly malloc'd string containing a pathname for CVSNULLREPOS,
1188 and make sure that it exists. If there is an error creating the
1189 directory, give a fatal error. Otherwise, the directory is guaranteed
1190 to exist when we return. */
1196 repository = xmalloc (strlen (current_parsed_root->directory)
1197 + sizeof (CVSROOTADM)
1198 + sizeof (CVSNULLREPOS)
1200 (void) sprintf (repository, "%s/%s/%s", current_parsed_root->directory,
1201 CVSROOTADM, CVSNULLREPOS);
1202 if (!isfile (repository))
1205 omask = umask (cvsumask);
1206 if (CVS_MKDIR (repository, 0777) < 0)
1207 error (1, errno, "cannot create %s", repository);
1208 (void) umask (omask);
1213 /* Build all the dirs along the path to DIRS with CVS subdirs with appropriate
1214 * repositories. If DIRS->repository is NULL or the directory already exists,
1215 * do not create a CVSADM directory for that subdirectory; just CVS_CHDIR into
1216 * it. Frees all storage used by DIRS.
1219 * 1. Parent directories will be listed in DIRS before their children.
1220 * 2. At most a single directory will need to be changed at one time. In
1221 * other words, if we are in /a/b/c, and our final destination is
1222 * /a/b/c/d/e/f, then we will build d, then d/e, then d/e/f.
1225 * dirs Simple list composed of dir_to_build structures, listing
1226 * information about directories to build.
1227 * sticky Passed to build_one_dir to tell it whether there are any sticky
1228 * tags or dates to be concerned with.
1231 * 1 on error, 0 otherwise.
1234 * The only nonfatal error this function may return is if the CHDIR fails.
1237 build_dirs_and_chdir (dirs, sticky)
1238 struct dir_to_build *dirs;
1242 struct dir_to_build *nextdir;
1244 while (dirs != NULL)
1246 const char *dir = last_component (dirs->dirpath);
1248 if (!dirs->just_chdir)
1250 mkdir_if_needed (dir);
1251 Subdir_Register (NULL, NULL, dir);
1254 if (CVS_CHDIR (dir) < 0)
1256 error (0, errno, "cannot chdir to %s", dir);
1260 if (dirs->repository != NULL)
1262 build_one_dir (dirs->repository, dirs->dirpath, sticky);
1263 free (dirs->repository);
1265 nextdir = dirs->next;
1266 free (dirs->dirpath);
1272 while (dirs != NULL)
1274 if (dirs->repository != NULL)
1275 free (dirs->repository);
1276 nextdir = dirs->next;
1277 free (dirs->dirpath);