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 --- orig/exclude.c 2004-05-22 19:30:03
34 +++ exclude.c 2004-08-03 17:06:22
39 +extern int am_sender;
44 +extern int module_id;
45 +extern int delete_mode;
46 +extern int delete_excluded;
47 +extern int inherit_exclude_levels;
48 +extern int sanitize_paths;
50 extern char curr_dir[];
51 +extern unsigned int curr_dir_len;
53 struct exclude_list_struct exclude_list = { 0, 0, "" };
54 -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " };
55 struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
56 char *exclude_path_prefix = NULL;
57 +struct exclude_struct **mergelist_parents;
58 +int mergelist_cnt = 0;
59 +int mergelist_size = 0;
61 +struct mergelist_save_struct {
62 + struct exclude_list_struct *array;
66 +static char dirbuf[MAXPATHLEN];
67 +static unsigned int dirbuf_offset = 0;
69 +/* Each exclude_list_struct describes a singly-linked list by keeping track
70 + * of both the head and tail pointers. The list is slightly unusual in that
71 + * a parent-dir's content can be appended to the end of the local list in a
72 + * special way: the last item in the local list has its "next" pointer set
73 + * to point to the inherited list, but the local list's tail pointer points
74 + * at the end of the local list. Thus, if the local list is empty, the head
75 + * will be pointing at the inherited content but the tail will be NULL. To
76 + * help you visualize this, here are the possible list arrangements:
78 + * Completely Empty Local Content Only
79 + * ================================== ====================================
80 + * head -> NULL head -> Local1 -> Local2 -> NULL
81 + * tail -> NULL tail -------------^
83 + * Inherited Content Only Both Local and Inherited Content
84 + * ================================== ====================================
85 + * head -> Parent1 -> Parent2 -> NULL head -> L1 -> L2 -> P1 -> P2 -> NULL
86 + * tail -> NULL tail ---------^
88 + * This means that anyone wanting to traverse the whole list to USE it just
89 + * needs to start at the head and use the "next" pointers until it goes
90 + * NULL. To add new local content, we insert the item after the tail item
91 + * and update the tail (obviously, if "tail" was NULL, we insert it at the
92 + * head). To clear the local list, WE MUST NOT FREE THE INHERITED CONTENT
93 + * because it is shared between the current list and our parent list(s).
94 + * The easiest way to handle this is to simply truncate the list after the
95 + * tail item and then free the local list from the head. When inheriting
96 + * the list for a new local dir, we just save off the exclude_list_struct
97 + * values (so we can pop back to them later) and set the tail to NULL.
100 /** Build an exclude structure given an exclude pattern. */
101 static void make_exclude(struct exclude_list_struct *listp, const char *pat,
102 @@ -46,6 +95,24 @@ static void make_exclude(struct exclude_
106 + if (mflags & MATCHFLG_MERGE_FILE) {
108 + /* If the local include file was already mentioned, don't
110 + for (i = 0; i < mergelist_cnt; i++) {
111 + struct exclude_struct *ex = mergelist_parents[i];
112 + if (strlen(ex->pattern) == pat_len
113 + && memcmp(ex->pattern, pat, pat_len) == 0)
116 + if ((pat_len == 10 || (pat_len > 10 && pat[pat_len-11] == '/'))
117 + && strncmp(pat+pat_len-10, ".cvsignore", 10) == 0) {
118 + mflags |= MATCHFLG_CVSIGNORE;
119 + mflags &= ~MATCHFLG_INCLUDE;
121 + mflags &= ~MATCHFLG_CVSIGNORE;
124 ret = new(struct exclude_struct);
126 out_of_memory("make_exclude");
127 @@ -81,14 +148,36 @@ static void make_exclude(struct exclude_
128 mflags |= MATCHFLG_DIRECTORY;
131 - for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
133 + if (mflags & MATCHFLG_MERGE_FILE) {
134 + struct exclude_list_struct *lp
135 + = new_array(struct exclude_list_struct, 1);
137 + out_of_memory("make_exclude");
138 + lp->head = lp->tail = NULL;
139 + if (asprintf(&lp->debug_type, "per-dir %s ", ret->pattern) < 0)
140 + out_of_memory("make_exclude");
141 + ret->u.mergelist = lp;
142 + if (mergelist_cnt == mergelist_size) {
143 + mergelist_size += 5;
144 + mergelist_parents = realloc_array(mergelist_parents,
145 + struct exclude_struct *,
147 + if (!mergelist_parents)
148 + out_of_memory("make_exclude");
150 + mergelist_parents[mergelist_cnt++] = ret;
152 + for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
153 + ret->u.slash_cnt++;
156 ret->match_flags = mflags;
159 + if (!listp->tail) {
160 + ret->next = listp->head;
161 listp->head = listp->tail = ret;
164 + ret->next = listp->tail->next;
165 listp->tail->next = ret;
168 @@ -96,22 +185,156 @@ static void make_exclude(struct exclude_
170 static void free_exclude(struct exclude_struct *ex)
172 + if (ex->match_flags & MATCHFLG_MERGE_FILE) {
173 + free(ex->u.mergelist->debug_type);
174 + free(ex->u.mergelist);
180 -void clear_exclude_list(struct exclude_list_struct *listp)
181 +static void clear_exclude_list(struct exclude_list_struct *listp)
183 - struct exclude_struct *ent, *next;
185 - for (ent = listp->head; ent; ent = next) {
189 + struct exclude_struct *ent, *next;
190 + /* Truncate any inherited items from the local list. */
191 + listp->tail->next = NULL;
192 + /* Now free everything that is left. */
193 + for (ent = listp->head; ent; ent = next) {
199 listp->head = listp->tail = NULL;
202 +void pre_inherit_files(char *fname, unsigned int len)
204 + char path[MAXPATHLEN], save[MAXPATHLEN];
205 + unsigned int limit;
208 + if (sanitize_paths)
209 + limit = strlen(lp_path(module_id));
214 + strcpy(path, fname); /* safe */
215 + else if (len == 2 && *fname == '.' && fname[1] == '/')
216 + len = strlcpy(path, curr_dir, sizeof path);
218 + len = pathjoin(path, sizeof path, curr_dir, fname);
220 + if (len >= MAXPATHLEN || len == 0)
223 + for (i = inherit_exclude_levels, len--; i && len > limit; ) {
224 + if (path[--len] == '/')
227 + for (len++; i < inherit_exclude_levels; i++) {
228 + char *s = path + len;
230 + push_local_excludes(path, len);
232 + if (!(s = strchr(s, '/')))
233 + break; /* Impossible ... */
234 + len = s - path + 1;
238 +void *push_local_excludes(char *fname, unsigned int offset)
240 + struct mergelist_save_struct *push;
241 + struct exclude_list_struct *ap;
244 + /* Make it easy to construct the full path for a merge-file that was
245 + * specified with a relative path by saving off the current dir. */
246 + memcpy(dirbuf, fname, offset);
247 + dirbuf_offset = offset;
248 + if (dirbuf_offset == 2 && *dirbuf == '.')
251 + if (!(push = new_array(struct mergelist_save_struct, 1)))
252 + out_of_memory("push_local_excludes");
254 + push->count = mergelist_cnt;
255 + push->array = new_array(struct exclude_list_struct, mergelist_cnt);
257 + out_of_memory("push_local_excludes");
259 + for (i = 0, ap = push->array; i < mergelist_cnt; i++) {
260 + memcpy(ap++, mergelist_parents[i]->u.mergelist,
261 + sizeof (struct exclude_list_struct));
264 + /* Note: add_exclude_file() might increase mergelist_cnt, so keep
265 + * this loop separate from the above loop. */
266 + for (i = 0; i < mergelist_cnt; i++) {
267 + struct exclude_struct *ex = mergelist_parents[i];
268 + struct exclude_list_struct *lp = ex->u.mergelist;
272 + rprintf(FINFO, "[%s] pushing %sexclude list\n",
273 + who_am_i(), lp->debug_type);
276 + if (ex->match_flags & MATCHFLG_CVSIGNORE) {
277 + lp->head = NULL; /* CVS doesn't inherit rules. */
278 + flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY;
280 + flags = ex->match_flags & MATCHFLG_INCLUDE
281 + ? XFLG_DEF_INCLUDE : 0;
282 + if (inherit_exclude_levels < 0)
285 + lp->tail = NULL; /* Switch any local rules to inherited. */
286 + if (strlcpy(dirbuf + dirbuf_offset, ex->pattern,
287 + MAXPATHLEN - dirbuf_offset) < MAXPATHLEN - dirbuf_offset)
288 + add_exclude_file(lp, dirbuf, flags);
290 + io_error |= IOERR_GENERAL;
292 + "cannot add local excludes in long-named directory %s\n",
293 + full_fname(dirbuf));
297 + return (void*)push;
300 +void pop_local_excludes(void *mem)
302 + struct mergelist_save_struct *pop = (struct mergelist_save_struct*)mem;
303 + struct exclude_list_struct *ap;
306 + for (i = mergelist_cnt; i-- > 0; ) {
307 + struct exclude_struct *ex = mergelist_parents[i];
308 + struct exclude_list_struct *lp = ex->u.mergelist;
311 + rprintf(FINFO, "[%s] popping %sexclude list\n",
312 + who_am_i(), lp->debug_type);
315 + clear_exclude_list(lp);
318 + mergelist_cnt = pop->count;
319 + for (i = 0, ap = pop->array; i < mergelist_cnt; i++) {
320 + memcpy(mergelist_parents[i]->u.mergelist, ap++,
321 + sizeof (struct exclude_list_struct));
328 static int check_one_exclude(char *name, struct exclude_struct *ex,
331 @@ -122,7 +345,7 @@ static int check_one_exclude(char *name,
332 /* If the pattern does not have any slashes AND it does not have
333 * a "**" (which could match a slash), then we just match the
334 * name portion of the path. */
335 - if (!ex->slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
336 + if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
337 if ((p = strrchr(name,'/')) != NULL)
340 @@ -133,7 +356,8 @@ static int check_one_exclude(char *name,
344 - if (!name[0]) return 0;
348 if (ex->match_flags & MATCHFLG_DIRECTORY && !name_is_dir)
350 @@ -148,9 +372,9 @@ static int check_one_exclude(char *name,
351 if (ex->match_flags & MATCHFLG_WILD) {
352 /* A non-anchored match with an infix slash and no "**"
353 * needs to match the last slash_cnt+1 name elements. */
354 - if (!match_start && ex->slash_cnt
355 + if (!match_start && ex->u.slash_cnt
356 && !(ex->match_flags & MATCHFLG_WILD2)) {
357 - int cnt = ex->slash_cnt + 1;
358 + int cnt = ex->u.slash_cnt + 1;
359 for (p = name + strlen(name) - 1; p >= name; p--) {
360 if (*p == '/' && !--cnt)
362 @@ -221,6 +445,13 @@ int check_exclude(struct exclude_list_st
363 struct exclude_struct *ent;
365 for (ent = listp->head; ent; ent = ent->next) {
366 + if (ent->match_flags & MATCHFLG_MERGE_FILE) {
367 + int rc = check_exclude(ent->u.mergelist, name,
373 if (check_one_exclude(name, ent, name_is_dir)) {
374 report_exclude_result(name, ent, name_is_dir,
376 @@ -253,11 +484,16 @@ static const char *get_exclude_tok(const
380 - /* Is this a '+' or '-' followed by a space (not whitespace)? */
381 + /* Is this a +/-/. followed by a space (not whitespace)? */
382 if (!(xflags & XFLG_WORDS_ONLY)
383 - && (*s == '-' || *s == '+') && s[1] == ' ') {
384 + && (*s == '-' || *s == '+' || *s == '.') && s[1] == ' ') {
386 mflags |= MATCHFLG_INCLUDE;
387 + else if (*s == '.') {
388 + mflags |= MATCHFLG_MERGE_FILE;
389 + if (xflags & XFLG_DEF_INCLUDE)
390 + mflags |= MATCHFLG_INCLUDE;
393 } else if (xflags & XFLG_DEF_INCLUDE)
394 mflags |= MATCHFLG_INCLUDE;
395 @@ -292,6 +528,7 @@ void add_exclude(struct exclude_list_str
399 + /* Remember that the returned string is NOT '\0' terminated! */
400 cp = get_exclude_tok(cp + pat_len, &pat_len, &mflags, xflags);
403 @@ -306,11 +543,57 @@ void add_exclude(struct exclude_list_str
407 + if (mflags & MATCHFLG_MERGE_FILE) {
408 + char name[MAXPATHLEN];
409 + if (pat_len >= sizeof name) {
411 + "merge filename too long: %s\n", cp);
414 + /* We need a null-terminated version of the filename. */
415 + strlcpy(name, cp, pat_len+1);
416 + if (!(xflags & XFLG_PERDIR_MERGE)
417 + && (inherit_exclude_levels == -1
418 + || strchr(name, '/') != NULL)) {
420 + if (*name == '/') {
421 + if (sanitize_paths) {
422 + mem = alloc_sanitize_path(name,
428 + if (sanitize_paths) {
429 + dirbuf[dirbuf_offset] = '\0';
430 + sanitize_path(name, dirbuf);
432 + if (!dirbuf_offset)
434 + else if (strlcpy(dirbuf + dirbuf_offset,
435 + name, MAXPATHLEN - dirbuf_offset)
436 + >= MAXPATHLEN - dirbuf_offset) {
438 + "merge filename too long: %s...\n",
444 + add_exclude_file(listp, cp,
445 + xflags | XFLG_FATAL_ERRORS);
452 make_exclude(listp, cp, pat_len, mflags);
455 - rprintf(FINFO, "[%s] add_exclude(%.*s, %s%sclude)\n",
456 + rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s%sclude)\n",
457 who_am_i(), (int)pat_len, cp, listp->debug_type,
458 + mflags & MATCHFLG_MERGE_FILE ? "FILE " : "",
459 mflags & MATCHFLG_INCLUDE ? "in" : "ex");
462 @@ -343,6 +626,11 @@ void add_exclude_file(struct exclude_lis
467 + rprintf(FINFO, "[%s] add_exclude_file(%s,%d)\n",
468 + who_am_i(), fname, xflags);
473 int ch, overflow = 0;
474 @@ -402,7 +690,11 @@ void send_exclude_list(int f)
475 if (ent->match_flags & MATCHFLG_INCLUDE) {
477 write_buf(f, "+ ", 2);
478 - } else if ((*p == '-' || *p == '+') && p[1] == ' ') {
479 + } else if (ent->match_flags & MATCHFLG_MERGE_FILE) {
480 + write_int(f, l + 2);
481 + write_buf(f, ". ", 2);
482 + } else if ((*p == '-' || *p == '+' || *p == '.')
485 write_buf(f, "- ", 2);
487 @@ -411,6 +703,13 @@ void send_exclude_list(int f)
492 + /* If we're the receiver and we don't need the excludes, dump them. */
493 + if (!am_sender && (!delete_mode || delete_excluded)) {
494 + clear_exclude_list(&exclude_list);
495 + inherit_exclude_levels = 0;
501 @@ -443,6 +742,7 @@ void add_cvs_excludes(void)
502 char fname[MAXPATHLEN];
505 + add_exclude(&exclude_list, ". .cvsignore", XFLG_PERDIR_MERGE);
506 add_exclude(&exclude_list, default_cvsignore,
507 XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
509 --- orig/flist.c 2004-07-17 15:20:05
510 +++ flist.c 2004-08-03 17:14:17
511 @@ -39,8 +39,6 @@ extern int module_id;
512 extern int ignore_errors;
513 extern int numeric_ids;
515 -extern int cvs_exclude;
518 extern char curr_dir[MAXPATHLEN];
519 extern char *files_from;
520 @@ -59,6 +57,7 @@ extern int implied_dirs;
521 extern int copy_links;
522 extern int copy_unsafe_links;
523 extern int protocol_version;
524 +extern int inherit_exclude_levels;
525 extern int sanitize_paths;
526 extern int delete_excluded;
527 extern int orig_umask;
528 @@ -66,7 +65,6 @@ extern int list_only;
530 extern struct exclude_list_struct exclude_list;
531 extern struct exclude_list_struct server_exclude_list;
532 -extern struct exclude_list_struct local_exclude_list;
536 @@ -221,8 +219,6 @@ int link_stat(const char *path, STRUCT_S
538 static int check_exclude_file(char *fname, int is_dir, int exclude_level)
542 #if 0 /* This currently never happens, so avoid a useless compare. */
543 if (exclude_level == NO_EXCLUDES)
545 @@ -244,10 +240,7 @@ static int check_exclude_file(char *fnam
546 if (exclude_level != ALL_EXCLUDES)
548 if (exclude_list.head
549 - && (rc = check_exclude(&exclude_list, fname, is_dir)) != 0)
551 - if (local_exclude_list.head
552 - && check_exclude(&local_exclude_list, fname, is_dir) < 0)
553 + && check_exclude(&exclude_list, fname, is_dir) < 0)
557 @@ -954,15 +947,7 @@ void send_file_name(int f, struct file_l
559 if (recursive && S_ISDIR(file->mode)
560 && !(file->flags & FLAG_MOUNT_POINT)) {
561 - struct exclude_list_struct last_list = local_exclude_list;
562 - local_exclude_list.head = local_exclude_list.tail = NULL;
563 send_directory(f, flist, f_name_to(file, fbuf));
565 - rprintf(FINFO, "[%s] popping %sexclude list\n",
566 - who_am_i(), local_exclude_list.debug_type);
568 - clear_exclude_list(&local_exclude_list);
569 - local_exclude_list = last_list;
573 @@ -973,6 +958,7 @@ static void send_directory(int f, struct
575 char fname[MAXPATHLEN];
577 + void *save_excludes;
581 @@ -996,18 +982,13 @@ static void send_directory(int f, struct
586 - if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset)
587 - < MAXPATHLEN - offset) {
588 - add_exclude_file(&local_exclude_list, fname,
589 - XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
591 - io_error |= IOERR_GENERAL;
593 - "cannot cvs-exclude in long-named directory %s\n",
594 - full_fname(fname));
597 + if (inherit_exclude_levels > 0) {
598 + pre_inherit_files(fname, offset);
599 + inherit_exclude_levels = 0;
600 + } else if (inherit_exclude_levels < -1)
601 + inherit_exclude_levels = -1;
603 + save_excludes = push_local_excludes(fname, offset);
605 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
606 char *dname = d_name(di);
607 @@ -1028,6 +1009,8 @@ static void send_directory(int f, struct
608 rsyserr(FERROR, errno, "readdir(%s)", dir);
611 + pop_local_excludes(save_excludes);
616 --- orig/options.c 2004-08-03 15:41:32
617 +++ options.c 2004-08-04 08:36:48
618 @@ -51,6 +51,7 @@ int preserve_gid = 0;
619 int preserve_times = 0;
622 +int inherit_exclude_levels = -9999;
624 int local_server = 0;
625 int ignore_times = 0;
626 @@ -287,6 +288,7 @@ void usage(enum logcode F)
627 rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n");
628 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
629 rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n");
630 + rprintf(F," --inherit=DEPTH inherit contents of per-dir merge files\n");
631 rprintf(F," --files-from=FILE read FILE for list of source-file names\n");
632 rprintf(F," -0, --from0 all *-from file lists are delimited by nulls\n");
633 rprintf(F," --version print version number\n");
634 @@ -319,7 +321,7 @@ void usage(enum logcode F)
636 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
637 OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
638 - OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
639 + OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_INHERIT, OPT_MODIFY_WINDOW,
640 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
641 OPT_REFUSED_BASE = 9000};
643 @@ -344,6 +346,7 @@ static struct poptOption long_options[]
644 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
645 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
646 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
647 + {"inherit", 0, POPT_ARG_STRING, 0, OPT_INHERIT, 0, 0 },
648 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
649 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
650 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
651 @@ -566,6 +569,31 @@ int parse_arguments(int *argc, const cha
652 XFLG_FATAL_ERRORS | XFLG_DEF_INCLUDE);
656 + arg = poptGetOptArg(pc);
658 + inherit_exclude_levels = atoi(arg);
659 + else if (*arg == '.') {
661 + inherit_exclude_levels = 0;
662 + else if (*arg == '.') {
663 + inherit_exclude_levels = 1;
665 + while (strncmp(arg, "/..", 3) == 0) {
666 + inherit_exclude_levels++;
670 + inherit_exclude_levels = -1;
673 + if (inherit_exclude_levels < 0) {
674 + snprintf(err_buf, sizeof err_buf,
675 + "Invalid argument given to --inherit.\n");
683 @@ -969,6 +997,12 @@ void server_options(char **args,int *arg
687 + if (inherit_exclude_levels >= 0) {
688 + if (asprintf(&arg, "--inherit=%d", inherit_exclude_levels) < 0)
694 if (asprintf(&arg, "-B%u", block_size) < 0)
696 --- orig/rsync.h 2004-08-03 15:41:32
697 +++ rsync.h 2004-07-03 20:21:27
699 #define XFLG_DEF_INCLUDE (1<<1)
700 #define XFLG_WORDS_ONLY (1<<2)
701 #define XFLG_WORD_SPLIT (1<<3)
702 +#define XFLG_PERDIR_MERGE (1<<4)
704 #define PERMS_REPORT (1<<0)
705 #define PERMS_SKIP_MTIME (1<<1)
706 @@ -499,11 +500,16 @@ struct map_struct {
707 #define MATCHFLG_INCLUDE (1<<4) /* this is an include, not an exclude */
708 #define MATCHFLG_DIRECTORY (1<<5) /* this matches only directories */
709 #define MATCHFLG_CLEAR_LIST (1<<6) /* this item is the "!" token */
710 +#define MATCHFLG_MERGE_FILE (1<<7) /* specifies a file to merge */
711 +#define MATCHFLG_CVSIGNORE (1<<8) /* parse this as a .cvsignore file */
712 struct exclude_struct {
713 struct exclude_struct *next;
715 unsigned int match_flags;
719 + struct exclude_list_struct *mergelist;
723 struct exclude_list_struct {
724 --- orig/rsync.yo 2004-08-03 15:34:32
725 +++ rsync.yo 2004-08-04 08:36:18
726 @@ -334,6 +334,7 @@ verb(
727 --exclude-from=FILE exclude patterns listed in FILE
728 --include=PATTERN don't exclude files matching PATTERN
729 --include-from=FILE don't exclude patterns listed in FILE
730 + --inherit=DEPTH inherit contents of per-dir merge files
731 --files-from=FILE read FILE for list of source-file names
732 -0 --from0 all file lists are delimited by nulls
733 --version print version number
734 @@ -711,6 +712,28 @@ dit(bf(--include-from=FILE)) This specif
736 If em(FILE) is "-" the list will be read from standard input.
738 +dit(bf(--inherit=DEPTH)) Using this option allows you to specify that the
739 +contents of per-directory merge files is inherited by the subdirectories of
740 +the spot where the rules were read in. If a subdirectory has its own
741 +per-directory merge file, its contents are prefixed to the inherited rules,
742 +which gives the newest rules a higher priority than the inherited rules.
744 +The DEPTH value tells rsync how much deeper than the root directory of the
745 +transfer should be scanned for merge files. If you don't need any higher
746 +directories scanned, use "." (dot). If you want the parent directory
747 +scanned, specify ".." (dot dot) or "1" (i.e. one directory higher). You
748 +can continue to specify either more ".."s (separated by slashes) or simply
749 +supply the count of how many parent-directory levels should be scanned.
750 +The reason this is useful is that you may wish to transfer just a small
751 +portion of a larger tree of files, but to be sure to get all the
752 +appropriate exclude rules, you need to make rsync read in all the
753 +merge files from the top of the tree of related files.
755 +Note also that you can eliminate all the inherited rules for the current
756 +per-directory ruleset by putting the list-clearing token (!) in the file.
757 +This only clears the rules in the current per-directory sub-list for the
758 +current directory and its subdirectories.
760 dit(bf(--files-from=FILE)) Using this option allows you to specify the
761 exact list of files to transfer (as read from the specified FILE or "-"
762 for standard input). It also tweaks the default behavior of rsync to make
763 @@ -1086,6 +1109,11 @@ itemize(
764 then it is always considered an exclude pattern, even if specified as
765 part of an include option. The prefix is discarded before matching.
767 + it() if the pattern starts with ". " (a dot followed by a space) then its
768 + pattern is taken to be a merge file that is read in to supplement the
769 + current rules. See the section on MERGING EXCLUDE FILES for more
772 it() if the pattern is a single exclamation mark ! then the current
773 include/exclude list is reset, removing all previously defined patterns.
775 @@ -1138,6 +1166,67 @@ itemize(
776 it would be excluded by the "*")
779 +manpagesection(MERGING EXCLUDE FILES)
781 +You can merge whole files into an exclude file using a rule that starts
782 +with a ". " (a dot followed by a space) and has a filename in place of the
783 +pattern. There are two types of merge rules, single-instance and
787 + it() If the filename has no slashes in it, it is a per-directory merge;
788 + rsync scans every directory that it traverses for the named file, merging
789 + its contents (when it exists) at the start of this per-directory
792 + it() If a filename has a slash in it, it is a single-instance merge; the
793 + named file's contents will be merged into the current exclude file,
794 + replacing the merge rule. Thus, you should use the name ./foo instead of
795 + foo if you don't want to scan for "foo" in all the subdirectories in the
796 + transferred tree of directories.
799 +Here's an example exclude file (which you'd specify via the normal
800 +--exclude-from option):
803 + . /home/user/.global_excludes
810 +This will merge the contents of the /home/user/.global_excludes file at the
811 +start of the list and also turns the ".excl" filename into a per-directory
812 +exclude file whose local contents will be merged into the list in place of
815 +Additionally, you can affect where the --cvs-exclude (-C) option's
816 +inclusion of a per-directory .cvsignore file gets placed into your rules by
817 +adding an explicit merge rule for ".cvsignore". For instance, specifying
821 + rsync -avC --exclude='. .cvsignore' --exclude-from=foo a/ b
824 +will merge all the per-directory .cvsignore rules at the start of your list
825 +rather than at the end. This allows their dir-specific rules to supersede
826 +your rules instead of being subservient to them. (The global rules taken
827 +from the $HOME/.cvsignore file and from $CVSIGNORE are not affected by
830 +Note also that the parsing of any merge-file named ".cvsignore" is always
831 +done in a CVS-compatible manner, even if -C wasn't specified (i.e. the
832 +rules are always exclude rules (even when specified by an include option);
833 +they are split on whitespace; the contents is never inherited; and no
834 +prefixes, list-clearing tokens, or comment characters are honored).
836 +See the --inherit option for how to make the rules read from a
837 +per-directory merge file inherited by all the subdirectories of the
838 +spot where the per-directory rule file was found.
840 manpagesection(BATCH MODE)
842 bf(Note:) Batch mode should be considered experimental in this version
843 --- orig/testsuite/exclude.test 2004-05-29 21:25:45
844 +++ testsuite/exclude.test 2004-07-03 20:21:27
845 @@ -23,19 +23,47 @@ export HOME CVSIGNORE
846 makepath "$fromdir/foo/down/to/you"
847 makepath "$fromdir/bar/down/to/foo/too"
848 makepath "$fromdir/mid/for/foo/and/that/is/who"
849 +cat >"$fromdir/.excl" <<EOF
855 echo kept >"$fromdir/foo/file1"
856 echo removed >"$fromdir/foo/file2"
857 echo cvsout >"$fromdir/foo/file2.old"
858 +cat >"$fromdir/foo/.excl" <<EOF
862 +cat >"$fromdir/bar/.excl" <<EOF
867 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
868 +cat >"$fromdir/bar/down/to/.excl2" <<EOF
871 echo keeper >"$fromdir/bar/down/to/foo/file1"
872 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
873 echo gone >"$fromdir/bar/down/to/foo/file3"
874 echo lost >"$fromdir/bar/down/to/foo/file4"
875 echo cvsout >"$fromdir/bar/down/to/foo/file4.junk"
876 echo smashed >"$fromdir/bar/down/to/foo/to"
877 +cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
880 +# This one should be ineffectual
881 +cat >"$fromdir/mid/.excl2" <<EOF
884 echo cvsout >"$fromdir/mid/one-in-one-out"
885 echo one-in-one-out >"$fromdir/mid/.cvsignore"
886 echo cvsin >"$fromdir/mid/one-for-all"
887 +cat >"$fromdir/mid/.excl" <<EOF
890 echo cvsin >"$fromdir/mid/for/one-in-one-out"
891 echo expunged >"$fromdir/mid/for/foo/extra"
892 echo retained >"$fromdir/mid/for/foo/keep"
893 @@ -100,5 +128,24 @@ $RSYNC -av --existing --include='*/' --e
894 checkit "$RSYNC -avvC --exclude-from=\"$excl\" \
895 --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
897 +# Modify the chk dir for our merge-exclude test and then tweak the dir times.
900 +rm "$chkdir"/foo/file1
901 +rm "$chkdir"/bar/.excl
902 +rm "$chkdir"/bar/down/to/.excl2
903 +rm "$chkdir"/bar/down/to/foo/.excl2
904 +rm "$chkdir"/mid/.excl
905 +cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
906 +cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
908 +$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
910 +# Now, test if rsync excludes the same files, this time with a merge-exclude
913 +checkit "$RSYNC -avv --exclude='. .excl' --exclude-from=\"$excl\" --inherit=. \
914 + --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
916 # The script would have aborted on error, so getting here means we've won.