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.)
39 static char *findslash PROTO((char *start, char *p));
40 static int checkout_proc PROTO((int argc, char **argv, char *where,
41 char *mwhere, char *mfile, int shorten,
42 int local_specified, char *omodule,
45 static const char *const checkout_usage[] =
47 "Usage:\n %s %s [-ANPRcflnps] [-r rev] [-D date] [-d dir]\n",
48 " [-j rev1] [-j rev2] [-k kopt] modules...\n",
49 "\t-A\tReset any sticky tags/date/kopts.\n",
50 "\t-N\tDon't shorten module paths if -d specified.\n",
51 "\t-P\tPrune empty directories.\n",
52 "\t-R\tProcess directories recursively.\n",
53 "\t-c\t\"cat\" the module database.\n",
54 "\t-f\tForce a head revision match if tag/date not found.\n",
55 "\t-l\tLocal directory only, not recursive\n",
56 "\t-n\tDo not run module program (if any).\n",
57 "\t-p\tCheck out files to standard output (avoids stickiness).\n",
58 "\t-s\tLike -c, but include module status.\n",
59 "\t-r rev\tCheck out revision or tag. (implies -P) (is sticky)\n",
60 "\t-D date\tCheck out revisions as of date. (implies -P) (is sticky)\n",
61 "\t-d dir\tCheck out into dir instead of module name.\n",
62 "\t-k kopt\tUse RCS kopt -k option on checkout. (is sticky)\n",
63 "\t-j rev\tMerge in changes made between current revision and rev.\n",
64 "(Specify the --help global option for a list of other help options)\n",
68 static const char *const export_usage[] =
70 "Usage: %s %s [-NRfln] [-r rev] [-D date] [-d dir] [-k kopt] module...\n",
71 "\t-N\tDon't shorten module paths if -d specified.\n",
72 "\t-f\tForce a head revision match if tag/date not found.\n",
73 "\t-l\tLocal directory only, not recursive\n",
74 "\t-R\tProcess directories recursively (default).\n",
75 "\t-n\tDo not run module program (if any).\n",
76 "\t-r rev\tExport revision or tag.\n",
77 "\t-D date\tExport revisions as of date.\n",
78 "\t-d dir\tExport into dir instead of module name.\n",
79 "\t-k kopt\tUse RCS kopt -k option on checkout.\n",
80 "(Specify the --help global option for a list of other help options)\n",
84 static int checkout_prune_dirs;
85 static int force_tag_match;
90 static int tag_validated;
92 static char *join_rev1;
93 static char *join_rev2;
94 static int join_tags_validated;
95 static char *preload_update_dir;
96 static char *history_name;
97 static enum mtype m_type;
100 checkout (argc, argv)
107 int cat = 0, err = 0, status = 0;
108 int run_module_prog = 1;
113 const char *const *valid_usage;
115 /* initialize static options */
122 tag = date = join_rev1 = join_rev2 = preload_update_dir = NULL;
124 tag_validated = join_tags_validated = 0;
128 * A smaller subset of options are allowed for the export command, which
129 * is essentially like checkout, except that it hard-codes certain
130 * options to be default (like -kv) and takes care to remove the CVS
131 * directory when it has done its duty
133 if (strcmp (cvs_cmd_name, "export") == 0)
136 valid_options = "+Nnk:d:flRQqr:D:";
137 valid_usage = export_usage;
142 valid_options = "+ANnk:d:flRpQqcsr:D:j:P";
143 valid_usage = checkout_usage;
153 while ((c = getopt (argc, argv, valid_options)) != -1)
166 options = RCS_check_kflag (optarg);
173 #ifdef SERVER_SUPPORT
174 /* The CVS 1.5 client sends these options (in addition to
175 Global_option requests), so we must ignore them. */
179 "-q or -Q must be specified before \"%s\"",
189 checkout_prune_dirs = 1;
193 run_module_prog = 0; /* don't run module prog when piping */
194 noexec = 1; /* so no locks will be created */
212 checkout_prune_dirs = 1;
215 date = Make_Date (optarg);
216 checkout_prune_dirs = 1;
220 error (1, 0, "only two -j options can be specified");
238 if (cat && argc != 0)
239 error (1, 0, "-c and -s must not get any arguments");
241 if (!cat && argc == 0)
242 error (1, 0, "must specify at least one module or directory");
244 if (where && pipeout)
245 error (1, 0, "-d and -p are mutually exclusive");
247 if (m_type == EXPORT)
250 error (1, 0, "must specify a tag or date");
252 if (tag && isdigit ((unsigned char) tag[0]))
253 error (1, 0, "tag `%s' must be a symbolic tag", tag);
256 #ifdef SERVER_SUPPORT
257 if (server_active && where != NULL)
259 server_pathname_check (where);
263 if (!cat && !pipeout && !safe_location( where )) {
264 error(1, 0, "Cannot check out files into the repository itself");
267 #ifdef CLIENT_SUPPORT
268 if (current_parsed_root->isremote)
276 expand_modules = (!cat && !pipeout
277 && supported_request ("expand-modules"));
281 /* This is done here because we need to read responses
282 from the server before we send the command checkout or
285 client_expand_modules (argc, argv, local);
288 if (!run_module_prog)
294 if (!force_tag_match)
300 if (checkout_prune_dirs && m_type == CHECKOUT)
302 client_prune_dirs = checkout_prune_dirs;
306 option_with_arg ("-d", where);
309 if (options != NULL && options[0] != '\0')
311 option_with_arg ("-r", tag);
313 client_senddate (date);
314 if (join_rev1 != NULL)
315 option_with_arg ("-j", join_rev1);
316 if (join_rev2 != NULL)
317 option_with_arg ("-j", join_rev2);
322 client_send_expansions (local, where, 1);
327 for (i = 0; i < argc; ++i)
329 client_nonexpanded_setup ();
332 send_to_server (m_type == EXPORT ? "export\012" : "co\012", 0);
333 return get_responses_and_close ();
335 #endif /* CLIENT_SUPPORT */
350 /* If we've specified something like "cvs co foo/bar baz/quux"
351 don't try to shorten names. There are a few cases in which we
352 could shorten (e.g. "cvs co foo/bar foo/baz"), but we don't
353 handle those yet. Better to have an extra directory created
354 than the thing checked out under the wrong directory name. */
360 /* If we will be calling history_write, work out the name to pass
370 history_name = xmalloc (strlen (tag) + strlen (date) + 2);
371 sprintf (history_name, "%s:%s", tag, date);
376 for (i = 0; i < argc; i++)
377 err += do_module (db, argv[i], m_type, "Updating", checkout_proc,
378 where, shorten, local, run_module_prog, !pipeout,
386 if (history_name != tag && history_name != date && history_name != NULL)
391 /* FIXME: This is and emptydir_name are in checkout.c for historical
392 reasons, probably want to move them. */
395 * safe_location ( char *where )
397 * Return true if where is a safe destination for a checkout.
400 * where The requested destination directory.
403 * current_parsed_root->directory
404 * current_parsed_root->isremote
405 * Used to locate our CVSROOT.
408 * true If we are running in client mode or if where is not located
409 * within the CVSROOT.
413 * Exits with a fatal error message when various events occur, such as not
414 * being able to resolve a path or failing ot chdir to a path.
417 safe_location (where)
421 char *where_location;
427 (void) fprintf (stderr, "%s-> safe_location( where=%s )\n",
429 where ? where : "(null)");
431 #ifdef CLIENT_SUPPORT
432 /* Don't compare remote CVSROOTs to our destination directory. */
433 if ( current_parsed_root->isremote ) return 1;
434 #endif /* CLIENT_SUPPORT */
436 /* set current - even if where is set we'll need to cd back... */
439 error (1, errno, "could not get working directory");
441 hardpath = xresolvepath ( current_parsed_root->directory );
443 /* if where is set, set current to where, where - last_component( where ),
444 * or fail, depending on whether the directories exist or not.
448 if( chdir( where ) != -1 )
451 where_location = xgetwd();
452 if( where_location == NULL )
453 error( 1, errno, "could not get working directory" );
455 if( chdir( current ) == -1 )
456 error( 1, errno, "could not change directory to `%s'", current );
459 current = where_location;
461 else if( errno == ENOENT )
463 if ( last_component( where ) != where )
465 /* where - last_component( where ) */
468 /* strip the last_component */
469 where_location = xstrdup (where);
470 /* It's okay to cast out the const below since we know we just
471 * allocated where_location and can do what we like with it.
473 parent = (char *)last_component (where_location);
476 if( chdir( where_location ) != -1 )
478 free( where_location );
479 where_location = xgetwd();
480 if( where_location == NULL )
481 error( 1, errno, "could not get working directory (nominally `%s')", where_location );
483 if( chdir( current ) == -1 )
484 error( 1, errno, "could not change directory to `%s'", current );
487 current = where_location;
491 error( 1, errno, "could not change directory to requested checkout directory `%s'", where_location );
493 /* else: ERRNO == ENOENT & last_component(where) == where
494 * for example, 'cvs co -d newdir module', where newdir hasn't
495 * been created yet, so leave current set to '.' and check that
500 error( 1, errno, "could not change directory to requested checkout directory `%s'", where );
503 hardpath_len = strlen (hardpath);
504 if (strlen (current) >= hardpath_len
505 && strncmp (current, hardpath, hardpath_len) == 0)
507 if (/* Current is a subdirectory of hardpath. */
508 current[hardpath_len] == '/'
510 /* Current is hardpath itself. */
511 || current[hardpath_len] == '\0')
514 /* It isn't a problem. For example, current is
515 "/foo/cvsroot-bar" and hardpath is "/foo/cvsroot". */
527 /* What to put in CVS/Repository. */
529 /* The path to the directory. */
532 /* If set, don't build the directory, just change to it.
533 The caller will also want to set REPOSITORY to NULL. */
536 struct dir_to_build *next;
539 static int build_dirs_and_chdir PROTO ((struct dir_to_build *list,
542 static void build_one_dir PROTO ((char *, char *, int));
545 build_one_dir (repository, dirpath, sticky)
554 if (m_type == EXPORT)
555 error (1, 0, "cannot export into a working directory");
557 else if (m_type == CHECKOUT)
559 /* I suspect that this check could be omitted. */
560 if (!isdir (repository))
561 error (1, 0, "there is no repository %s", repository);
563 if (Create_Admin (".", dirpath, repository,
564 sticky ? tag : (char *) NULL,
565 sticky ? date : (char *) NULL,
567 /* FIXME? This is a guess. If it is important
568 for nonbranch to be set correctly here I
569 think we need to write it one way now and
570 then rewrite it later via WriteTag, once
571 we've had a chance to call RCS_nodeisbranch
578 fp = open_file (CVSADM_ENTSTAT, "w+");
579 if (fclose (fp) == EOF)
580 error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
581 #ifdef SERVER_SUPPORT
583 server_set_entstat (dirpath, repository);
590 * process_module calls us back here so we do the actual checkout stuff
594 checkout_proc (argc, argv, where_orig, mwhere, mfile, shorten,
595 local_specified, omodule, msg)
611 char *oldupdate = NULL;
615 * OK, so we're doing the checkout! Our args are as follows:
616 * argc,argv contain either dir or dir followed by a list of files
617 * where contains where to put it (if supplied by checkout)
618 * mwhere contains the module name or -d from module file
619 * mfile says do only that part of the module
620 * shorten = 1 says shorten as much as possible
621 * omodule is the original arg to do_module()
624 /* Set up the repository (maybe) for the bottom directory.
625 Allocate more space than we need so we don't need to keep
626 reallocating this string. */
627 repository = xmalloc (strlen (current_parsed_root->directory)
629 + (mfile == NULL ? 0 : strlen (mfile))
631 (void) sprintf (repository, "%s/%s", current_parsed_root->directory, argv[0]);
632 Sanitize_Repository_Name (repository);
635 /* save the original value of preload_update_dir */
636 if (preload_update_dir != NULL)
637 oldupdate = xstrdup (preload_update_dir);
640 /* Allocate space and set up the where variable. We allocate more
641 space than necessary here so that we don't have to keep
642 reallocaing it later on. */
644 where = xmalloc (strlen (argv[0])
645 + (mfile == NULL ? 0 : strlen (mfile))
646 + (mwhere == NULL ? 0 : strlen (mwhere))
647 + (where_orig == NULL ? 0 : strlen (where_orig))
650 /* Yes, this could be written in a less verbose way, but in this
651 form it is quite easy to read.
653 FIXME? The following code that sets should probably be moved
654 to do_module in modules.c, since there is similar code in
655 patch.c and rtag.c. */
659 if (where_orig != NULL)
661 /* If the user has specified a directory with `-d' on the
662 command line, use it preferentially, even over the `-d'
663 flag in the modules file. */
665 (void) strcpy (where, where_orig);
667 else if (mwhere != NULL)
669 /* Second preference is the value of mwhere, which is from
670 the `-d' flag in the modules file. */
672 (void) strcpy (where, mwhere);
676 /* Third preference is the directory specified in argv[0]
677 which is this module'e directory in the repository. */
679 (void) strcpy (where, argv[0]);
684 /* Use the same preferences here, bug don't shorten -- that
685 is, tack on where_orig if it exists. */
689 if (where_orig != NULL)
691 (void) strcat (where, where_orig);
692 (void) strcat (where, "/");
695 /* If the -d flag in the modules file specified an absolute
696 directory, let the user override it with the command-line
699 if ((mwhere != NULL) && (! isabsolute (mwhere)))
700 (void) strcat (where, mwhere);
702 (void) strcat (where, argv[0]);
704 strip_trailing_slashes (where); /* necessary? */
707 /* At this point, the user may have asked for a single file or
708 directory from within a module. In that case, we should modify
709 where, repository, and argv as appropriate. */
713 /* The mfile variable can have one or more path elements. If
714 it has multiple elements, we want to tack those onto both
715 repository and where. The last element may refer to either
716 a file or directory. Here's what to do:
718 it refers to a directory
719 -> simply tack it on to where and repository
721 -> munge argv to contain `basename mfile` */
727 /* Paranoia check. */
729 if (mfile[strlen (mfile) - 1] == '/')
731 error (0, 0, "checkout_proc: trailing slash on mfile (%s)!",
736 /* Does mfile have multiple path elements? */
738 cp = strrchr (mfile, '/');
742 (void) strcat (repository, "/");
743 (void) strcat (repository, mfile);
744 (void) strcat (where, "/");
745 (void) strcat (where, mfile);
750 /* Now mfile is a single path element. */
752 path = xmalloc (strlen (repository) + strlen (mfile) + 5);
753 (void) sprintf (path, "%s/%s", repository, mfile);
756 /* It's a directory, so tack it on to repository and
757 where, as we did above. */
759 (void) strcat (repository, "/");
760 (void) strcat (repository, mfile);
761 (void) strcat (where, "/");
762 (void) strcat (where, mfile);
766 /* It's a file, which means we have to screw around with
776 if (preload_update_dir != NULL)
779 xrealloc (preload_update_dir,
780 strlen (preload_update_dir) + strlen (where) + 5);
781 strcat (preload_update_dir, "/");
782 strcat (preload_update_dir, where);
785 preload_update_dir = xstrdup (where);
788 * At this point, where is the directory we want to build, repository is
789 * the repository for the lowest level of the path.
791 * We need to tell build_dirs not only the path we want it to
792 * build, but also the repositories we want it to populate the
793 * path with. To accomplish this, we walk the path backwards, one
794 * pathname component at a time, constucting a linked list of
795 * struct dir_to_build.
799 * If we are sending everything to stdout, we can skip a whole bunch of
804 struct dir_to_build *head;
807 if (strncmp (repository, current_parsed_root->directory,
808 strlen (current_parsed_root->directory)) != 0)
810 internal error: %s doesn't start with %s in checkout_proc",
811 repository, current_parsed_root->directory);
813 /* We always create at least one directory, which corresponds to
814 the entire strings for WHERE and REPOSITORY. */
815 head = (struct dir_to_build *) xmalloc (sizeof (struct dir_to_build));
816 /* Special marker to indicate that we don't want build_dirs_and_chdir
817 to create the CVSADM directory for us. */
818 head->repository = NULL;
819 head->dirpath = xstrdup (where);
821 head->just_chdir = 0;
824 /* Make a copy of the repository name to play with. */
825 reposcopy = xstrdup (repository);
827 /* FIXME: this should be written in terms of last_component
828 instead of hardcoding '/'. This presumably affects OS/2,
829 NT, &c, if the user specifies '\'. Likewise for the call
831 cp = where + strlen (where);
834 struct dir_to_build *new;
836 cp = findslash (where, cp - 1);
838 break; /* we're done */
840 new = (struct dir_to_build *)
841 xmalloc (sizeof (struct dir_to_build));
842 new->dirpath = xmalloc (strlen (where));
844 /* If the user specified an absolute path for where, the
845 last path element we create should be the top-level
850 strncpy (new->dirpath, where, cp - where);
851 new->dirpath[cp - where] = '\0';
855 /* where should always be at least one character long. */
856 assert (where[0] != '\0');
857 strcpy (new->dirpath, "/");
862 /* If where consists of multiple pathname components,
863 then we want to just cd into it, without creating
864 directories or modifying CVS directories as we go.
865 In CVS 1.9 and earlier, the code actually does a
866 CVS_CHDIR up-front; I'm not going to try to go back
867 to that exact code but this is somewhat similar
869 if (where_orig != NULL
870 && cp - where < strlen (where_orig))
872 new->repository = NULL;
879 /* Now figure out what repository directory to generate.
880 The most complete case would be something like this:
882 The modules file contains
885 The command issued was:
886 cvs co -d what/ever -N foo
888 The results in the CVS/Repository files should be:
889 . -> (don't touch CVS/Repository)
890 (I think this case might be buggy currently)
891 what -> (don't touch CVS/Repository)
892 ever -> . (same as "cd what/ever; cvs co -N foo")
893 bar -> Emptydir (generated dir -- not in repos)
894 baz -> quux (finally!) */
896 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
898 /* We can't walk up past CVSROOT. Instead, the
899 repository should be Emptydir. */
900 new->repository = emptydir_name ();
904 /* It's a directory in the repository! */
908 /* We'll always be below CVSROOT, but check for
910 rp = strrchr (reposcopy, '/');
913 "internal error: %s doesn't contain a slash",
917 new->repository = xmalloc (strlen (reposcopy) + 5);
918 (void) strcpy (new->repository, reposcopy);
920 if (strcmp (reposcopy, current_parsed_root->directory) == 0)
922 /* Special case -- the repository name needs
923 to be "/path/to/repos/." (the trailing dot
924 is important). We might be able to get rid
925 of this after the we check out the other
926 code that handles repository names. */
927 (void) strcat (new->repository, "/.");
935 /* The top-level CVSADM directory should always be
936 current_parsed_root->directory. Create it, but only if WHERE is
937 relative. If WHERE is absolute, our current directory
938 may not have a thing to do with where the sources are
939 being checked out. If it does, build_dirs_and_chdir
940 will take care of creating adm files here. */
941 /* FIXME: checking is_absolute (where) is a horrid kludge;
942 I suspect we probably can just skip the call to
943 build_one_dir whenever the -d command option was specified
946 if (!isabsolute (where) && top_level_admin && m_type == CHECKOUT)
948 /* It may be argued that we shouldn't set any sticky
949 bits for the top-level repository. FIXME? */
950 build_one_dir (current_parsed_root->directory, ".", argc <= 1);
952 #ifdef SERVER_SUPPORT
953 /* We _always_ want to have a top-level admin
954 directory. If we're running in client/server mode,
955 send a "Clear-static-directory" command to make
956 sure it is created on the client side. (See 5.10
957 in cvsclient.dvi to convince yourself that this is
958 OK.) If this is a duplicate command being sent, it
959 will be ignored on the client side. */
962 server_clear_entstat (".", current_parsed_root->directory);
967 /* Build dirs on the path if necessary and leave us in the
968 bottom directory (where if where was specified) doesn't
969 contain a CVS subdir yet, but all the others contain
970 CVS and Entries.Static files */
972 if (build_dirs_and_chdir (head, argc <= 1) != 0)
974 error (0, 0, "ignoring module %s", omodule);
979 /* set up the repository (or make sure the old one matches) */
980 if (!isfile (CVSADM))
984 if (!noexec && argc > 1)
986 /* I'm not sure whether this check is redundant. */
987 if (!isdir (repository))
988 error (1, 0, "there is no repository %s", repository);
990 Create_Admin (".", preload_update_dir, repository,
991 (char *) NULL, (char *) NULL, 0, 0,
993 fp = open_file (CVSADM_ENTSTAT, "w+");
994 if (fclose(fp) == EOF)
995 error(1, errno, "cannot close %s", CVSADM_ENTSTAT);
996 #ifdef SERVER_SUPPORT
998 server_set_entstat (where, repository);
1003 /* I'm not sure whether this check is redundant. */
1004 if (!isdir (repository))
1005 error (1, 0, "there is no repository %s", repository);
1007 Create_Admin (".", preload_update_dir, repository, tag, date,
1009 /* FIXME? This is a guess. If it is important
1010 for nonbranch to be set correctly here I
1011 think we need to write it one way now and
1012 then rewrite it later via WriteTag, once
1013 we've had a chance to call RCS_nodeisbranch
1015 0, 0, m_type == CHECKOUT);
1022 if (m_type == EXPORT)
1023 error (1, 0, "cannot export into working directory");
1025 /* get the contents of the previously existing repository */
1026 repos = Name_Repository ((char *) NULL, preload_update_dir);
1027 if (fncmp (repository, repos) != 0)
1029 error (0, 0, "existing repository %s does not match %s",
1031 error (0, 0, "ignoring module %s", omodule);
1041 * If we are going to be updating to stdout, we need to cd to the
1042 * repository directory so the recursion processor can use the current
1043 * directory as the place to find repository information
1047 if ( CVS_CHDIR (repository) < 0)
1049 error (0, errno, "cannot chdir to %s", repository);
1054 if (tag != NULL && !tag_validated)
1056 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag, NULL);
1062 which = W_LOCAL | W_REPOS;
1063 if (tag != NULL && !tag_validated)
1065 tag_check_valid (tag, argc - 1, argv + 1, 0, aflag,
1071 if (tag != NULL || date != NULL || join_rev1 != NULL)
1074 if (! join_tags_validated)
1076 if (join_rev1 != NULL)
1077 tag_check_valid_join (join_rev1, argc - 1, argv + 1, 0, aflag,
1079 if (join_rev2 != NULL)
1080 tag_check_valid_join (join_rev2, argc - 1, argv + 1, 0, aflag,
1082 join_tags_validated = 1;
1086 * if we are going to be recursive (building dirs), go ahead and call the
1087 * update recursion processor. We will be recursive unless either local
1088 * only was specified, or we were passed arguments
1090 if (!(local_specified || argc > 1))
1093 history_write (m_type == CHECKOUT ? 'O' : 'E', preload_update_dir,
1094 history_name, where, repository);
1095 err += do_update (0, (char **) NULL, options, tag, date,
1096 force_tag_match, 0 /* !local */ ,
1097 1 /* update -d */ , aflag, checkout_prune_dirs,
1098 pipeout, which, join_rev1, join_rev2,
1099 preload_update_dir, m_type == CHECKOUT,
1109 /* we are only doing files, so register them */
1110 entries = Entries_Open (0, NULL);
1111 for (i = 1; i < argc; i++)
1115 struct file_info finfo;
1117 memset (&finfo, 0, sizeof finfo);
1118 finfo.file = argv[i];
1119 /* Shouldn't be used, so set to arbitrary value. */
1120 finfo.update_dir = NULL;
1121 finfo.fullname = argv[i];
1122 finfo.repository = repository;
1123 finfo.entries = entries;
1124 /* The rcs slot is needed to get the options from the RCS
1126 finfo.rcs = RCS_parse (finfo.file, repository);
1128 vers = Version_TS (&finfo, options, tag, date,
1129 force_tag_match, 0);
1130 if (vers->ts_user == NULL)
1132 line = xmalloc (strlen (finfo.file) + 15);
1133 (void) sprintf (line, "Initial %s", finfo.file);
1134 Register (entries, finfo.file,
1135 vers->vn_rcs ? vers->vn_rcs : "0",
1136 line, vers->options, vers->tag,
1137 vers->date, (char *) 0);
1140 freevers_ts (&vers);
1141 freercsnode (&finfo.rcs);
1144 Entries_Close (entries);
1147 /* Don't log "export", just regular "checkouts" */
1148 if (m_type == CHECKOUT && !pipeout)
1149 history_write ('O', preload_update_dir, history_name, where,
1152 /* go ahead and call update now that everything is set */
1153 err += do_update (argc - 1, argv + 1, options, tag, date,
1154 force_tag_match, local_specified, 1 /* update -d */,
1155 aflag, checkout_prune_dirs, pipeout, which, join_rev1,
1156 join_rev2, preload_update_dir, m_type == CHECKOUT,
1159 free (preload_update_dir);
1160 preload_update_dir = oldupdate;
1167 findslash (start, p)
1173 if (*p == '/') return p;
1174 if (p == start) break;
1180 /* Return a newly malloc'd string containing a pathname for CVSNULLREPOS,
1181 and make sure that it exists. If there is an error creating the
1182 directory, give a fatal error. Otherwise, the directory is guaranteed
1183 to exist when we return. */
1189 repository = xmalloc (strlen (current_parsed_root->directory)
1190 + sizeof (CVSROOTADM)
1191 + sizeof (CVSNULLREPOS)
1193 (void) sprintf (repository, "%s/%s/%s", current_parsed_root->directory,
1194 CVSROOTADM, CVSNULLREPOS);
1195 if (!isfile (repository))
1198 omask = umask (cvsumask);
1199 if (CVS_MKDIR (repository, 0777) < 0)
1200 error (1, errno, "cannot create %s", repository);
1201 (void) umask (omask);
1206 /* Build all the dirs along the path to DIRS with CVS subdirs with appropriate
1207 * repositories. If DIRS->repository is NULL or the directory already exists,
1208 * do not create a CVSADM directory for that subdirectory; just CVS_CHDIR into
1209 * it. Frees all storage used by DIRS.
1212 * 1. Parent directories will be listed in DIRS before their children.
1213 * 2. At most a single directory will need to be changed at one time. In
1214 * other words, if we are in /a/b/c, and our final destination is
1215 * /a/b/c/d/e/f, then we will build d, then d/e, then d/e/f.
1218 * dirs Simple list composed of dir_to_build structures, listing
1219 * information about directories to build.
1220 * sticky Passed to build_one_dir to tell it whether there are any sticky
1221 * tags or dates to be concerned with.
1224 * 1 on error, 0 otherwise.
1227 * The only nonfatal error this function may return is if the CHDIR fails.
1230 build_dirs_and_chdir (dirs, sticky)
1231 struct dir_to_build *dirs;
1235 struct dir_to_build *nextdir;
1237 while (dirs != NULL)
1239 const char *dir = last_component (dirs->dirpath);
1241 if (!dirs->just_chdir)
1243 mkdir_if_needed (dir);
1244 Subdir_Register (NULL, NULL, dir);
1247 if (CVS_CHDIR (dir) < 0)
1249 error (0, errno, "cannot chdir to %s", dir);
1253 if (dirs->repository != NULL)
1255 build_one_dir (dirs->repository, dirs->dirpath, sticky);
1256 free (dirs->repository);
1258 nextdir = dirs->next;
1259 free (dirs->dirpath);
1265 while (dirs != NULL)
1267 if (dirs->repository != NULL)
1268 free (dirs->repository);
1269 nextdir = dirs->next;
1270 free (dirs->dirpath);