2 * Copyright (C) 1986-2008 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.
13 * General recursion handler
23 static int do_dir_proc PROTO((Node * p, void *closure));
24 static int do_file_proc PROTO((Node * p, void *closure));
25 static void addlist PROTO((List ** listp, char *key));
26 static int unroll_files_proc PROTO((Node *p, void *closure));
27 static void addfile PROTO((List **listp, char *dir, char *file));
29 static char *update_dir;
30 static char *repository = NULL;
31 static List *filelist = NULL; /* holds list of files on which to operate */
32 static List *dirlist = NULL; /* holds list of directories on which to operate */
34 struct recursion_frame {
36 FILESDONEPROC filesdoneproc;
37 DIRENTPROC direntproc;
38 DIRLEAVEPROC dirleaveproc;
45 char *repository; /* Keep track of repository for rtag */
48 static int do_recursion PROTO ((struct recursion_frame *frame));
50 /* I am half tempted to shove a struct file_info * into the struct
51 recursion_frame (but then we would need to modify or create a
52 recursion_frame for each file), or shove a struct recursion_frame *
53 into the struct file_info (more tempting, although it isn't completely
54 clear that the struct file_info should contain info about recursion
55 processor internals). So instead use this struct. */
57 struct frame_and_file {
58 struct recursion_frame *frame;
59 struct file_info *finfo;
62 /* Similarly, we need to pass the entries list to do_dir_proc. */
64 struct frame_and_entries {
65 struct recursion_frame *frame;
70 /* Start a recursive command.
72 Command line arguments (ARGC, ARGV) dictate the directories and
73 files on which we operate. In the special case of no arguments, we
76 start_recursion (fileproc, filesdoneproc, direntproc, dirleaveproc, callerdat,
77 argc, argv, local, which, aflag, locktype,
78 update_preload, dosrcs, repository_in)
80 FILESDONEPROC filesdoneproc;
81 DIRENTPROC direntproc;
82 DIRLEAVEPROC dirleaveproc;
89 /* This specifies the kind of recursion. There are several cases:
91 1. W_LOCAL is not set but W_REPOS or W_ATTIC is. The current
92 directory when we are called must be the repository and
93 recursion proceeds according to what exists in the repository.
95 2a. W_LOCAL is set but W_REPOS and W_ATTIC are not. The
96 current directory when we are called must be the working
97 directory. Recursion proceeds according to what exists in the
98 working directory, never (I think) consulting any part of the
99 repository which does not correspond to the working directory
100 ("correspond" == Name_Repository).
102 2b. W_LOCAL is set and so is W_REPOS or W_ATTIC. This is the
103 weird one. The current directory when we are called must be
104 the working directory. We recurse through working directories,
105 but we recurse into a directory if it is exists in the working
106 directory *or* it exists in the repository. If a directory
107 does not exist in the working directory, the direntproc must
108 either tell us to skip it (R_SKIP_ALL), or must create it (I
109 think those are the only two cases). */
114 char *update_preload;
116 /* Keep track of the repository string. This is only for the remote mode,
117 * specifically, r* commands (rtag, rdiff, co, ...) where xgetwd() was
118 * used to locate the repository. Things would break when xgetwd() was
119 * used with a symlinked repository because xgetwd() would return the true
120 * path and in some cases this would cause the path to be printed as other
121 * than the user specified in error messages and in other cases some of
122 * CVS's security assertions would fail.
127 #ifdef CLIENT_SUPPORT
128 List *args_to_send_when_finished = NULL;
130 List *files_by_dir = NULL;
131 struct recursion_frame frame;
133 frame.fileproc = fileproc;
134 frame.filesdoneproc = filesdoneproc;
135 frame.direntproc = direntproc;
136 frame.dirleaveproc = dirleaveproc;
137 frame.callerdat = callerdat;
138 frame.flags = local ? R_SKIP_DIRS : R_PROCESS;
141 frame.locktype = locktype;
142 frame.dosrcs = dosrcs;
144 /* If our repository_in has a trailing "/.", remove it before storing it
145 * for do_recursion().
147 * FIXME: This is somewhat of a hack in the sense that many of our callers
148 * painstakingly compute and add the trailing '.' we now remove.
150 while (repository_in && strlen (repository_in) >= 2
151 && repository_in[strlen (repository_in) - 2] == '/'
152 && repository_in[strlen (repository_in) - 1] == '.')
154 /* Beware the case where the string is exactly "/." or "//.".
155 * Paths with a leading "//" are special on some early UNIXes.
157 if (strlen (repository_in) == 2 || strlen (repository_in) == 3)
158 repository_in[strlen (repository_in) - 1] = '\0';
160 repository_in[strlen (repository_in) - 2] = '\0';
162 frame.repository = repository_in;
164 expand_wild (argc, argv, &argc, &argv);
166 if (update_preload == NULL)
167 update_dir = xstrdup ("");
169 update_dir = xstrdup (update_preload);
171 /* clean up from any previous calls to start_recursion */
175 repository = (char *) NULL;
178 dellist (&filelist); /* FIXME-krp: no longer correct. */
182 #ifdef SERVER_SUPPORT
185 for (i = 0; i < argc; ++i)
186 server_pathname_check (argv[i]);
192 int just_subdirs = (which & W_LOCAL) && !isdir (CVSADM);
194 #ifdef CLIENT_SUPPORT
196 && CVSroot_cmdline == NULL
197 && current_parsed_root->isremote)
199 cvsroot_t *root = Name_Root (NULL, update_dir);
202 if (strcmp (root->original, current_parsed_root->original))
203 /* We're skipping this directory because it is for
204 * a different root. Therefore, we just want to
205 * do the subdirectories only. Processing files would
206 * cause a working directory from one repository to be
207 * processed against a different repository, which could
208 * cause all kinds of spurious conflicts and such.
210 * Question: what about the case of "cvs update foo"
211 * where we process foo/bar and not foo itself? That
212 * seems to be handled somewhere (else) but why should
213 * it be a separate case? Needs investigation... */
215 free_cvsroot_t (root);
221 * There were no arguments, so we'll probably just recurse. The
222 * exception to the rule is when we are called from a directory
223 * without any CVS administration files. That has always meant to
224 * process each of the sub-directories, so we pretend like we were
225 * called with the list of sub-dirs of the current dir as args
229 dirlist = Find_Directories ((char *) NULL, W_LOCAL, (List *) NULL);
230 /* If there are no sub-directories, there is a certain logic in
231 favor of doing nothing, but in fact probably the user is just
232 confused about what directory they are in, or whether they
233 cvs add'd a new directory. In the case of at least one
234 sub-directory, at least when we recurse into them we
235 notice (hopefully) whether they are under CVS control. */
236 if (list_isempty (dirlist))
238 if (update_dir[0] == '\0')
239 error (0, 0, "in directory .:");
241 error (0, 0, "in directory %s:", update_dir);
243 "there is no version here; run '%s checkout' first",
246 #ifdef CLIENT_SUPPORT
247 else if (current_parsed_root->isremote && server_started)
249 /* In the the case "cvs update foo bar baz", a call to
250 send_file_names in update.c will have sent the
251 appropriate "Argument" commands to the server. In
252 this case, that won't have happened, so we need to
253 do it here. While this example uses "update", this
254 generalizes to other commands. */
256 /* This is the same call to Find_Directories as above.
257 FIXME: perhaps it would be better to write a
258 function that duplicates a list. */
259 args_to_send_when_finished = Find_Directories ((char *) NULL,
266 addlist (&dirlist, ".");
273 * There were arguments, so we have to handle them by hand. To do
274 * that, we set up the filelist and dirlist with the arguments and
275 * call do_recursion. do_recursion recognizes the fact that the
276 * lists are non-null when it starts and doesn't update them.
278 * explicitly named directories are stored in dirlist.
279 * explicitly named files are stored in filelist.
280 * other possibility is named entities whicha are not currently in
281 * the working directory.
284 for (i = 0; i < argc; i++)
286 /* if this argument is a directory, then add it to the list of
289 if (!wrap_name_has (argv[i], WRAP_TOCVS) && isdir (argv[i]))
291 strip_trailing_slashes (argv[i]);
292 addlist (&dirlist, argv[i]);
296 /* otherwise, split argument into directory and component names. */
301 /* Now break out argv[i] into directory part (DIR) and file part (COMP).
302 DIR and COMP will each point to a newly malloc'd string. */
303 dir = xstrdup (argv[i]);
304 /* Its okay to discard the const below - we know we just allocated
307 comp = (char *)last_component (dir);
310 /* no dir component. What we have is an implied "./" */
321 /* if this argument exists as a file in the current
322 working directory tree, then add it to the files list. */
324 if (!(which & W_LOCAL))
326 /* If doing rtag, we've done a chdir to the repository. */
327 file_to_try = xmalloc (strlen (argv[i]) + sizeof (RCSEXT) + 5);
328 sprintf (file_to_try, "%s%s", argv[i], RCSEXT);
331 file_to_try = xstrdup (argv[i]);
333 if (isfile (file_to_try))
334 addfile (&files_by_dir, dir, comp);
335 else if (isdir (dir))
337 if ((which & W_LOCAL) && isdir (CVSADM) &&
338 !current_parsed_root->isremote)
340 /* otherwise, look for it in the repository. */
341 char *tmp_update_dir;
345 tmp_update_dir = xmalloc (strlen (update_dir)
348 strcpy (tmp_update_dir, update_dir);
350 if (*tmp_update_dir != '\0')
351 (void) strcat (tmp_update_dir, "/");
353 (void) strcat (tmp_update_dir, dir);
355 /* look for it in the repository. */
356 repos = Name_Repository (dir, tmp_update_dir);
357 reposfile = xmalloc (strlen (repos)
360 (void) sprintf (reposfile, "%s/%s", repos, comp);
363 if (!wrap_name_has (comp, WRAP_TOCVS) && isdir (reposfile))
364 addlist (&dirlist, argv[i]);
366 addfile (&files_by_dir, dir, comp);
368 free (tmp_update_dir);
372 addfile (&files_by_dir, dir, comp);
375 error (1, 0, "no such directory `%s'", dir);
383 /* At this point we have looped over all named arguments and built
384 a coupla lists. Now we unroll the lists, setting up and
385 calling do_recursion. */
387 err += walklist (files_by_dir, unroll_files_proc, (void *) &frame);
388 dellist(&files_by_dir);
390 /* then do_recursion on the dirlist. */
394 err += do_recursion (&frame);
397 /* Free the data which expand_wild allocated. */
398 free_names (&argc, argv);
403 #ifdef CLIENT_SUPPORT
404 if (args_to_send_when_finished != NULL)
406 /* FIXME (njc): in the multiroot case, we don't want to send
407 argument commands for those top-level directories which do
408 not contain any subdirectories which have files checked out
409 from current_parsed_root->original. If we do, and two repositories
410 have a module with the same name, nasty things could happen.
412 This is hard. Perhaps we should send the Argument commands
413 later in this procedure, after we've had a chance to notice
414 which directores we're using (after do_recursion has been
415 called once). This means a _lot_ of rewriting, however.
417 What we need to do for that to happen is descend the tree
418 and construct a list of directories which are checked out
419 from current_cvsroot. Now, we eliminate from the list all
420 of those directories which are immediate subdirectories of
421 another directory in the list. To say that the opposite
422 way, we keep the directories which are not immediate
423 subdirectories of any other in the list. Here's a picture:
435 The node in capitals are those directories which are
436 checked out from current_cvsroot. We want the list to
437 contain B, C, F, and G. D, H, and I are not included,
438 because their parents are also checked out from
441 The algorithm should be:
443 1) construct a tree of all directory names where each
444 element contains a directory name and a flag which notes if
445 that directory is checked out from current_cvsroot
457 2) Recursively descend the tree. For each node, recurse
458 before processing the node. If the flag is zero, do
459 nothing. If the flag is 1, check the node's parent. If
460 the parent's flag is one, change the current entry's flag
473 3) Walk the tree and spit out "Argument" commands to tell
474 the server which directories to munge.
476 Yuck. It's not clear this is worth spending time on, since
477 we might want to disable cvs commands entirely from
478 directories that do not have CVSADM files...
480 Anyways, the solution as it stands has modified server.c
481 (dirswitch) to create admin files [via server.c
482 (create_adm_p)] in all path elements for a client's
483 "Directory xxx" command, which forces the server to descend
484 and serve the files there. client.c (send_file_names) has
485 also been modified to send only those arguments which are
486 appropriate to current_parsed_root->original.
490 /* Construct a fake argc/argv pair. */
493 char **our_argv = NULL;
495 if (! list_isempty (args_to_send_when_finished))
499 head = args_to_send_when_finished->list;
501 /* count the number of nodes */
503 for (p = head->next; p != head; p = p->next)
507 /* create the argument vector */
508 our_argv = (char **) xmalloc (sizeof (char *) * our_argc);
512 for (p = head->next; p != head; p = p->next)
513 our_argv[i++] = xstrdup (p->key);
516 /* We don't want to expand widcards, since we've just created
517 a list of directories directly from the filesystem. */
518 send_file_names (our_argc, our_argv, 0);
520 /* Free our argc/argv. */
521 if (our_argv != NULL)
523 for (i = 0; i < our_argc; i++)
528 dellist (&args_to_send_when_finished);
536 * Implement the recursive policies on the local directory. This may be
537 * called directly, or may be called by start_recursion
541 struct recursion_frame *frame;
545 char *srepository = NULL;
546 List *entries = NULL;
548 int process_this_directory = 1;
550 /* do nothing if told */
551 if (frame->flags == R_SKIP_ALL)
554 locktype = noexec ? CVS_LOCK_NONE : frame->locktype;
556 /* The fact that locks are not active here is what makes us fail to have
559 If someone commits some changes in one cvs command,
560 then an update by someone else will either get all the
561 changes, or none of them.
563 property (see node Concurrency in cvs.texinfo).
565 The most straightforward fix would just to readlock the whole
566 tree before starting an update, but that means that if a commit
567 gets blocked on a big update, it might need to wait a *long*
570 A more adequate fix would be a two-pass design for update,
571 checkout, etc. The first pass would go through the repository,
572 with the whole tree readlocked, noting what versions of each
573 file we want to get. The second pass would release all locks
574 (except perhaps short-term locks on one file at a
575 time--although I think RCS already deals with this) and
576 actually get the files, specifying the particular versions it wants.
578 This could be sped up by separating out the data needed for the
579 first pass into a separate file(s)--for example a file
580 attribute for each file whose value contains the head revision
581 for each branch. The structure should be designed so that
582 commit can relatively quickly update the information for a
583 single file or a handful of files (file attributes, as
584 implemented in Jan 96, are probably acceptable; improvements
585 would be possible such as branch attributes which are in
586 separate files for each branch). */
588 #if defined(SERVER_SUPPORT) && defined(SERVER_FLOWCONTROL)
590 * Now would be a good time to check to see if we need to stop
591 * generating data, to give the buffers a chance to drain to the
592 * remote client. We should not have locks active at this point,
593 * but if there are writelocks around, we cannot pause here. */
594 if (server_active && locktype != CVS_LOCK_WRITE)
595 server_pause_check();
598 /* Check the value in CVSADM_ROOT and see if it's in the list. If
599 not, add it to our lists of CVS/Root directories and do not
600 process the files in this directory. Otherwise, continue as
601 usual. THIS_ROOT might be NULL if we're doing an initial
602 checkout -- check before using it. The default should be that
603 we process a directory's contents and only skip those contents
604 if a CVS/Root file exists.
606 If we're running the server, we want to process all
607 directories, since we're guaranteed to have only one CVSROOT --
610 /* If -d was specified, it should override CVS/Root.
612 In the single-repository case, it is long-standing CVS behavior
613 and makes sense - the user might want another access method,
614 another server (which mounts the same repository), &c.
616 In the multiple-repository case, -d overrides all CVS/Root
617 files. That is the only plausible generalization I can
619 if (CVSroot_cmdline == NULL && !server_active)
621 cvsroot_t *this_root = Name_Root ((char *) NULL, update_dir);
622 if (this_root != NULL)
624 if (findnode (root_directories, this_root->original))
626 process_this_directory = !strcmp (current_parsed_root->original,
627 this_root->original);
628 free_cvsroot_t (this_root);
632 /* Add it to our list. */
634 Node *n = getnode ();
635 n->type = NT_UNKNOWN;
636 n->key = xstrdup (this_root->original);
639 if (addnode (root_directories, n))
640 error (1, 0, "cannot add new CVSROOT %s",
641 this_root->original);
643 process_this_directory = 0;
649 * Fill in repository with the current repository
651 if (frame->which & W_LOCAL)
655 repository = Name_Repository ((char *) NULL, update_dir);
656 srepository = repository; /* remember what to free */
663 repository = frame->repository;
664 assert (repository != NULL);
667 fileattr_startdir (repository);
670 * The filesdoneproc needs to be called for each directory where files
671 * processed, or each directory that is processed by a call where no
672 * directories were passed in. In fact, the only time we don't want to
673 * call back the filesdoneproc is when we are processing directories that
674 * were passed in on the command line (or in the special case of `.' when
675 * we were called with no args
677 if (dirlist != NULL && filelist == NULL)
681 * If filelist or dirlist is already set, we don't look again. Otherwise,
682 * find the files and directories
684 if (filelist == NULL && dirlist == NULL)
686 /* both lists were NULL, so start from scratch */
687 if (frame->fileproc != NULL && frame->flags != R_SKIP_FILES)
689 int lwhich = frame->which;
691 /* be sure to look in the attic if we have sticky tags/date */
692 if ((lwhich & W_ATTIC) == 0)
693 if (isreadable (CVSADM_TAG))
696 /* In the !(which & W_LOCAL) case, we filled in repository
697 earlier in the function. In the (which & W_LOCAL) case,
698 the Find_Names function is going to look through the
699 Entries file. If we do not have a repository, that
700 does not make sense, so we insist upon having a
701 repository at this point. Name_Repository will give a
702 reasonable error message. */
703 if (repository == NULL)
705 Name_Repository ((char *) NULL, update_dir);
706 assert (!"Not reached. Please report this problem to <"
707 PACKAGE_BUGREPORT ">");
710 /* find the files and fill in entries if appropriate */
711 if (process_this_directory)
713 filelist = Find_Names (repository, lwhich, frame->aflag,
715 if (filelist == NULL)
717 error (0, 0, "skipping directory %s", update_dir);
718 /* Note that Find_Directories and the filesdoneproc
719 in particular would do bad things ("? foo.c" in
720 the case of some filesdoneproc's). */
726 /* find sub-directories if we will recurse */
727 if (frame->flags != R_SKIP_DIRS)
728 dirlist = Find_Directories (
729 process_this_directory ? repository : NULL,
730 frame->which, entries);
734 /* something was passed on the command line */
735 if (filelist != NULL && frame->fileproc != NULL)
737 /* we will process files, so pre-parse entries */
738 if (frame->which & W_LOCAL)
739 entries = Entries_Open (frame->aflag, NULL);
743 /* process the files (if any) */
744 if (process_this_directory && filelist != NULL && frame->fileproc)
746 struct file_info finfo_struct;
747 struct frame_and_file frfile;
749 /* read lock it if necessary */
752 if (locktype == CVS_LOCK_READ)
754 if (Reader_Lock (repository) != 0)
755 error (1, 0, "read lock failed - giving up");
757 else if (locktype == CVS_LOCK_WRITE)
758 lock_dir_for_write (repository);
761 #ifdef CLIENT_SUPPORT
762 /* For the server, we handle notifications in a completely different
763 place (server_notify). For local, we can't do them here--we don't
764 have writelocks in place, and there is no way to get writelocks
766 if (current_parsed_root->isremote)
767 cvs_notify_check (repository, update_dir);
768 #endif /* CLIENT_SUPPORT */
770 finfo_struct.repository = repository;
771 finfo_struct.update_dir = update_dir;
772 finfo_struct.entries = entries;
773 /* do_file_proc will fill in finfo_struct.file. */
775 frfile.finfo = &finfo_struct;
776 frfile.frame = frame;
778 /* process the files */
779 err += walklist (filelist, do_file_proc, &frfile);
782 if (/* We only lock the repository above when repository is set */
784 /* and when asked for a read or write lock. */
785 && locktype != CVS_LOCK_NONE)
792 /* call-back files done proc (if any) */
793 if (process_this_directory && dodoneproc && frame->filesdoneproc != NULL)
794 err = frame->filesdoneproc (frame->callerdat, err, repository,
795 update_dir[0] ? update_dir : ".",
802 /* process the directories (if necessary) */
805 struct frame_and_entries frent;
808 frent.entries = entries;
809 err += walklist (dirlist, do_dir_proc, (void *) &frent);
812 else if (frame->dirleaveproc != NULL)
813 err += frame->dirleaveproc (frame->callerdat, ".", err, ".");
819 Entries_Close (entries);
823 /* free the saved copy of the pointer if necessary */
828 repository = (char *) NULL;
836 * Process each of the files in the list with the callback proc
839 do_file_proc (p, closure)
843 struct frame_and_file *frfile = (struct frame_and_file *)closure;
844 struct file_info *finfo = frfile->finfo;
848 finfo->file = p->key;
849 tmp = xmalloc (strlen (finfo->file)
850 + strlen (finfo->update_dir)
853 if (finfo->update_dir[0] != '\0')
855 strcat (tmp, finfo->update_dir);
858 strcat (tmp, finfo->file);
860 if (frfile->frame->dosrcs && repository)
862 finfo->rcs = RCS_parse (finfo->file, repository);
864 /* OK, without W_LOCAL the error handling becomes relatively
865 simple. The file names came from readdir() on the
866 repository and so we know any ENOENT is an error
867 (e.g. symlink pointing to nothing). Now, the logic could
868 be simpler - since we got the name from readdir, we could
869 just be calling RCS_parsercsfile. */
870 if (finfo->rcs == NULL
871 && !(frfile->frame->which & W_LOCAL))
873 error (0, 0, "could not read RCS file for %s", tmp);
880 finfo->rcs = (RCSNode *) NULL;
881 finfo->fullname = tmp;
882 ret = frfile->frame->fileproc (frfile->frame->callerdat, finfo);
884 freercsnode(&finfo->rcs);
887 /* Allow the user to monitor progress with tail -f. Doing this once
888 per file should be no big deal, but we don't want the performance
889 hit of flushing on every line like previous versions of CVS. */
898 * Process each of the directories in the list (recursing as we go)
901 do_dir_proc (p, closure)
905 struct frame_and_entries *frent = (struct frame_and_entries *) closure;
906 struct recursion_frame *frame = frent->frame;
907 struct recursion_frame xframe;
912 Dtype dir_return = R_PROCESS;
913 int stripped_dot = 0;
915 struct saved_cwd cwd;
916 char *saved_update_dir;
917 int process_this_directory = 1;
919 if (fncmp (dir, CVSADM) == 0)
921 /* This seems to most often happen when users (beginning users,
922 generally), try "cvs ci *" or something similar. On that
923 theory, it is possible that we should just silently skip the
924 CVSADM directories, but on the other hand, using a wildcard
925 like this isn't necessarily a practice to encourage (it operates
926 only on files which exist in the working directory, unlike
927 regular CVS recursion). */
929 /* FIXME-reentrancy: printed_cvs_msg should be in a "command
930 struct" or some such, so that it gets cleared for each new
931 command (this is possible using the remote protocol and a
932 custom-written client). The struct recursion_frame is not
933 far back enough though, some commands (commit at least)
934 will call start_recursion several times. An alternate solution
935 would be to take this whole check and move it to a new function
936 validate_arguments or some such that all the commands call
937 and which snips the offending directory from the argc,argv
939 static int printed_cvs_msg = 0;
940 if (!printed_cvs_msg)
942 error (0, 0, "warning: directory %s specified in argument",
945 but CVS uses %s for its own purposes; skipping %s directory",
952 saved_update_dir = update_dir;
953 update_dir = xmalloc (strlen (saved_update_dir)
956 strcpy (update_dir, saved_update_dir);
958 /* set up update_dir - skip dots if not at start */
959 if (strcmp (dir, ".") != 0)
961 if (update_dir[0] != '\0')
963 (void) strcat (update_dir, "/");
964 (void) strcat (update_dir, dir);
967 (void) strcpy (update_dir, dir);
970 * Here we need a plausible repository name for the sub-directory. We
971 * create one by concatenating the new directory name onto the
972 * previous repository name. The only case where the name should be
973 * used is in the case where we are creating a new sub-directory for
974 * update -d and in that case the generated name will be correct.
976 if (repository == NULL)
977 newrepos = xstrdup ("");
980 newrepos = xmalloc (strlen (repository) + strlen (dir) + 5);
981 sprintf (newrepos, "%s/%s", repository, dir);
986 if (update_dir[0] == '\0')
987 (void) strcpy (update_dir, dir);
989 if (repository == NULL)
990 newrepos = xstrdup ("");
992 newrepos = xstrdup (repository);
995 /* Check to see that the CVSADM directory, if it exists, seems to be
996 well-formed. It can be missing files if the user hit ^C in the
997 middle of a previous run. We want to (a) make this a nonfatal
998 error, and (b) make sure we print which directory has the
1001 Do this before the direntproc, so that (1) the direntproc
1002 doesn't have to guess/deduce whether we will skip the directory
1003 (e.g. send_dirent_proc and whether to send the directory), and
1004 (2) so that the warm fuzzy doesn't get printed if we skip the
1006 if (frame->which & W_LOCAL)
1010 cvsadmdir = xmalloc (strlen (dir)
1011 + sizeof (CVSADM_REP)
1012 + sizeof (CVSADM_ENT)
1015 strcpy (cvsadmdir, dir);
1016 strcat (cvsadmdir, "/");
1017 strcat (cvsadmdir, CVSADM);
1018 if (isdir (cvsadmdir))
1020 strcpy (cvsadmdir, dir);
1021 strcat (cvsadmdir, "/");
1022 strcat (cvsadmdir, CVSADM_REP);
1023 if (!isfile (cvsadmdir))
1025 /* Some commands like update may have printed "? foo" but
1026 if we were planning to recurse, and don't on account of
1027 CVS/Repository, we want to say why. */
1028 error (0, 0, "ignoring %s (%s missing)", update_dir,
1030 dir_return = R_SKIP_ALL;
1033 /* Likewise for CVS/Entries. */
1034 if (dir_return != R_SKIP_ALL)
1036 strcpy (cvsadmdir, dir);
1037 strcat (cvsadmdir, "/");
1038 strcat (cvsadmdir, CVSADM_ENT);
1039 if (!isfile (cvsadmdir))
1041 /* Some commands like update may have printed "? foo" but
1042 if we were planning to recurse, and don't on account of
1043 CVS/Repository, we want to say why. */
1044 error (0, 0, "ignoring %s (%s missing)", update_dir,
1046 dir_return = R_SKIP_ALL;
1053 /* Only process this directory if the root matches. This nearly
1054 duplicates code in do_recursion. */
1056 /* If -d was specified, it should override CVS/Root.
1058 In the single-repository case, it is long-standing CVS behavior
1059 and makes sense - the user might want another access method,
1060 another server (which mounts the same repository), &c.
1062 In the multiple-repository case, -d overrides all CVS/Root
1063 files. That is the only plausible generalization I can
1065 if (CVSroot_cmdline == NULL && !server_active)
1067 cvsroot_t *this_root = Name_Root (dir, update_dir);
1068 if (this_root != NULL)
1070 if (findnode (root_directories, this_root->original))
1072 process_this_directory = !strcmp (current_parsed_root->original,
1073 this_root->original);
1074 free_cvsroot_t (this_root);
1078 /* Add it to our list. */
1080 Node *n = getnode ();
1081 n->type = NT_UNKNOWN;
1082 n->key = xstrdup (this_root->original);
1083 n->data = this_root;
1085 if (addnode (root_directories, n))
1086 error (1, 0, "cannot add new CVSROOT %s",
1087 this_root->original);
1089 process_this_directory = 0;
1094 /* call-back dir entry proc (if any) */
1095 if (dir_return == R_SKIP_ALL)
1097 else if (frame->direntproc != NULL)
1099 /* If we're doing the actual processing, call direntproc.
1100 Otherwise, assume that we need to process this directory
1101 and recurse. FIXME. */
1103 if (process_this_directory)
1104 dir_return = frame->direntproc (frame->callerdat, dir, newrepos,
1105 update_dir, frent->entries);
1107 dir_return = R_PROCESS;
1111 /* Generic behavior. I don't see a reason to make the caller specify
1112 a direntproc just to get this. */
1113 if ((frame->which & W_LOCAL) && !isdir (dir))
1114 dir_return = R_SKIP_ALL;
1119 /* only process the dir if the return code was 0 */
1120 if (dir_return != R_SKIP_ALL)
1122 /* save our current directory and static vars */
1123 if (save_cwd (&cwd))
1126 srepository = repository;
1129 /* cd to the sub-directory */
1130 if (CVS_CHDIR (dir) < 0)
1131 error (1, errno, "could not chdir to %s", dir);
1133 /* honor the global SKIP_DIRS (a.k.a. local) */
1134 if (frame->flags == R_SKIP_DIRS)
1135 dir_return = R_SKIP_DIRS;
1137 /* remember if the `.' will be stripped for subsequent dirs */
1138 if (strcmp (update_dir, ".") == 0)
1140 update_dir[0] = '\0';
1144 /* make the recursive call */
1146 xframe.flags = dir_return;
1147 /* Keep track of repository, really just for r* commands (rtag, rdiff,
1148 * co, ...) to tag_check_valid, since all the other commands use
1149 * CVS/Repository to figure it out per directory.
1153 if (strcmp (dir, ".") == 0)
1154 xframe.repository = xstrdup (repository);
1157 xframe.repository = xmalloc (strlen (repository)
1160 sprintf (xframe.repository, "%s/%s", repository, dir);
1164 xframe.repository = NULL;
1165 err += do_recursion (&xframe);
1166 if (xframe.repository)
1168 free (xframe.repository);
1169 xframe.repository = NULL;
1172 /* put the `.' back if necessary */
1174 (void) strcpy (update_dir, ".");
1176 /* call-back dir leave proc (if any) */
1177 if (process_this_directory && frame->dirleaveproc != NULL)
1178 err = frame->dirleaveproc (frame->callerdat, dir, err, update_dir,
1181 /* get back to where we started and restore state vars */
1182 if (restore_cwd (&cwd, NULL))
1186 repository = srepository;
1190 update_dir = saved_update_dir;
1196 * Add a node to a list allocating the list if necessary.
1199 addlist (listp, key)
1206 *listp = getlist ();
1209 p->key = xstrdup (key);
1210 if (addnode (*listp, p) != 0)
1215 addfile (listp, dir, file)
1224 addlist (listp, dir);
1226 n = findnode (*listp, dir);
1229 error (1, 0, "can't find recently added dir node `%s' in start_recursion.",
1235 addlist (&fl, file);
1241 unroll_files_proc (p, closure)
1246 struct recursion_frame *frame = (struct recursion_frame *) closure;
1249 char *save_update_dir = NULL;
1250 struct saved_cwd cwd;
1252 /* if this dir was also an explicitly named argument, then skip
1253 it. We'll catch it later when we do dirs. */
1254 n = findnode (dirlist, p->key);
1258 /* otherwise, call dorecusion for this list of files. */
1261 save_dirlist = dirlist;
1264 if (strcmp(p->key, ".") != 0)
1266 if (save_cwd (&cwd))
1268 if ( CVS_CHDIR (p->key) < 0)
1269 error (1, errno, "could not chdir to %s", p->key);
1271 save_update_dir = update_dir;
1272 update_dir = xmalloc (strlen (save_update_dir)
1275 strcpy (update_dir, save_update_dir);
1277 if (*update_dir != '\0')
1278 (void) strcat (update_dir, "/");
1280 (void) strcat (update_dir, p->key);
1283 err += do_recursion (frame);
1285 if (save_update_dir != NULL)
1288 update_dir = save_update_dir;
1290 if (restore_cwd (&cwd, NULL))
1295 dirlist = save_dirlist;
1297 dellist (&filelist);