1 After applying this patch and running configure, you MUST run this
6 This patch adds the ability to merge rules into your excludes/includes
7 using a ". FILE" idiom. If you specify a name without slashes, that
8 filename will be looked for in every subdirectory that rsync visits,
9 and the rules found in that subdirectory's file will affect that dir
10 and (optionally) its subdirectories.
14 rsync -av --exclude='. .excl' --inherit=. from/ to
16 The above will look for a file named ".excl" in every directory of the
17 hierarchy that rsync visits, and it will exclude (by default) names
18 based on the rules found therein. If one of the .excl files contains
26 Then the file ".excl2" will also be read in the current dir, and all
27 subdirs of the current dir (due to the --inherit option). The file
28 ".excl3" would just be read in for the current dir because its name
33 --- exclude.c 22 May 2004 05:32:20 -0000 1.82
34 +++ exclude.c 4 Jun 2004 07:07:33 -0000
35 @@ -30,13 +30,59 @@ extern int verbose;
40 +extern int module_id;
41 +extern int inherit_exclude_levels;
42 +extern int sanitize_paths;
44 extern char curr_dir[];
45 +extern unsigned int curr_dir_len;
47 struct exclude_list_struct exclude_list = { 0, 0, "" };
48 -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " };
49 struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
50 char *exclude_path_prefix = NULL;
51 +struct exclude_struct **mergelist_parents;
52 +int mergelist_cnt = 0;
53 +int mergelist_size = 0;
55 +struct mergelist_save_struct {
56 + struct exclude_list_struct *array;
60 +static char dirbuf[MAXPATHLEN];
61 +static unsigned int dirbuf_offset = 0;
63 +/* Each exclude_list_struct describes a singly-linked list by keeping track
64 + * of both the head and tail pointers. The list is slightly unusual in that
65 + * a parent-dir's content can be appended to the end of the local list in a
66 + * special way: the last item in the local list has its "next" pointer set
67 + * to point to the inherited list, but the local list's tail pointer points
68 + * at the end of the local list. Thus, if the local list is empty, the head
69 + * will be pointing at the inherited content but the tail will be NULL. To
70 + * help you visualize this, here are the possible list arrangements:
72 + * Completely Empty Local Content Only
73 + * ================================== ====================================
74 + * head -> NULL head -> Local1 -> Local2 -> NULL
75 + * tail -> NULL tail -------------^
77 + * Inherited Content Only Both Local and Inherited Content
78 + * ================================== ====================================
79 + * head -> Parent1 -> Parent2 -> NULL head -> L1 -> L2 -> P1 -> P2 -> NULL
80 + * tail -> NULL tail ---------^
82 + * This means that anyone wanting to traverse the whole list to USE it just
83 + * needs to start at the head and use the "next" pointers until it goes
84 + * NULL. To add new local content, we insert the item after the tail item
85 + * and update the tail (obviously, if "tail" was NULL, we insert it at the
86 + * head). To clear the local list, WE MUST NOT FREE THE INHERITED CONTENT
87 + * because it is shared between the current list and our parent list(s).
88 + * The easiest way to handle this is to simply truncate the list after the
89 + * tail item and then free the local list from the head. When inheriting
90 + * the list for a new local dir, we just save off the exclude_list_struct
91 + * values (so we can pop back to them later) and set the tail to NULL.
94 /** Build an exclude structure given an exclude pattern. */
95 static void make_exclude(struct exclude_list_struct *listp, const char *pat,
96 @@ -46,6 +92,24 @@ static void make_exclude(struct exclude_
100 + if (mflags & MATCHFLG_MERGE_FILE) {
102 + /* If the local include file was already mentioned, don't
104 + for (i = 0; i < mergelist_cnt; i++) {
105 + struct exclude_struct *ex = mergelist_parents[i];
106 + if (strlen(ex->pattern) == pat_len
107 + && memcmp(ex->pattern, pat, pat_len) == 0)
110 + if ((pat_len == 10 || (pat_len > 10 && pat[pat_len-11] == '/'))
111 + && strncmp(pat+pat_len-10, ".cvsignore", 10) == 0) {
112 + mflags |= MATCHFLG_CVSIGNORE;
113 + mflags &= ~MATCHFLG_INCLUDE;
115 + mflags &= ~MATCHFLG_CVSIGNORE;
118 ret = new(struct exclude_struct);
120 out_of_memory("make_exclude");
121 @@ -81,14 +145,36 @@ static void make_exclude(struct exclude_
122 mflags |= MATCHFLG_DIRECTORY;
125 - for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
127 + if (mflags & MATCHFLG_MERGE_FILE) {
128 + struct exclude_list_struct *lp
129 + = new_array(struct exclude_list_struct, 1);
131 + out_of_memory("make_exclude");
132 + lp->head = lp->tail = NULL;
133 + if (asprintf(&lp->debug_type, "per-dir %s ", ret->pattern) < 0)
134 + out_of_memory("make_exclude");
135 + ret->u.mergelist = lp;
136 + if (mergelist_cnt == mergelist_size) {
137 + mergelist_size += 5;
138 + mergelist_parents = realloc_array(mergelist_parents,
139 + struct exclude_struct *,
141 + if (!mergelist_parents)
142 + out_of_memory("make_exclude");
144 + mergelist_parents[mergelist_cnt++] = ret;
146 + for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
147 + ret->u.slash_cnt++;
150 ret->match_flags = mflags;
153 + if (!listp->tail) {
154 + ret->next = listp->head;
155 listp->head = listp->tail = ret;
158 + ret->next = listp->tail->next;
159 listp->tail->next = ret;
162 @@ -96,22 +182,150 @@ static void make_exclude(struct exclude_
164 static void free_exclude(struct exclude_struct *ex)
166 + if (ex->match_flags & MATCHFLG_MERGE_FILE) {
167 + free(ex->u.mergelist->debug_type);
168 + free(ex->u.mergelist);
174 -void clear_exclude_list(struct exclude_list_struct *listp)
175 +static void clear_exclude_list(struct exclude_list_struct *listp)
177 - struct exclude_struct *ent, *next;
179 - for (ent = listp->head; ent; ent = next) {
183 + struct exclude_struct *ent, *next;
184 + /* Truncate any inherited items from the local list. */
185 + listp->tail->next = NULL;
186 + /* Now free everything that is left. */
187 + for (ent = listp->head; ent; ent = next) {
193 listp->head = listp->tail = NULL;
196 +void pre_inherit_files(char *fname, unsigned int len)
198 + char path[MAXPATHLEN], save[MAXPATHLEN];
199 + unsigned int limit;
202 + if (sanitize_paths)
203 + limit = strlen(lp_path(module_id));
208 + strcpy(path, fname);
210 + len = pathjoin(path, sizeof path, curr_dir, fname);
212 + if (len >= MAXPATHLEN || len == 0)
215 + for (i = inherit_exclude_levels, len--; i && len > limit; ) {
216 + if (path[--len] == '/')
219 + for (len++; i < inherit_exclude_levels; i++) {
220 + char *s = path + len;
222 + push_local_excludes(path, len);
224 + if (!(s = strchr(s, '/')))
225 + break; /* Impossible ... */
226 + len = s - path + 1;
230 +void *push_local_excludes(char *fname, unsigned int offset)
232 + struct mergelist_save_struct *push;
233 + struct exclude_list_struct *ap;
236 + /* Make it easy to construct the full path for a merge-file that was
237 + * specified with a relative path by saving off the current dir. */
238 + memcpy(dirbuf, fname, offset);
239 + dirbuf_offset = offset;
241 + if (!(push = new_array(struct mergelist_save_struct, 1)))
242 + out_of_memory("push_local_excludes");
244 + push->count = mergelist_cnt;
245 + push->array = new_array(struct exclude_list_struct, mergelist_cnt);
247 + out_of_memory("push_local_excludes");
249 + for (i = 0, ap = push->array; i < mergelist_cnt; i++) {
250 + memcpy(ap++, mergelist_parents[i]->u.mergelist,
251 + sizeof (struct exclude_list_struct));
254 + /* Note: add_exclude_file() might increase mergelist_cnt, so keep
255 + * this loop separate from the above loop. */
256 + for (i = 0; i < mergelist_cnt; i++) {
257 + struct exclude_struct *ex = mergelist_parents[i];
258 + struct exclude_list_struct *lp = ex->u.mergelist;
262 + rprintf(FINFO, "[%s] pushing %sexclude list\n",
263 + who_am_i(), lp->debug_type);
266 + if (ex->match_flags & MATCHFLG_CVSIGNORE) {
267 + lp->head = NULL; /* CVS doesn't inherit rules. */
268 + flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY;
270 + flags = ex->match_flags & MATCHFLG_INCLUDE
271 + ? XFLG_DEF_INCLUDE : 0;
273 + lp->tail = NULL; /* Switch any local rules to inherited. */
274 + if (strlcpy(dirbuf + dirbuf_offset, ex->pattern,
275 + MAXPATHLEN - dirbuf_offset) < MAXPATHLEN - dirbuf_offset)
276 + add_exclude_file(lp, dirbuf, flags);
278 + io_error |= IOERR_GENERAL;
280 + "cannot add local excludes in long-named directory %s\n",
281 + full_fname(dirbuf));
285 + return (void*)push;
288 +void pop_local_excludes(void *mem)
290 + struct mergelist_save_struct *pop = (struct mergelist_save_struct*)mem;
291 + struct exclude_list_struct *ap;
294 + for (i = mergelist_cnt; i-- > 0; ) {
295 + struct exclude_struct *ex = mergelist_parents[i];
296 + struct exclude_list_struct *lp = ex->u.mergelist;
299 + rprintf(FINFO, "[%s] popping %sexclude list\n",
300 + who_am_i(), lp->debug_type);
303 + clear_exclude_list(lp);
306 + mergelist_cnt = pop->count;
307 + for (i = 0, ap = pop->array; i < mergelist_cnt; i++) {
308 + memcpy(mergelist_parents[i]->u.mergelist, ap++,
309 + sizeof (struct exclude_list_struct));
316 static int check_one_exclude(char *name, struct exclude_struct *ex,
319 @@ -122,7 +336,7 @@ static int check_one_exclude(char *name,
320 /* If the pattern does not have any slashes AND it does not have
321 * a "**" (which could match a slash), then we just match the
322 * name portion of the path. */
323 - if (!ex->slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
324 + if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
325 if ((p = strrchr(name,'/')) != NULL)
328 @@ -148,9 +362,9 @@ static int check_one_exclude(char *name,
329 if (ex->match_flags & MATCHFLG_WILD) {
330 /* A non-anchored match with an infix slash and no "**"
331 * needs to match the last slash_cnt+1 name elements. */
332 - if (!match_start && ex->slash_cnt
333 + if (!match_start && ex->u.slash_cnt
334 && !(ex->match_flags & MATCHFLG_WILD2)) {
335 - int cnt = ex->slash_cnt + 1;
336 + int cnt = ex->u.slash_cnt + 1;
337 for (p = name + strlen(name) - 1; p >= name; p--) {
338 if (*p == '/' && !--cnt)
340 @@ -221,6 +435,13 @@ int check_exclude(struct exclude_list_st
341 struct exclude_struct *ent;
343 for (ent = listp->head; ent; ent = ent->next) {
344 + if (ent->match_flags & MATCHFLG_MERGE_FILE) {
345 + int rc = check_exclude(ent->u.mergelist, name,
351 if (check_one_exclude(name, ent, name_is_dir)) {
352 report_exclude_result(name, ent, name_is_dir,
354 @@ -253,11 +474,16 @@ static const char *get_exclude_tok(const
358 - /* Is this a '+' or '-' followed by a space (not whitespace)? */
359 + /* Is this a +/-/. followed by a space (not whitespace)? */
360 if (!(xflags & XFLG_WORDS_ONLY)
361 - && (*s == '-' || *s == '+') && s[1] == ' ') {
362 + && (*s == '-' || *s == '+' || *s == '.') && s[1] == ' ') {
364 mflags |= MATCHFLG_INCLUDE;
365 + else if (*s == '.') {
366 + mflags |= MATCHFLG_MERGE_FILE;
367 + if (xflags & XFLG_DEF_INCLUDE)
368 + mflags |= MATCHFLG_INCLUDE;
371 } else if (xflags & XFLG_DEF_INCLUDE)
372 mflags |= MATCHFLG_INCLUDE;
373 @@ -306,11 +532,54 @@ void add_exclude(struct exclude_list_str
377 + if (mflags & MATCHFLG_MERGE_FILE) {
378 + char name[MAXPATHLEN];
379 + if (pat_len >= sizeof name) {
381 + "merge filename too long: %s\n", cp);
384 + strlcpy(name, cp, pat_len+1);
385 + if (!(xflags & XFLG_PERDIR_MERGE)
386 + && (inherit_exclude_levels == -1
387 + || strchr(name, '/') != NULL)) {
389 + if (*name == '/') {
390 + if (sanitize_paths) {
391 + mem = alloc_sanitize_path(name,
397 + if (sanitize_paths) {
398 + dirbuf[dirbuf_offset] = '\0';
399 + sanitize_path(name, dirbuf);
401 + if (strlcpy(dirbuf + dirbuf_offset,
402 + name, MAXPATHLEN - dirbuf_offset)
403 + >= MAXPATHLEN - dirbuf_offset) {
405 + "merge filename too long: %s...\n",
411 + add_exclude_file(listp, cp,
412 + xflags | XFLG_FATAL_ERRORS);
419 make_exclude(listp, cp, pat_len, mflags);
422 - rprintf(FINFO, "[%s] add_exclude(%.*s, %s%sclude)\n",
423 + rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s%sclude)\n",
424 who_am_i(), (int)pat_len, cp, listp->debug_type,
425 + mflags & MATCHFLG_MERGE_FILE ? "FILE " : "",
426 mflags & MATCHFLG_INCLUDE ? "in" : "ex");
429 @@ -343,6 +612,11 @@ void add_exclude_file(struct exclude_lis
434 + rprintf(FINFO, "[%s] add_exclude_file(%s,%d)\n",
435 + who_am_i(), fname, xflags);
440 int ch, overflow = 0;
441 @@ -402,7 +676,11 @@ void send_exclude_list(int f)
442 if (ent->match_flags & MATCHFLG_INCLUDE) {
444 write_buf(f, "+ ", 2);
445 - } else if ((*p == '-' || *p == '+') && p[1] == ' ') {
446 + } else if (ent->match_flags & MATCHFLG_MERGE_FILE) {
447 + write_int(f, l + 2);
448 + write_buf(f, ". ", 2);
449 + } else if ((*p == '-' || *p == '+' || *p == '.')
452 write_buf(f, "- ", 2);
454 @@ -443,6 +721,7 @@ void add_cvs_excludes(void)
455 char fname[MAXPATHLEN];
458 + add_exclude(&exclude_list, ". .cvsignore", XFLG_PERDIR_MERGE);
459 add_exclude(&exclude_list, default_cvsignore,
460 XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
462 --- flist.c 29 May 2004 21:21:17 -0000 1.226
463 +++ flist.c 4 Jun 2004 07:07:33 -0000
464 @@ -39,8 +39,6 @@ extern int module_id;
465 extern int ignore_errors;
466 extern int numeric_ids;
468 -extern int cvs_exclude;
471 extern char curr_dir[MAXPATHLEN];
472 extern char *files_from;
473 @@ -58,6 +56,7 @@ extern int implied_dirs;
474 extern int copy_links;
475 extern int copy_unsafe_links;
476 extern int protocol_version;
477 +extern int inherit_exclude_levels;
478 extern int sanitize_paths;
480 extern int read_batch;
481 @@ -65,7 +64,6 @@ extern int write_batch;
483 extern struct exclude_list_struct exclude_list;
484 extern struct exclude_list_struct server_exclude_list;
485 -extern struct exclude_list_struct local_exclude_list;
489 @@ -210,8 +208,6 @@ int link_stat(const char *path, STRUCT_S
491 static int check_exclude_file(char *fname, int is_dir, int exclude_level)
495 #if 0 /* This currently never happens, so avoid a useless compare. */
496 if (exclude_level == NO_EXCLUDES)
498 @@ -233,10 +229,7 @@ static int check_exclude_file(char *fnam
499 if (exclude_level != ALL_EXCLUDES)
501 if (exclude_list.head
502 - && (rc = check_exclude(&exclude_list, fname, is_dir)) != 0)
504 - if (local_exclude_list.head
505 - && check_exclude(&local_exclude_list, fname, is_dir) < 0)
506 + && check_exclude(&exclude_list, fname, is_dir) < 0)
510 @@ -942,15 +935,7 @@ void send_file_name(int f, struct file_l
512 if (recursive && S_ISDIR(file->mode)
513 && !(file->flags & FLAG_MOUNT_POINT)) {
514 - struct exclude_list_struct last_list = local_exclude_list;
515 - local_exclude_list.head = local_exclude_list.tail = NULL;
516 send_directory(f, flist, f_name_to(file, fbuf));
518 - rprintf(FINFO, "[%s] popping %sexclude list\n",
519 - who_am_i(), local_exclude_list.debug_type);
521 - clear_exclude_list(&local_exclude_list);
522 - local_exclude_list = last_list;
526 @@ -961,6 +946,7 @@ static void send_directory(int f, struct
528 char fname[MAXPATHLEN];
530 + void *save_excludes;
534 @@ -984,19 +970,13 @@ static void send_directory(int f, struct
539 - if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset)
540 - < MAXPATHLEN - offset) {
541 - add_exclude_file(&local_exclude_list, fname,
542 - XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
544 - io_error |= IOERR_GENERAL;
546 - "cannot cvs-exclude in long-named directory %s\n",
547 - full_fname(fname));
549 + if (inherit_exclude_levels > 0) {
550 + pre_inherit_files(fname, offset);
551 + inherit_exclude_levels = 0;
554 + save_excludes = push_local_excludes(fname, offset);
556 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
557 char *dname = d_name(di);
558 if (dname[0] == '.' && (dname[1] == '\0'
559 @@ -1016,6 +996,8 @@ static void send_directory(int f, struct
560 rsyserr(FERROR, errno, "readdir(%s)", dir);
563 + pop_local_excludes(save_excludes);
568 --- options.c 27 May 2004 21:51:53 -0000 1.153
569 +++ options.c 4 Jun 2004 07:07:34 -0000
570 @@ -48,6 +48,7 @@ int preserve_gid = 0;
571 int preserve_times = 0;
574 +int inherit_exclude_levels = -9999;
576 int local_server = 0;
577 int ignore_times = 0;
578 @@ -306,7 +307,7 @@ void usage(enum logcode F)
580 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
581 OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
582 - OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
583 + OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_INHERIT, OPT_MODIFY_WINDOW,
584 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
585 OPT_REFUSED_BASE = 9000};
587 @@ -331,6 +332,7 @@ static struct poptOption long_options[]
588 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
589 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
590 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
591 + {"inherit", 0, POPT_ARG_STRING, 0, OPT_INHERIT, 0, 0 },
592 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
593 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
594 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
595 @@ -543,6 +545,31 @@ int parse_arguments(int *argc, const cha
596 XFLG_FATAL_ERRORS | XFLG_DEF_INCLUDE);
600 + arg = poptGetOptArg(pc);
602 + inherit_exclude_levels = atoi(arg);
603 + else if (*arg == '.') {
605 + inherit_exclude_levels = 0;
606 + else if (arg[1] == '.') {
607 + inherit_exclude_levels = 0;
610 + inherit_exclude_levels++;
612 + } while (strncmp(arg, "/..", 3) == 0);
614 + inherit_exclude_levels = -1;
617 + if (inherit_exclude_levels < 0) {
618 + snprintf(err_buf, sizeof err_buf,
619 + "Invalid argument given to --inherit.\n");
627 @@ -767,6 +794,9 @@ int parse_arguments(int *argc, const cha
631 + if (inherit_exclude_levels < 0)
632 + inherit_exclude_levels = -1;
637 @@ -866,6 +896,12 @@ void server_options(char **args,int *arg
641 + if (inherit_exclude_levels >= 0) {
642 + if (asprintf(&arg, "--inherit=%d", inherit_exclude_levels) < 0)
648 if (asprintf(&arg, "-B%u", block_size) < 0)
650 --- rsync.h 16 May 2004 07:28:24 -0000 1.204
651 +++ rsync.h 4 Jun 2004 07:07:34 -0000
653 #define XFLG_DEF_INCLUDE (1<<1)
654 #define XFLG_WORDS_ONLY (1<<2)
655 #define XFLG_WORD_SPLIT (1<<3)
656 +#define XFLG_PERDIR_MERGE (1<<4)
658 #define PERMS_REPORT (1<<0)
659 #define PERMS_SKIP_MTIME (1<<1)
660 @@ -496,11 +497,16 @@ struct map_struct {
661 #define MATCHFLG_INCLUDE (1<<4) /* this is an include, not an exclude */
662 #define MATCHFLG_DIRECTORY (1<<5) /* this matches only directories */
663 #define MATCHFLG_CLEAR_LIST (1<<6) /* this item is the "!" token */
664 +#define MATCHFLG_MERGE_FILE (1<<7) /* specifies a file to merge */
665 +#define MATCHFLG_CVSIGNORE (1<<8) /* parse this as a .cvsignore file */
666 struct exclude_struct {
667 struct exclude_struct *next;
669 unsigned int match_flags;
673 + struct exclude_list_struct *mergelist;
677 struct exclude_list_struct {
678 --- rsync.yo 21 May 2004 09:44:32 -0000 1.170
679 +++ rsync.yo 4 Jun 2004 07:07:35 -0000
680 @@ -331,6 +331,7 @@ verb(
681 --exclude-from=FILE exclude patterns listed in FILE
682 --include=PATTERN don't exclude files matching PATTERN
683 --include-from=FILE don't exclude patterns listed in FILE
684 + --inherit=DEPTH make per-dir merge files inherited
685 --files-from=FILE read FILE for list of source-file names
686 -0 --from0 all file lists are delimited by nulls
687 --version print version number
688 @@ -683,6 +684,28 @@ dit(bf(--include-from=FILE)) This specif
690 If em(FILE) is bf(-) the list will be read from standard input.
692 +dit(bf(--inherit=DEPTH)) Using this option allows you to specify that the
693 +contents of per-directory merge files is inherited by the subdirectories of
694 +the spot where the rules were read in. If a subdirectory has its own
695 +per-directory merge file, its contents are prefixed to the inherited rules,
696 +which gives them higher priority.
698 +The DEPTH value tells rsync how much deeper than the root directory of the
699 +transfer should be scanned for merge files. If you don't need any higher
700 +directories scanned, use "." (dot). If you want the parent directory
701 +scanned, specify ".." (dot dot) or "1" (i.e. one directory higher). You
702 +can continue to specify either more ".."s (separated by slashes) or simply
703 +supply the count of how many parent-directory levels should be scanned.
704 +The reason this is useful is that you may wish to transfer just a small
705 +portion of a larger tree of files, but to be sure to get all the
706 +appropriate exclude rules, you need to be sure that rsync reads in all the
707 +merge files from the top of the tree of related files.
709 +Note also that you can eliminate all the inherited rules for the current
710 +per-directory ruleset by putting the list-clearing token (!) in the file.
711 +This only clears the rules in the current per-directory sub-list for the
712 +current directory and its subdirectories.
714 dit(bf(--files-from=FILE)) Using this option allows you to specify the
715 exact list of files to transfer (as read from the specified FILE or "-"
716 for stdin). It also tweaks the default behavior of rsync to make
717 @@ -1038,6 +1061,11 @@ itemize(
718 then it is always considered an exclude pattern, even if specified as
719 part of an include option. The prefix is discarded before matching.
721 + it() if the pattern starts with ". " (a dot followed by a space) then it
722 + its pattern is taken to be a merge file that is read in to supplement the
723 + current rules. See the section on MERGING EXCLUDE FILES for more
726 it() if the pattern is a single exclamation mark ! then the current
727 include/exclude list is reset, removing all previously defined patterns.
729 @@ -1090,6 +1118,67 @@ itemize(
730 it would be excluded by the "*")
733 +manpagesection(MERGING EXCLUDE FILES)
735 +You can merge whole files into an exclude file using a rule that starts
736 +with a ". " (a dot followed by a space) and has a filename in place of the
737 +pattern. There are two types of merge rules, single-instance and
741 + it() If the filename has no slashes in it, it is a per-directory merge;
742 + rsync scans every directory that it traverses for the named file, merging
743 + its contents (when it exists) at the start of this per-directory
746 + it() If a filename has a slash in it, it is a single-instance merge; the
747 + named file's contents will be merged into the current exclude file,
748 + replacing the merge rule. Thus, you should use the name ./foo instead of
749 + foo if you don't want to scan for "foo" in all the subdirectories in the
750 + transferred tree of directories.
753 +Here's an example exclude file (which you'd specify via the normal
754 +--exclude-from option):
757 + . /home/user/.global_excludes
764 +This will merge the contents of the /home/user/.global_excludes file at the
765 +start of the list and also turns the ".excl" filename into a per-directory
766 +exclude file whose local contents will be merged into the list in place of
769 +Additionally, you can affect where the --cvs-exclude (-C) option's
770 +inclusion of a per-directory .cvsignore file gets placed into your rules by
771 +adding an explicit merge rule for ".cvsignore". For instance, specifying
775 + rsync -avC --exclude='. .cvsignore' --exclude-from=foo a/ b
778 +will merge all the per-directory .cvsignore rules at the start of your list
779 +rather than at the end. This allows their dir-specific rules to supersede
780 +your rules instead of being subservient to them. (The global rules taken
781 +from the $HOME/.cvsignore file and from $CVSIGNORE are not affected by
784 +Note also that the parsing of any merge-file named ".cvsignore" is always
785 +done in a CVS-compatible manner, even if -C wasn't specified (i.e. the
786 +rules are always exclude rules (even when specified by an include option);
787 +they are split on whitespace; and no special prefixes, list-clearing
788 +tokens, or comment characters are honored).
790 +See the --inherit option for how to make the rules read from a
791 +per-directory merge file inherited by all the subdirectories of the
792 +spot where the per-directory rule file was found.
794 manpagesection(BATCH MODE)
796 bf(Note:) Batch mode should be considered experimental in this version
797 --- testsuite/exclude.test 24 May 2004 00:16:07 -0000 1.8
798 +++ testsuite/exclude.test 4 Jun 2004 07:07:35 -0000
799 @@ -23,19 +23,47 @@ export HOME CVSIGNORE
800 makepath "$fromdir/foo/down/to/you"
801 makepath "$fromdir/bar/down/to/foo/too"
802 makepath "$fromdir/mid/for/foo/and/that/is/who"
803 +cat >"$fromdir/.excl" <<EOF
809 echo kept >"$fromdir/foo/file1"
810 echo removed >"$fromdir/foo/file2"
811 echo cvsout >"$fromdir/foo/file2.old"
812 +cat >"$fromdir/foo/.excl" <<EOF
816 +cat >"$fromdir/bar/.excl" <<EOF
821 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
822 +cat >"$fromdir/bar/down/to/.excl2" <<EOF
825 echo keeper >"$fromdir/bar/down/to/foo/file1"
826 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
827 echo gone >"$fromdir/bar/down/to/foo/file3"
828 echo lost >"$fromdir/bar/down/to/foo/file4"
829 echo cvsout >"$fromdir/bar/down/to/foo/file4.junk"
830 echo smashed >"$fromdir/bar/down/to/foo/to"
831 +cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
834 +# This one should be ineffectual
835 +cat >"$fromdir/mid/.excl2" <<EOF
838 echo cvsout >"$fromdir/mid/one-in-one-out"
839 echo one-in-one-out >"$fromdir/mid/.cvsignore"
840 echo cvsin >"$fromdir/mid/one-for-all"
841 +cat >"$fromdir/mid/.excl" <<EOF
844 echo cvsin >"$fromdir/mid/for/one-in-one-out"
845 echo expunged >"$fromdir/mid/for/foo/extra"
846 echo retained >"$fromdir/mid/for/foo/keep"
847 @@ -100,5 +128,24 @@ $RSYNC -av --existing --include='*/' --e
848 checkit "$RSYNC -avvC --exclude-from=\"$excl\" \
849 --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
851 +# Modify the chk dir for our merge-exclude test and then tweak the dir times.
854 +rm "$chkdir"/foo/file1
855 +rm "$chkdir"/bar/.excl
856 +rm "$chkdir"/bar/down/to/.excl2
857 +rm "$chkdir"/bar/down/to/foo/.excl2
858 +rm "$chkdir"/mid/.excl
859 +cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
860 +cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
862 +$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
864 +# Now, test if rsync excludes the same files, this time with a merge-exclude
867 +checkit "$RSYNC -avv --exclude='. .excl' --exclude-from=\"$excl\" --inherit=. \
868 + --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
870 # The script would have aborted on error, so getting here means we've won.