2 * Copyright (c) 1992, Brian Berliner and Jeff Polk
4 * You may distribute under the terms of the GNU General Public License as
5 * specified in the README file that comes with the CVS source distribution.
7 * General recursion handler
18 static int do_dir_proc PROTO((Node * p, void *closure));
19 static int do_file_proc PROTO((Node * p, void *closure));
20 static void addlist PROTO((List ** listp, char *key));
21 static int unroll_files_proc PROTO((Node *p, void *closure));
22 static void addfile PROTO((List **listp, char *dir, char *file));
24 static char *update_dir;
25 static char *repository = NULL;
26 static List *filelist = NULL; /* holds list of files on which to operate */
27 static List *dirlist = NULL; /* holds list of directories on which to operate */
29 struct recursion_frame {
31 FILESDONEPROC filesdoneproc;
32 DIRENTPROC direntproc;
33 DIRLEAVEPROC dirleaveproc;
40 char *repository; /* Keep track of repository for rtag */
43 static int do_recursion PROTO ((struct recursion_frame *frame));
45 /* I am half tempted to shove a struct file_info * into the struct
46 recursion_frame (but then we would need to modify or create a
47 recursion_frame for each file), or shove a struct recursion_frame *
48 into the struct file_info (more tempting, although it isn't completely
49 clear that the struct file_info should contain info about recursion
50 processor internals). So instead use this struct. */
52 struct frame_and_file {
53 struct recursion_frame *frame;
54 struct file_info *finfo;
57 /* Similarly, we need to pass the entries list to do_dir_proc. */
59 struct frame_and_entries {
60 struct recursion_frame *frame;
65 /* Start a recursive command.
67 Command line arguments (ARGC, ARGV) dictate the directories and
68 files on which we operate. In the special case of no arguments, we
71 start_recursion (fileproc, filesdoneproc, direntproc, dirleaveproc, callerdat,
72 argc, argv, local, which, aflag, locktype,
73 update_preload, dosrcs, repository_in)
75 FILESDONEPROC filesdoneproc;
76 DIRENTPROC direntproc;
77 DIRLEAVEPROC dirleaveproc;
84 /* This specifies the kind of recursion. There are several cases:
86 1. W_LOCAL is not set but W_REPOS or W_ATTIC is. The current
87 directory when we are called must be the repository and
88 recursion proceeds according to what exists in the repository.
90 2a. W_LOCAL is set but W_REPOS and W_ATTIC are not. The
91 current directory when we are called must be the working
92 directory. Recursion proceeds according to what exists in the
93 working directory, never (I think) consulting any part of the
94 repository which does not correspond to the working directory
95 ("correspond" == Name_Repository).
97 2b. W_LOCAL is set and so is W_REPOS or W_ATTIC. This is the
98 weird one. The current directory when we are called must be
99 the working directory. We recurse through working directories,
100 but we recurse into a directory if it is exists in the working
101 directory *or* it exists in the repository. If a directory
102 does not exist in the working directory, the direntproc must
103 either tell us to skip it (R_SKIP_ALL), or must create it (I
104 think those are the only two cases). */
109 char *update_preload;
111 /* Keep track of the repository string. This is only for the remote mode,
112 * specifically, r* commands (rtag, rdiff, co, ...) where xgetwd() was
113 * used to locate the repository. Things would break when xgetwd() was
114 * used with a symlinked repository because xgetwd() would return the true
115 * path and in some cases this would cause the path to be printed as other
116 * than the user specified in error messages and in other cases some of
117 * CVS's security assertions would fail.
122 #ifdef CLIENT_SUPPORT
123 List *args_to_send_when_finished = NULL;
125 List *files_by_dir = NULL;
126 struct recursion_frame frame;
128 frame.fileproc = fileproc;
129 frame.filesdoneproc = filesdoneproc;
130 frame.direntproc = direntproc;
131 frame.dirleaveproc = dirleaveproc;
132 frame.callerdat = callerdat;
133 frame.flags = local ? R_SKIP_DIRS : R_PROCESS;
136 frame.locktype = locktype;
137 frame.dosrcs = dosrcs;
138 frame.repository = repository_in;
140 expand_wild (argc, argv, &argc, &argv);
142 if (update_preload == NULL)
143 update_dir = xstrdup ("");
145 update_dir = xstrdup (update_preload);
147 /* clean up from any previous calls to start_recursion */
151 repository = (char *) NULL;
154 dellist (&filelist); /* FIXME-krp: no longer correct. */
158 #ifdef SERVER_SUPPORT
161 for (i = 0; i < argc; ++i)
162 server_pathname_check (argv[i]);
168 int just_subdirs = (which & W_LOCAL) && !isdir (CVSADM);
170 #ifdef CLIENT_SUPPORT
172 && CVSroot_cmdline == NULL
173 && current_parsed_root->isremote)
175 char *root = Name_Root (NULL, update_dir);
176 if (root && strcmp (root, current_parsed_root->original) != 0)
177 /* We're skipping this directory because it is for
178 a different root. Therefore, we just want to
179 do the subdirectories only. Processing files would
180 cause a working directory from one repository to be
181 processed against a different repository, which could
182 cause all kinds of spurious conflicts and such.
184 Question: what about the case of "cvs update foo"
185 where we process foo/bar and not foo itself? That
186 seems to be handled somewhere (else) but why should
187 it be a separate case? Needs investigation... */
194 * There were no arguments, so we'll probably just recurse. The
195 * exception to the rule is when we are called from a directory
196 * without any CVS administration files. That has always meant to
197 * process each of the sub-directories, so we pretend like we were
198 * called with the list of sub-dirs of the current dir as args
202 dirlist = Find_Directories ((char *) NULL, W_LOCAL, (List *) NULL);
203 /* If there are no sub-directories, there is a certain logic in
204 favor of doing nothing, but in fact probably the user is just
205 confused about what directory they are in, or whether they
206 cvs add'd a new directory. In the case of at least one
207 sub-directory, at least when we recurse into them we
208 notice (hopefully) whether they are under CVS control. */
209 if (list_isempty (dirlist))
211 if (update_dir[0] == '\0')
212 error (0, 0, "in directory .:");
214 error (0, 0, "in directory %s:", update_dir);
216 "there is no version here; run '%s checkout' first",
219 #ifdef CLIENT_SUPPORT
220 else if (current_parsed_root->isremote && server_started)
222 /* In the the case "cvs update foo bar baz", a call to
223 send_file_names in update.c will have sent the
224 appropriate "Argument" commands to the server. In
225 this case, that won't have happened, so we need to
226 do it here. While this example uses "update", this
227 generalizes to other commands. */
229 /* This is the same call to Find_Directories as above.
230 FIXME: perhaps it would be better to write a
231 function that duplicates a list. */
232 args_to_send_when_finished = Find_Directories ((char *) NULL,
239 addlist (&dirlist, ".");
246 * There were arguments, so we have to handle them by hand. To do
247 * that, we set up the filelist and dirlist with the arguments and
248 * call do_recursion. do_recursion recognizes the fact that the
249 * lists are non-null when it starts and doesn't update them.
251 * explicitly named directories are stored in dirlist.
252 * explicitly named files are stored in filelist.
253 * other possibility is named entities whicha are not currently in
254 * the working directory.
257 for (i = 0; i < argc; i++)
259 /* if this argument is a directory, then add it to the list of
262 if (!wrap_name_has (argv[i], WRAP_TOCVS) && isdir (argv[i]))
264 strip_trailing_slashes (argv[i]);
265 addlist (&dirlist, argv[i]);
269 /* otherwise, split argument into directory and component names. */
274 /* Now break out argv[i] into directory part (DIR) and file part (COMP).
275 DIR and COMP will each point to a newly malloc'd string. */
276 dir = xstrdup (argv[i]);
277 /* Its okay to discard the const below - we know we just allocated
280 comp = (char *)last_component (dir);
283 /* no dir component. What we have is an implied "./" */
294 /* if this argument exists as a file in the current
295 working directory tree, then add it to the files list. */
297 if (!(which & W_LOCAL))
299 /* If doing rtag, we've done a chdir to the repository. */
300 file_to_try = xmalloc (strlen (argv[i]) + sizeof (RCSEXT) + 5);
301 sprintf (file_to_try, "%s%s", argv[i], RCSEXT);
304 file_to_try = xstrdup (argv[i]);
306 if (isfile (file_to_try))
307 addfile (&files_by_dir, dir, comp);
308 else if (isdir (dir))
310 if ((which & W_LOCAL) && isdir (CVSADM)
311 #ifdef CLIENT_SUPPORT
312 && !current_parsed_root->isremote
316 /* otherwise, look for it in the repository. */
317 char *tmp_update_dir;
321 tmp_update_dir = xmalloc (strlen (update_dir)
324 strcpy (tmp_update_dir, update_dir);
326 if (*tmp_update_dir != '\0')
327 (void) strcat (tmp_update_dir, "/");
329 (void) strcat (tmp_update_dir, dir);
331 /* look for it in the repository. */
332 repos = Name_Repository (dir, tmp_update_dir);
333 reposfile = xmalloc (strlen (repos)
336 (void) sprintf (reposfile, "%s/%s", repos, comp);
339 if (!wrap_name_has (comp, WRAP_TOCVS) && isdir (reposfile))
340 addlist (&dirlist, argv[i]);
342 addfile (&files_by_dir, dir, comp);
344 free (tmp_update_dir);
348 addfile (&files_by_dir, dir, comp);
351 error (1, 0, "no such directory `%s'", dir);
359 /* At this point we have looped over all named arguments and built
360 a coupla lists. Now we unroll the lists, setting up and
361 calling do_recursion. */
363 err += walklist (files_by_dir, unroll_files_proc, (void *) &frame);
364 dellist(&files_by_dir);
366 /* then do_recursion on the dirlist. */
370 err += do_recursion (&frame);
373 /* Free the data which expand_wild allocated. */
374 free_names (&argc, argv);
379 #ifdef CLIENT_SUPPORT
380 if (args_to_send_when_finished != NULL)
382 /* FIXME (njc): in the multiroot case, we don't want to send
383 argument commands for those top-level directories which do
384 not contain any subdirectories which have files checked out
385 from current_parsed_root->original. If we do, and two repositories
386 have a module with the same name, nasty things could happen.
388 This is hard. Perhaps we should send the Argument commands
389 later in this procedure, after we've had a chance to notice
390 which directores we're using (after do_recursion has been
391 called once). This means a _lot_ of rewriting, however.
393 What we need to do for that to happen is descend the tree
394 and construct a list of directories which are checked out
395 from current_cvsroot. Now, we eliminate from the list all
396 of those directories which are immediate subdirectories of
397 another directory in the list. To say that the opposite
398 way, we keep the directories which are not immediate
399 subdirectories of any other in the list. Here's a picture:
411 The node in capitals are those directories which are
412 checked out from current_cvsroot. We want the list to
413 contain B, C, F, and G. D, H, and I are not included,
414 because their parents are also checked out from
417 The algorithm should be:
419 1) construct a tree of all directory names where each
420 element contains a directory name and a flag which notes if
421 that directory is checked out from current_cvsroot
433 2) Recursively descend the tree. For each node, recurse
434 before processing the node. If the flag is zero, do
435 nothing. If the flag is 1, check the node's parent. If
436 the parent's flag is one, change the current entry's flag
449 3) Walk the tree and spit out "Argument" commands to tell
450 the server which directories to munge.
452 Yuck. It's not clear this is worth spending time on, since
453 we might want to disable cvs commands entirely from
454 directories that do not have CVSADM files...
456 Anyways, the solution as it stands has modified server.c
457 (dirswitch) to create admin files [via server.c
458 (create_adm_p)] in all path elements for a client's
459 "Directory xxx" command, which forces the server to descend
460 and serve the files there. client.c (send_file_names) has
461 also been modified to send only those arguments which are
462 appropriate to current_parsed_root->original.
466 /* Construct a fake argc/argv pair. */
469 char **our_argv = NULL;
471 if (! list_isempty (args_to_send_when_finished))
475 head = args_to_send_when_finished->list;
477 /* count the number of nodes */
479 for (p = head->next; p != head; p = p->next)
483 /* create the argument vector */
484 our_argv = (char **) xmalloc (sizeof (char *) * our_argc);
488 for (p = head->next; p != head; p = p->next)
489 our_argv[i++] = xstrdup (p->key);
492 /* We don't want to expand widcards, since we've just created
493 a list of directories directly from the filesystem. */
494 send_file_names (our_argc, our_argv, 0);
496 /* Free our argc/argv. */
497 if (our_argv != NULL)
499 for (i = 0; i < our_argc; i++)
504 dellist (&args_to_send_when_finished);
512 * Implement the recursive policies on the local directory. This may be
513 * called directly, or may be called by start_recursion
517 struct recursion_frame *frame;
521 char *srepository = NULL;
522 List *entries = NULL;
524 int process_this_directory = 1;
526 /* do nothing if told */
527 if (frame->flags == R_SKIP_ALL)
530 locktype = noexec ? CVS_LOCK_NONE : frame->locktype;
532 /* The fact that locks are not active here is what makes us fail to have
535 If someone commits some changes in one cvs command,
536 then an update by someone else will either get all the
537 changes, or none of them.
539 property (see node Concurrency in cvs.texinfo).
541 The most straightforward fix would just to readlock the whole
542 tree before starting an update, but that means that if a commit
543 gets blocked on a big update, it might need to wait a *long*
546 A more adequate fix would be a two-pass design for update,
547 checkout, etc. The first pass would go through the repository,
548 with the whole tree readlocked, noting what versions of each
549 file we want to get. The second pass would release all locks
550 (except perhaps short-term locks on one file at a
551 time--although I think RCS already deals with this) and
552 actually get the files, specifying the particular versions it wants.
554 This could be sped up by separating out the data needed for the
555 first pass into a separate file(s)--for example a file
556 attribute for each file whose value contains the head revision
557 for each branch. The structure should be designed so that
558 commit can relatively quickly update the information for a
559 single file or a handful of files (file attributes, as
560 implemented in Jan 96, are probably acceptable; improvements
561 would be possible such as branch attributes which are in
562 separate files for each branch). */
564 #if defined(SERVER_SUPPORT) && defined(SERVER_FLOWCONTROL)
566 * Now would be a good time to check to see if we need to stop
567 * generating data, to give the buffers a chance to drain to the
568 * remote client. We should not have locks active at this point,
569 * but if there are writelocks around, we cannot pause here. */
570 if (server_active && locktype != CVS_LOCK_NONE)
571 server_pause_check();
574 /* Check the value in CVSADM_ROOT and see if it's in the list. If
575 not, add it to our lists of CVS/Root directories and do not
576 process the files in this directory. Otherwise, continue as
577 usual. THIS_ROOT might be NULL if we're doing an initial
578 checkout -- check before using it. The default should be that
579 we process a directory's contents and only skip those contents
580 if a CVS/Root file exists.
582 If we're running the server, we want to process all
583 directories, since we're guaranteed to have only one CVSROOT --
587 /* If -d was specified, it should override CVS/Root.
589 In the single-repository case, it is long-standing CVS behavior
590 and makes sense - the user might want another access method,
591 another server (which mounts the same repository), &c.
593 In the multiple-repository case, -d overrides all CVS/Root
594 files. That is the only plausible generalization I can
596 CVSroot_cmdline == NULL
598 #ifdef SERVER_SUPPORT
603 char *this_root = Name_Root ((char *) NULL, update_dir);
604 if (this_root != NULL)
606 if (findnode (root_directories, this_root) == NULL)
608 /* Add it to our list. */
610 Node *n = getnode ();
611 n->type = NT_UNKNOWN;
612 n->key = xstrdup (this_root);
614 if (addnode (root_directories, n))
615 error (1, 0, "cannot add new CVSROOT %s", this_root);
619 process_this_directory =
620 (strcmp (current_parsed_root->original, this_root) == 0);
627 * Fill in repository with the current repository
629 if (frame->which & W_LOCAL)
633 repository = Name_Repository ((char *) NULL, update_dir);
634 srepository = repository; /* remember what to free */
641 repository = frame->repository;
642 assert (repository != NULL);
643 assert (strstr (repository, "/./") == NULL);
646 fileattr_startdir (repository);
649 * The filesdoneproc needs to be called for each directory where files
650 * processed, or each directory that is processed by a call where no
651 * directories were passed in. In fact, the only time we don't want to
652 * call back the filesdoneproc is when we are processing directories that
653 * were passed in on the command line (or in the special case of `.' when
654 * we were called with no args
656 if (dirlist != NULL && filelist == NULL)
660 * If filelist or dirlist is already set, we don't look again. Otherwise,
661 * find the files and directories
663 if (filelist == NULL && dirlist == NULL)
665 /* both lists were NULL, so start from scratch */
666 if (frame->fileproc != NULL && frame->flags != R_SKIP_FILES)
668 int lwhich = frame->which;
670 /* be sure to look in the attic if we have sticky tags/date */
671 if ((lwhich & W_ATTIC) == 0)
672 if (isreadable (CVSADM_TAG))
675 /* In the !(which & W_LOCAL) case, we filled in repository
676 earlier in the function. In the (which & W_LOCAL) case,
677 the Find_Names function is going to look through the
678 Entries file. If we do not have a repository, that
679 does not make sense, so we insist upon having a
680 repository at this point. Name_Repository will give a
681 reasonable error message. */
682 if (repository == NULL)
684 Name_Repository ((char *) NULL, update_dir);
685 assert (!"Not reached. Please report this problem to <bug-cvs@gnu.org>");
688 /* find the files and fill in entries if appropriate */
689 if (process_this_directory)
691 filelist = Find_Names (repository, lwhich, frame->aflag,
693 if (filelist == NULL)
695 error (0, 0, "skipping directory %s", update_dir);
696 /* Note that Find_Directories and the filesdoneproc
697 in particular would do bad things ("? foo.c" in
698 the case of some filesdoneproc's). */
704 /* find sub-directories if we will recurse */
705 if (frame->flags != R_SKIP_DIRS)
706 dirlist = Find_Directories (
707 process_this_directory ? repository : NULL,
708 frame->which, entries);
712 /* something was passed on the command line */
713 if (filelist != NULL && frame->fileproc != NULL)
715 /* we will process files, so pre-parse entries */
716 if (frame->which & W_LOCAL)
717 entries = Entries_Open (frame->aflag, NULL);
721 /* process the files (if any) */
722 if (process_this_directory && filelist != NULL && frame->fileproc)
724 struct file_info finfo_struct;
725 struct frame_and_file frfile;
727 /* read lock it if necessary */
730 if (locktype == CVS_LOCK_READ)
732 if (Reader_Lock (repository) != 0)
733 error (1, 0, "read lock failed - giving up");
735 else if (locktype == CVS_LOCK_WRITE)
736 lock_dir_for_write (repository);
739 #ifdef CLIENT_SUPPORT
740 /* For the server, we handle notifications in a completely different
741 place (server_notify). For local, we can't do them here--we don't
742 have writelocks in place, and there is no way to get writelocks
744 if (current_parsed_root->isremote)
745 notify_check (repository, update_dir);
746 #endif /* CLIENT_SUPPORT */
748 finfo_struct.repository = repository;
749 finfo_struct.update_dir = update_dir;
750 finfo_struct.entries = entries;
751 /* do_file_proc will fill in finfo_struct.file. */
753 frfile.finfo = &finfo_struct;
754 frfile.frame = frame;
756 /* process the files */
757 err += walklist (filelist, do_file_proc, &frfile);
760 if (/* We only lock the repository above when repository is set */
762 /* and when asked for a read or write lock. */
763 && locktype != CVS_LOCK_NONE)
770 /* call-back files done proc (if any) */
771 if (process_this_directory && dodoneproc && frame->filesdoneproc != NULL)
772 err = frame->filesdoneproc (frame->callerdat, err, repository,
773 update_dir[0] ? update_dir : ".",
780 /* process the directories (if necessary) */
783 struct frame_and_entries frent;
786 frent.entries = entries;
787 err += walklist (dirlist, do_dir_proc, (void *) &frent);
790 else if (frame->dirleaveproc != NULL)
791 err += frame->dirleaveproc (frame->callerdat, ".", err, ".");
797 Entries_Close (entries);
801 /* free the saved copy of the pointer if necessary */
806 repository = (char *) NULL;
814 * Process each of the files in the list with the callback proc
817 do_file_proc (p, closure)
821 struct frame_and_file *frfile = (struct frame_and_file *)closure;
822 struct file_info *finfo = frfile->finfo;
826 finfo->file = p->key;
827 tmp = xmalloc (strlen (finfo->file)
828 + strlen (finfo->update_dir)
831 if (finfo->update_dir[0] != '\0')
833 strcat (tmp, finfo->update_dir);
836 strcat (tmp, finfo->file);
838 if (frfile->frame->dosrcs && repository)
840 finfo->rcs = RCS_parse (finfo->file, repository);
842 /* OK, without W_LOCAL the error handling becomes relatively
843 simple. The file names came from readdir() on the
844 repository and so we know any ENOENT is an error
845 (e.g. symlink pointing to nothing). Now, the logic could
846 be simpler - since we got the name from readdir, we could
847 just be calling RCS_parsercsfile. */
848 if (finfo->rcs == NULL
849 && !(frfile->frame->which & W_LOCAL))
851 error (0, 0, "could not read RCS file for %s", tmp);
858 finfo->rcs = (RCSNode *) NULL;
859 finfo->fullname = tmp;
860 ret = frfile->frame->fileproc (frfile->frame->callerdat, finfo);
862 freercsnode(&finfo->rcs);
865 /* Allow the user to monitor progress with tail -f. Doing this once
866 per file should be no big deal, but we don't want the performance
867 hit of flushing on every line like previous versions of CVS. */
876 * Process each of the directories in the list (recursing as we go)
879 do_dir_proc (p, closure)
883 struct frame_and_entries *frent = (struct frame_and_entries *) closure;
884 struct recursion_frame *frame = frent->frame;
885 struct recursion_frame xframe;
890 Dtype dir_return = R_PROCESS;
891 int stripped_dot = 0;
893 struct saved_cwd cwd;
894 char *saved_update_dir;
895 int process_this_directory = 1;
897 if (fncmp (dir, CVSADM) == 0)
899 /* This seems to most often happen when users (beginning users,
900 generally), try "cvs ci *" or something similar. On that
901 theory, it is possible that we should just silently skip the
902 CVSADM directories, but on the other hand, using a wildcard
903 like this isn't necessarily a practice to encourage (it operates
904 only on files which exist in the working directory, unlike
905 regular CVS recursion). */
907 /* FIXME-reentrancy: printed_cvs_msg should be in a "command
908 struct" or some such, so that it gets cleared for each new
909 command (this is possible using the remote protocol and a
910 custom-written client). The struct recursion_frame is not
911 far back enough though, some commands (commit at least)
912 will call start_recursion several times. An alternate solution
913 would be to take this whole check and move it to a new function
914 validate_arguments or some such that all the commands call
915 and which snips the offending directory from the argc,argv
917 static int printed_cvs_msg = 0;
918 if (!printed_cvs_msg)
920 error (0, 0, "warning: directory %s specified in argument",
923 but CVS uses %s for its own purposes; skipping %s directory",
930 saved_update_dir = update_dir;
931 update_dir = xmalloc (strlen (saved_update_dir)
934 strcpy (update_dir, saved_update_dir);
936 /* set up update_dir - skip dots if not at start */
937 if (strcmp (dir, ".") != 0)
939 if (update_dir[0] != '\0')
941 (void) strcat (update_dir, "/");
942 (void) strcat (update_dir, dir);
945 (void) strcpy (update_dir, dir);
948 * Here we need a plausible repository name for the sub-directory. We
949 * create one by concatenating the new directory name onto the
950 * previous repository name. The only case where the name should be
951 * used is in the case where we are creating a new sub-directory for
952 * update -d and in that case the generated name will be correct.
954 if (repository == NULL)
955 newrepos = xstrdup ("");
958 newrepos = xmalloc (strlen (repository) + strlen (dir) + 5);
959 sprintf (newrepos, "%s/%s", repository, dir);
964 if (update_dir[0] == '\0')
965 (void) strcpy (update_dir, dir);
967 if (repository == NULL)
968 newrepos = xstrdup ("");
970 newrepos = xstrdup (repository);
973 /* Check to see that the CVSADM directory, if it exists, seems to be
974 well-formed. It can be missing files if the user hit ^C in the
975 middle of a previous run. We want to (a) make this a nonfatal
976 error, and (b) make sure we print which directory has the
979 Do this before the direntproc, so that (1) the direntproc
980 doesn't have to guess/deduce whether we will skip the directory
981 (e.g. send_dirent_proc and whether to send the directory), and
982 (2) so that the warm fuzzy doesn't get printed if we skip the
984 if (frame->which & W_LOCAL)
988 cvsadmdir = xmalloc (strlen (dir)
989 + sizeof (CVSADM_REP)
990 + sizeof (CVSADM_ENT)
993 strcpy (cvsadmdir, dir);
994 strcat (cvsadmdir, "/");
995 strcat (cvsadmdir, CVSADM);
996 if (isdir (cvsadmdir))
998 strcpy (cvsadmdir, dir);
999 strcat (cvsadmdir, "/");
1000 strcat (cvsadmdir, CVSADM_REP);
1001 if (!isfile (cvsadmdir))
1003 /* Some commands like update may have printed "? foo" but
1004 if we were planning to recurse, and don't on account of
1005 CVS/Repository, we want to say why. */
1006 error (0, 0, "ignoring %s (%s missing)", update_dir,
1008 dir_return = R_SKIP_ALL;
1011 /* Likewise for CVS/Entries. */
1012 if (dir_return != R_SKIP_ALL)
1014 strcpy (cvsadmdir, dir);
1015 strcat (cvsadmdir, "/");
1016 strcat (cvsadmdir, CVSADM_ENT);
1017 if (!isfile (cvsadmdir))
1019 /* Some commands like update may have printed "? foo" but
1020 if we were planning to recurse, and don't on account of
1021 CVS/Repository, we want to say why. */
1022 error (0, 0, "ignoring %s (%s missing)", update_dir,
1024 dir_return = R_SKIP_ALL;
1031 /* Only process this directory if the root matches. This nearly
1032 duplicates code in do_recursion. */
1035 /* If -d was specified, it should override CVS/Root.
1037 In the single-repository case, it is long-standing CVS behavior
1038 and makes sense - the user might want another access method,
1039 another server (which mounts the same repository), &c.
1041 In the multiple-repository case, -d overrides all CVS/Root
1042 files. That is the only plausible generalization I can
1044 CVSroot_cmdline == NULL
1046 #ifdef SERVER_SUPPORT
1051 char *this_root = Name_Root (dir, update_dir);
1052 if (this_root != NULL)
1054 if (findnode (root_directories, this_root) == NULL)
1056 /* Add it to our list. */
1058 Node *n = getnode ();
1059 n->type = NT_UNKNOWN;
1060 n->key = xstrdup (this_root);
1062 if (addnode (root_directories, n))
1063 error (1, 0, "cannot add new CVSROOT %s", this_root);
1067 process_this_directory = (strcmp (current_parsed_root->original, this_root) == 0);
1073 /* call-back dir entry proc (if any) */
1074 if (dir_return == R_SKIP_ALL)
1076 else if (frame->direntproc != NULL)
1078 /* If we're doing the actual processing, call direntproc.
1079 Otherwise, assume that we need to process this directory
1080 and recurse. FIXME. */
1082 if (process_this_directory)
1083 dir_return = frame->direntproc (frame->callerdat, dir, newrepos,
1084 update_dir, frent->entries);
1086 dir_return = R_PROCESS;
1090 /* Generic behavior. I don't see a reason to make the caller specify
1091 a direntproc just to get this. */
1092 if ((frame->which & W_LOCAL) && !isdir (dir))
1093 dir_return = R_SKIP_ALL;
1098 /* only process the dir if the return code was 0 */
1099 if (dir_return != R_SKIP_ALL)
1101 /* save our current directory and static vars */
1102 if (save_cwd (&cwd))
1105 srepository = repository;
1108 /* cd to the sub-directory */
1109 if (CVS_CHDIR (dir) < 0)
1110 error (1, errno, "could not chdir to %s", dir);
1112 /* honor the global SKIP_DIRS (a.k.a. local) */
1113 if (frame->flags == R_SKIP_DIRS)
1114 dir_return = R_SKIP_DIRS;
1116 /* remember if the `.' will be stripped for subsequent dirs */
1117 if (strcmp (update_dir, ".") == 0)
1119 update_dir[0] = '\0';
1123 /* make the recursive call */
1125 xframe.flags = dir_return;
1126 /* Keep track of repository, really just for r* commands (rtag, rdiff,
1127 * co, ...) to tag_check_valid, since all the other commands use
1128 * CVS/Repository to figure it out per directory.
1132 if (strcmp (dir, ".") == 0)
1133 xframe.repository = xstrdup (repository);
1136 xframe.repository = xmalloc (strlen (repository)
1139 sprintf (xframe.repository, "%s/%s", repository, dir);
1143 xframe.repository = NULL;
1144 err += do_recursion (&xframe);
1145 if (xframe.repository)
1147 free (xframe.repository);
1148 xframe.repository = NULL;
1151 /* put the `.' back if necessary */
1153 (void) strcpy (update_dir, ".");
1155 /* call-back dir leave proc (if any) */
1156 if (process_this_directory && frame->dirleaveproc != NULL)
1157 err = frame->dirleaveproc (frame->callerdat, dir, err, update_dir,
1160 /* get back to where we started and restore state vars */
1161 if (restore_cwd (&cwd, NULL))
1165 repository = srepository;
1169 update_dir = saved_update_dir;
1175 * Add a node to a list allocating the list if necessary.
1178 addlist (listp, key)
1185 *listp = getlist ();
1188 p->key = xstrdup (key);
1189 if (addnode (*listp, p) != 0)
1194 addfile (listp, dir, file)
1203 addlist (listp, dir);
1205 n = findnode (*listp, dir);
1208 error (1, 0, "can't find recently added dir node `%s' in start_recursion.",
1214 addlist (&fl, file);
1220 unroll_files_proc (p, closure)
1225 struct recursion_frame *frame = (struct recursion_frame *) closure;
1228 char *save_update_dir = NULL;
1229 struct saved_cwd cwd;
1231 /* if this dir was also an explicitly named argument, then skip
1232 it. We'll catch it later when we do dirs. */
1233 n = findnode (dirlist, p->key);
1237 /* otherwise, call dorecusion for this list of files. */
1240 save_dirlist = dirlist;
1243 if (strcmp(p->key, ".") != 0)
1245 if (save_cwd (&cwd))
1247 if ( CVS_CHDIR (p->key) < 0)
1248 error (1, errno, "could not chdir to %s", p->key);
1250 save_update_dir = update_dir;
1251 update_dir = xmalloc (strlen (save_update_dir)
1254 strcpy (update_dir, save_update_dir);
1256 if (*update_dir != '\0')
1257 (void) strcat (update_dir, "/");
1259 (void) strcat (update_dir, p->key);
1262 err += do_recursion (frame);
1264 if (save_update_dir != NULL)
1267 update_dir = save_update_dir;
1269 if (restore_cwd (&cwd, NULL))
1274 dirlist = save_dirlist;
1276 dellist (&filelist);