2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
7 * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
8 * Portions Copyright (C) 1989-1992, Brian Berliner
10 * You may distribute under the terms of the GNU General Public License as
11 * specified in the README file that comes with the CVS source distribution.
15 * "checkout" creates a "version" of an RCS repository. This version is owned
16 * totally by the user and is actually an independent copy, to be dealt with
17 * as seen fit. Once "checkout" has been called in a given directory, it
18 * never needs to be called again. The user can keep up-to-date by calling
19 * "update" when he feels like it; this will supply him with a merge of his
20 * own modifications and the changes made in the RCS original. See "update"
23 * "checkout" can be given a list of directories or files to be updated and in
24 * the case of a directory, will recursivley create any sub-directories that
25 * exist in the repository.
27 * When the user is satisfied with his own modifications, the present version
28 * can be committed by "commit"; this keeps the present version in tact,
31 * The call is cvs checkout [options] <module-name>...
33 * "checkout" creates a directory ./CVS, in which it keeps its administration,
34 * in two files, Repository and Entries. The first contains the name of the
35 * repository. The second contains one line for each registered file,
36 * consisting of the version number it derives from, its time stamp at
37 * derivation time and its name. Both files are normal files and can be
38 * edited by the user, if necessary (when the repository is moved, e.g.)
48 static char *findslash PROTO((char *start, char *p));
49 static int checkout_proc PROTO((int argc, char **argv, char *where,
50 char *mwhere, char *mfile, int shorten,
51 int local_specified, char *omodule,
54 static const char *const checkout_usage[] =
56 "Usage:\n %s %s [-ANPRcflnps] [-r rev] [-D date] [-d dir]\n",
57 " [-j rev1] [-j rev2] [-k kopt] modules...\n",
58 "\t-A\tReset any sticky tags/date/kopts.\n",
59 "\t-N\tDon't shorten module paths if -d specified.\n",
60 "\t-P\tPrune empty directories.\n",
61 "\t-R\tProcess directories recursively.\n",
62 "\t-T\tCreate Template file from local repository for remote commit.\n",
63 "\t-c\t\"cat\" the module database.\n",
64 "\t-f\tForce a head revision match if tag/date not found.\n",
65 "\t-l\tLocal directory only, not recursive\n",
66 "\t-n\tDo not run module program (if any).\n",
67 "\t-p\tCheck out files to standard output (avoids stickiness).\n",
68 "\t-s\tLike -c, but include module status.\n",
69 "\t-r rev\tCheck out revision or tag. (implies -P) (is sticky)\n",
70 "\t-D date\tCheck out revisions as of date. (implies -P) (is sticky)\n",
71 "\t-d dir\tCheck out into dir instead of module name.\n",
72 "\t-k kopt\tUse RCS kopt -k option on checkout. (is sticky)\n",
73 "\t-j rev\tMerge in changes made between current revision and rev.\n",
74 "(Specify the --help global option for a list of other help options)\n",
78 static const char *const export_usage[] =
80 "Usage: %s %s [-NRfln] [-r tag] [-D date] [-d dir] [-k kopt] module...\n",
81 "\t-N\tDon't shorten module paths if -d specified.\n",
82 "\t-f\tForce a head revision match if tag/date not found.\n",
83 "\t-l\tLocal directory only, not recursive\n",
84 "\t-R\tProcess directories recursively (default).\n",
85 "\t-n\tDo not run module program (if any).\n",
86 "\t-r tag\tExport tagged revisions.\n",
87 "\t-D date\tExport revisions as of date.\n",
88 "\t-d dir\tExport into dir instead of module name.\n",
89 "\t-k kopt\tUse RCS kopt -k option on checkout.\n",
90 "(Specify the --help global option for a list of other help options)\n",
94 static int checkout_prune_dirs;
95 static int force_tag_match;
100 static int tag_validated;
102 static char *join_rev1;
103 static char *join_rev2;
104 static int join_tags_validated;
105 static int pull_template;
106 static char *preload_update_dir;
107 static char *history_name;
108 static enum mtype m_type;
111 checkout (argc, argv)
118 int cat = 0, err = 0, status = 0;
119 int run_module_prog = 1;
124 const char *const *valid_usage;
126 /* initialize static options */
133 tag = date = join_rev1 = join_rev2 = preload_update_dir = NULL;
135 tag_validated = join_tags_validated = 0;
139 * A smaller subset of options are allowed for the export command, which
140 * is essentially like checkout, except that it hard-codes certain
141 * options to be default (like -kv) and takes care to remove the CVS
142 * directory when it has done its duty
144 if (strcmp (cvs_cmd_name, "export") == 0)
147 valid_options = "+Nnk:d:flRQqr:D:";
148 valid_usage = export_usage;
153 valid_options = "+ANnk:d:flRpTQqcsr:D:j:P";
154 valid_usage = checkout_usage;
164 while ((c = getopt (argc, argv, valid_options)) != -1)
177 options = RCS_check_kflag (optarg);
187 /* The CVS 1.5 client sends these options (in addition to
188 Global_option requests), so we must ignore them. */
191 "-q or -Q must be specified before \"%s\"",
201 checkout_prune_dirs = 1;
205 run_module_prog = 0; /* don't run module prog when piping */
206 noexec = 1; /* so no locks will be created */
224 checkout_prune_dirs = 1;
227 date = Make_Date (optarg);
228 checkout_prune_dirs = 1;
232 error (1, 0, "only two -j options can be specified");
250 if (cat && argc != 0)
251 error (1, 0, "-c and -s must not get any arguments");
253 if (!cat && argc == 0)
254 error (1, 0, "must specify at least one module or directory");
256 if (where && pipeout)
257 error (1, 0, "-d and -p are mutually exclusive");
259 if (m_type == EXPORT)
262 error (1, 0, "must specify a tag or date");
264 if (tag && isdigit ((unsigned char) tag[0]))
265 error (1, 0, "tag `%s' must be a symbolic tag", tag);
268 #ifdef SERVER_SUPPORT
269 if (server_active && where != NULL)
271 server_pathname_check (where);
275 if (!cat && !pipeout && !safe_location( where )) {
276 error(1, 0, "Cannot check out files into the repository itself");
279 #ifdef CLIENT_SUPPORT
280 if (current_parsed_root->isremote)
288 expand_modules = (!cat && !pipeout
289 && supported_request ("expand-modules"));
293 /* This is done here because we need to read responses
294 from the server before we send the command checkout or
297 client_expand_modules (argc, argv, local);
300 if (!run_module_prog)
306 if (!force_tag_match)
312 if (checkout_prune_dirs && m_type == CHECKOUT)
314 client_prune_dirs = checkout_prune_dirs;
318 option_with_arg ("-d", where);
321 if (options != NULL && options[0] != '\0')
323 option_with_arg ("-r", tag);
325 client_senddate (date);
326 if (join_rev1 != NULL)
327 option_with_arg ("-j", join_rev1);
328 if (join_rev2 != NULL)
329 option_with_arg ("-j", join_rev2);
334 client_send_expansions (local, where, 1);
339 for (i = 0; i < argc; ++i)
341 client_nonexpanded_setup ();
344 send_to_server (m_type == EXPORT ? "export\012" : "co\012", 0);
345 return get_responses_and_close ();
347 #endif /* CLIENT_SUPPORT */
362 /* If we've specified something like "cvs co foo/bar baz/quux"
363 don't try to shorten names. There are a few cases in which we
364 could shorten (e.g. "cvs co foo/bar foo/baz"), but we don't
365 handle those yet. Better to have an extra directory created
366 than the thing checked out under the wrong directory name. */
372 /* If we will be calling history_write, work out the name to pass
382 history_name = xmalloc (strlen (tag) + strlen (date) + 2);
383 sprintf (history_name, "%s:%s", tag, date);
388 for (i = 0; i < argc; i++)
389 err += do_module (db, argv[i], m_type, "Updating", checkout_proc,
390 where, shorten, local, run_module_prog, !pipeout,
398 if (history_name != tag && history_name != date && history_name != NULL)
403 /* FIXME: This is and emptydir_name are in checkout.c for historical
404 reasons, probably want to move them. */
407 * safe_location ( char *where )
409 * Return true if where is a safe destination for a checkout.
412 * where The requested destination directory.
415 * current_parsed_root->directory
416 * current_parsed_root->isremote
417 * Used to locate our CVSROOT.
420 * true If we are running in client mode or if where is not located
421 * within the CVSROOT.
425 * Exits with a fatal error message when various events occur, such as not
426 * being able to resolve a path or failing ot chdir to a path.
429 safe_location (where)
433 char *where_location;
439 (void) fprintf (stderr, "%s-> safe_location( where=%s )\n",
441 where ? where : "(null)");
443 /* Don't compare remote CVSROOTs to our destination directory. */
444 if (current_parsed_root->isremote) return 1;
446 /* set current - even if where is set we'll need to cd back... */
449 error (1, errno, "could not get working directory");
451 hardpath = xresolvepath ( current_parsed_root->directory );
453 /* if where is set, set current to where, where - last_component( where ),
454 * or fail, depending on whether the directories exist or not.
458 if( chdir( where ) != -1 )
461 where_location = xgetwd();
462 if( where_location == NULL )
463 error( 1, errno, "could not get working directory" );
465 if( chdir( current ) == -1 )
466 error( 1, errno, "could not change directory to `%s'", current );
469 current = where_location;
471 else if( errno == ENOENT )
473 if ( last_component( where ) != where )
475 /* where - last_component( where ) */
478 /* strip the last_component */
479 where_location = xstrdup (where);
480 /* It's okay to cast out the const below since we know we just
481 * allocated where_location and can do what we like with it.
483 parent = (char *)last_component (where_location);
486 if( chdir( where_location ) != -1 )
488 free( where_location );
489 where_location = xgetwd();
490 if( where_location == NULL )
491 error( 1, errno, "could not get working directory (nominally `%s')", where_location );
493 if( chdir( current ) == -1 )
494 error( 1, errno, "could not change directory to `%s'", current );
497 current = where_location;
501 error( 1, errno, "could not change directory to requested checkout directory `%s'", where_location );
503 /* else: ERRNO == ENOENT & last_component(where) == where
504 * for example, 'cvs co -d newdir module', where newdir hasn't
505 * been created yet, so leave current set to '.' and check that
510 error( 1, errno, "could not change directory to requested checkout directory `%s'", where );
513 hardpath_len = strlen (hardpath);
514 if (strlen (current) >= hardpath_len
515 && strncmp (current, hardpath, hardpath_len) == 0)
517 if (/* Current is a subdirectory of hardpath. */
518 current[hardpath_len] == '/'
520 /* Current is hardpath itself. */
521 || current[hardpath_len] == '\0')
524 /* It isn't a problem. For example, current is
525 "/foo/cvsroot-bar" and hardpath is "/foo/cvsroot". */
537 /* What to put in CVS/Repository. */
539 /* The path to the directory. */
542 /* If set, don't build the directory, just change to it.
543 The caller will also want to set REPOSITORY to NULL. */
546 struct dir_to_build *next;
549 static int build_dirs_and_chdir PROTO ((struct dir_to_build *list,
552 static void build_one_dir PROTO ((char *, char *, int));
555 build_one_dir (repository, dirpath, sticky)
564 if (m_type == EXPORT)
565 error (1, 0, "cannot export into a working directory");
567 else if (m_type == CHECKOUT)
569 /* I suspect that this check could be omitted. */
570 if (!isdir (repository))
571 error (1, 0, "there is no repository %s", repository);
573 if (Create_Admin (".", dirpath, repository,
574 sticky ? tag : (char *) NULL,
575 sticky ? date : (char *) NULL,
577 /* FIXME? This is a guess. If it is important
578 for nonbranch to be set correctly here I
579 think we need to write it one way now and
580 then rewrite it later via WriteTag, once
581 we've had a chance to call RCS_nodeisbranch
588 fp = open_file (CVSADM_ENTSTAT, "w+");
589 if (fclose (fp) == EOF)
590 error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
591 #ifdef SERVER_SUPPORT
593 server_set_entstat (dirpath, repository);
600 * process_module calls us back here so we do the actual checkout stuff
604 checkout_proc (argc, argv, where_orig, mwhere, mfile, shorten,
605 local_specified, omodule, msg)
621 char *oldupdate = NULL;
625 * OK, so we're doing the checkout! Our args are as follows:
626 * argc,argv contain either dir or dir followed by a list of files
627 * where contains where to put it (if supplied by checkout)
628 * mwhere contains the module name or -d from module file
629 * mfile says do only that part of the module
630 * shorten = 1 says shorten as much as possible
631 * omodule is the original arg to do_module()
634 /* Set up the repository (maybe) for the bottom directory.
635 Allocate more space than we need so we don't need to keep
636 reallocating this string. */
637 repository = xmalloc (strlen (current_parsed_root->directory)
639 + (mfile == NULL ? 0 : strlen (mfile))
641 (void) sprintf (repository, "%s/%s", current_parsed_root->directory, argv[0]);
642 Sanitize_Repository_Name (repository);
645 /* save the original value of preload_update_dir */
646 if (preload_update_dir != NULL)
647 oldupdate = xstrdup (preload_update_dir);
650 /* Allocate space and set up the where variable. We allocate more
651 space than necessary here so that we don't have to keep
652 reallocaing it later on. */
654 where = xmalloc (strlen (argv[0])
655 + (mfile == NULL ? 0 : strlen (mfile))
656 + (mwhere == NULL ? 0 : strlen (mwhere))
657 + (where_orig == NULL ? 0 : strlen (where_orig))
660 /* Yes, this could be written in a less verbose way, but in this
661 form it is quite easy to read.
663 FIXME? The following code that sets should probably be moved
664 to do_module in modules.c, since there is similar code in
665 patch.c and rtag.c. */
669 if (where_orig != NULL)
671 /* If the user has specified a directory with `-d' on the
672 command line, use it preferentially, even over the `-d'
673 flag in the modules file. */
675 (void) strcpy (where, where_orig);
677 else if (mwhere != NULL)
679 /* Second preference is the value of mwhere, which is from
680 the `-d' flag in the modules file. */
682 (void) strcpy (where, mwhere);
686 /* Third preference is the directory specified in argv[0]
687 which is this module'e directory in the repository. */
689 (void) strcpy (where, argv[0]);
694 /* Use the same preferences here, bug don't shorten -- that
695 is, tack on where_orig if it exists. */
699 if (where_orig != NULL)
701 (void) strcat (where, where_orig);
702 (void) strcat (where, "/");
705 /* If the -d flag in the modules file specified an absolute
706 directory, let the user override it with the command-line
709 if ((mwhere != NULL) && (! isabsolute (mwhere)))
710 (void) strcat (where, mwhere);
712 (void) strcat (where, argv[0]);
714 strip_trailing_slashes (where); /* necessary? */
717 /* At this point, the user may have asked for a single file or
718 directory from within a module. In that case, we should modify
719 where, repository, and argv as appropriate. */
723 /* The mfile variable can have one or more path elements. If
724 it has multiple elements, we want to tack those onto both
725 repository and where. The last element may refer to either
726 a file or directory. Here's what to do:
728 it refers to a directory
729 -> simply tack it on to where and repository
731 -> munge argv to contain `basename mfile` */
737 /* Paranoia check. */
739 if (mfile[strlen (mfile) - 1] == '/')
741 error (0, 0, "checkout_proc: trailing slash on mfile (%s)!",
746 /* Does mfile have multiple path elements? */
748 cp = strrchr (mfile, '/');
752 (void) strcat (repository, "/");
753 (void) strcat (repository, mfile);
754 (void) strcat (where, "/");
755 (void) strcat (where, mfile);
760 /* Now mfile is a single path element. */
762 path = xmalloc (strlen (repository) + strlen (mfile) + 5);
763 (void) sprintf (path, "%s/%s", repository, mfile);
766 /* It's a directory, so tack it on to repository and
767 where, as we did above. */
769 (void) strcat (repository, "/");
770 (void) strcat (repository, mfile);
771 (void) strcat (where, "/");
772 (void) strcat (where, mfile);
776 /* It's a file, which means we have to screw around with
786 if (preload_update_dir != NULL)
789 xrealloc (preload_update_dir,
790 strlen (preload_update_dir) + strlen (where) + 5);
791 strcat (preload_update_dir, "/");
792 strcat (preload_update_dir, where);
795 preload_update_dir = xstrdup (where);
798 * At this point, where is the directory we want to build, repository is
799 * the repository for the lowest level of the path.
801 * We need to tell build_dirs not only the path we want it to
802 * build, but also the repositories we want it to populate the
803 * path with. To accomplish this, we walk the path backwards, one
804 * pathname component at a time, constucting a linked list of
805 * struct dir_to_build.
809 * If we are sending everything to stdout, we can skip a whole bunch of
814 struct dir_to_build *head;
817 if (strncmp (repository, current_parsed_root->directory,
818 strlen (current_parsed_root->directory)) != 0)
820 internal error: %s doesn't start with %s in checkout_proc",
821 repository, current_parsed_root->directory);
823 /* We always create at least one directory, which corresponds to
824 the entire strings for WHERE and REPOSITORY. */
825 head = (struct dir_to_build *) xmalloc (sizeof (struct dir_to_build));
826 /* Special marker to indicate that we don't want build_dirs_and_chdir
827 to create the CVSADM directory for us. */
828 head->repository = NULL;
829 head->dirpath = xstrdup (where);
831 head->just_chdir = 0;
834 /* Make a copy of the repository name to play with. */
835 reposcopy = xstrdup (repository);
837 /* FIXME: this should be written in terms of last_component
838 instead of hardcoding '/'. This presumably affects OS/2,
839 NT, &c, if the user specifies '\'. Likewise for the call
841 cp = where + strlen (where);
844 struct dir_to_build *new;
846 cp = findslash (where, cp - 1);
848 break; /* we're done */
850 new = (struct dir_to_build *)
851 xmalloc (sizeof (struct dir_to_build));
852 new->dirpath = xmalloc (strlen (where));
854 /* If the user specified an absolute path for where, the
855 last path element we create should be the top-level
860 strncpy (new->dirpath, where, cp - where);
861 new->dirpath[cp - where] = '\0';
865 /* where should always be at least one character long. */
866 assert (where[0] != '\0');
867 strcpy (new->dirpath, "/");
872 /* If where consists of multiple pathname components,
873 then we want to just cd into it, without creating
874 directories or modifying CVS directories as we go.
875 In CVS 1.9 and earlier, the code actually does a
876 CVS_CHDIR up-front; I'm not going to try to go back
877 to that exact code but this is somewhat similar
879 if (where_orig != NULL
880 && cp - where < strlen (where_orig))
882 new->repository = NULL;
889 /* Now figure out what repository directory to generate.
890 The most complete case would be something like this:
892 The modules file contains
895 The command issued was:
896 cvs co -d what/ever -N foo
898 The results in the CVS/Repository files should be:
899 . -> (don't touch CVS/Repository)
900 (I think this case might be buggy currently)
901 what -> (don't touch CVS/Repository)
902 ever -> . (same as "cd what/ever; cvs co -N foo")
903 bar -> Emptydir (generated dir -- not in repos)
904 baz -> quux (finally!) */
906 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
908 /* We can't walk up past CVSROOT. Instead, the
909 repository should be Emptydir. */
910 new->repository = emptydir_name ();
914 /* It's a directory in the repository! */
918 /* We'll always be below CVSROOT, but check for
920 rp = strrchr (reposcopy, '/');
923 "internal error: %s doesn't contain a slash",
927 new->repository = xmalloc (strlen (reposcopy) + 5);
928 (void) strcpy (new->repository, reposcopy);
930 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
932 /* Special case -- the repository name needs
933 to be "/path/to/repos/." (the trailing dot
934 is important). We might be able to get rid
935 of this after the we check out the other
936 code that handles repository names. */
937 (void) strcat (new->repository, "/.");
945 /* The top-level CVSADM directory should always be
946 current_parsed_root->directory. Create it, but only if WHERE is
947 relative. If WHERE is absolute, our current directory
948 may not have a thing to do with where the sources are
949 being checked out. If it does, build_dirs_and_chdir
950 will take care of creating adm files here. */
951 /* FIXME: checking is_absolute (where) is a horrid kludge;
952 I suspect we probably can just skip the call to
953 build_one_dir whenever the -d command option was specified
956 if (!isabsolute (where) && top_level_admin && m_type == CHECKOUT)
958 /* It may be argued that we shouldn't set any sticky
959 bits for the top-level repository. FIXME? */
960 build_one_dir (current_parsed_root->directory, ".", argc <= 1);
962 #ifdef SERVER_SUPPORT
963 /* We _always_ want to have a top-level admin
964 directory. If we're running in client/server mode,
965 send a "Clear-static-directory" command to make
966 sure it is created on the client side. (See 5.10
967 in cvsclient.dvi to convince yourself that this is
968 OK.) If this is a duplicate command being sent, it
969 will be ignored on the client side. */
972 server_clear_entstat (".", current_parsed_root->directory);
977 /* Build dirs on the path if necessary and leave us in the
978 bottom directory (where if where was specified) doesn't
979 contain a CVS subdir yet, but all the others contain
980 CVS and Entries.Static files */
982 if (build_dirs_and_chdir (head, argc <= 1) != 0)
984 error (0, 0, "ignoring module %s", omodule);
989 /* set up the repository (or make sure the old one matches) */
990 if (!isfile (CVSADM))
994 if (!noexec && argc > 1)
996 /* I'm not sure whether this check is redundant. */
997 if (!isdir (repository))
998 error (1, 0, "there is no repository %s", repository);
1000 Create_Admin (".", preload_update_dir, repository,
1001 (char *) NULL, (char *) NULL, 0, 0,
1002 m_type == CHECKOUT);
1003 fp = open_file (CVSADM_ENTSTAT, "w+");
1004 if (fclose(fp) == EOF)
1005 error(1, errno, "cannot close %s", CVSADM_ENTSTAT);
1006 #ifdef SERVER_SUPPORT
1008 server_set_entstat (where, repository);
1013 /* I'm not sure whether this check is redundant. */
1014 if (!isdir (repository))
1015 error (1, 0, "there is no repository %s", repository);
1017 Create_Admin (".", preload_update_dir, repository, tag, date,
1019 /* FIXME? This is a guess. If it is important
1020 for nonbranch to be set correctly here I
1021 think we need to write it one way now and
1022 then rewrite it later via WriteTag, once
1023 we've had a chance to call RCS_nodeisbranch
1025 0, 0, m_type == CHECKOUT);
1032 if (m_type == EXPORT)
1033 error (1, 0, "cannot export into working directory");
1035 /* get the contents of the previously existing repository */
1036 repos = Name_Repository ((char *) NULL, preload_update_dir);
1037 if (fncmp (repository, repos) != 0)
1039 error (0, 0, "existing repository %s does not match %s",
1041 error (0, 0, "ignoring module %s", omodule);
1051 * If we are going to be updating to stdout, we need to cd to the
1052 * repository directory so the recursion processor can use the current
1053 * directory as the place to find repository information
1057 if ( CVS_CHDIR (repository) < 0)
1059 error (0, errno, "cannot chdir to %s", repository);
1064 if (tag != NULL && !tag_validated)
1066 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag,
1073 which = W_LOCAL | W_REPOS;
1074 if (tag != NULL && !tag_validated)
1076 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag,
1082 if (tag != NULL || date != NULL || join_rev1 != NULL)
1085 if (! join_tags_validated)
1087 if (join_rev1 != NULL)
1088 tag_check_valid_join (join_rev1, argc - 1, argv + 1, 0, aflag,
1090 if (join_rev2 != NULL)
1091 tag_check_valid_join (join_rev2, argc - 1, argv + 1, 0, aflag,
1093 join_tags_validated = 1;
1097 * if we are going to be recursive (building dirs), go ahead and call the
1098 * update recursion processor. We will be recursive unless either local
1099 * only was specified, or we were passed arguments
1101 if (!(local_specified || argc > 1))
1104 history_write (m_type == CHECKOUT ? 'O' : 'E', preload_update_dir,
1105 history_name, where, repository);
1106 err += do_update (0, (char **) NULL, options, tag, date,
1107 force_tag_match, 0 /* !local */ ,
1108 1 /* update -d */ , aflag, checkout_prune_dirs,
1109 pipeout, which, join_rev1, join_rev2,
1110 preload_update_dir, pull_template, repository);
1119 /* we are only doing files, so register them */
1120 entries = Entries_Open (0, NULL);
1121 for (i = 1; i < argc; i++)
1125 struct file_info finfo;
1127 memset (&finfo, 0, sizeof finfo);
1128 finfo.file = argv[i];
1129 /* Shouldn't be used, so set to arbitrary value. */
1130 finfo.update_dir = NULL;
1131 finfo.fullname = argv[i];
1132 finfo.repository = repository;
1133 finfo.entries = entries;
1134 /* The rcs slot is needed to get the options from the RCS
1136 finfo.rcs = RCS_parse (finfo.file, repository);
1138 vers = Version_TS (&finfo, options, tag, date,
1139 force_tag_match, 0);
1140 if (vers->ts_user == NULL)
1142 line = xmalloc (strlen (finfo.file) + 15);
1143 (void) sprintf (line, "Initial %s", finfo.file);
1144 Register (entries, finfo.file,
1145 vers->vn_rcs ? vers->vn_rcs : "0",
1146 line, vers->options, vers->tag,
1147 vers->date, (char *) 0);
1150 freevers_ts (&vers);
1151 freercsnode (&finfo.rcs);
1154 Entries_Close (entries);
1157 /* Don't log "export", just regular "checkouts" */
1158 if (m_type == CHECKOUT && !pipeout)
1159 history_write ('O', preload_update_dir, history_name, where,
1162 /* go ahead and call update now that everything is set */
1163 err += do_update (argc - 1, argv + 1, options, tag, date,
1164 force_tag_match, local_specified, 1 /* update -d */,
1165 aflag, checkout_prune_dirs, pipeout, which, join_rev1,
1166 join_rev2, preload_update_dir, pull_template, repository);
1168 free (preload_update_dir);
1169 preload_update_dir = oldupdate;
1176 findslash (start, p)
1182 if (*p == '/') return p;
1183 if (p == start) break;
1189 /* Return a newly malloc'd string containing a pathname for CVSNULLREPOS,
1190 and make sure that it exists. If there is an error creating the
1191 directory, give a fatal error. Otherwise, the directory is guaranteed
1192 to exist when we return. */
1198 repository = xmalloc (strlen (current_parsed_root->directory)
1199 + sizeof (CVSROOTADM)
1200 + sizeof (CVSNULLREPOS)
1202 (void) sprintf (repository, "%s/%s/%s", current_parsed_root->directory,
1203 CVSROOTADM, CVSNULLREPOS);
1204 if (!isfile (repository))
1207 omask = umask (cvsumask);
1208 if (CVS_MKDIR (repository, 0777) < 0)
1209 error (1, errno, "cannot create %s", repository);
1210 (void) umask (omask);
1215 /* Build all the dirs along the path to DIRS with CVS subdirs with appropriate
1216 * repositories. If DIRS->repository is NULL or the directory already exists,
1217 * do not create a CVSADM directory for that subdirectory; just CVS_CHDIR into
1218 * it. Frees all storage used by DIRS.
1221 * 1. Parent directories will be listed in DIRS before their children.
1222 * 2. At most a single directory will need to be changed at one time. In
1223 * other words, if we are in /a/b/c, and our final destination is
1224 * /a/b/c/d/e/f, then we will build d, then d/e, then d/e/f.
1227 * dirs Simple list composed of dir_to_build structures, listing
1228 * information about directories to build.
1229 * sticky Passed to build_one_dir to tell it whether there are any sticky
1230 * tags or dates to be concerned with.
1233 * 1 on error, 0 otherwise.
1236 * The only nonfatal error this function may return is if the CHDIR fails.
1239 build_dirs_and_chdir (dirs, sticky)
1240 struct dir_to_build *dirs;
1244 struct dir_to_build *nextdir;
1246 while (dirs != NULL)
1248 const char *dir = last_component (dirs->dirpath);
1250 if (!dirs->just_chdir)
1252 mkdir_if_needed (dir);
1253 Subdir_Register (NULL, NULL, dir);
1256 if (CVS_CHDIR (dir) < 0)
1258 error (0, errno, "cannot chdir to %s", dir);
1262 if (dirs->repository != NULL)
1264 build_one_dir (dirs->repository, dirs->dirpath, sticky);
1265 free (dirs->repository);
1267 nextdir = dirs->next;
1268 free (dirs->dirpath);
1274 while (dirs != NULL)
1276 if (dirs->repository != NULL)
1277 free (dirs->repository);
1278 nextdir = dirs->next;
1279 free (dirs->dirpath);