--- exclude.c 14 Apr 2004 23:33:40 -0000 1.67 +++ exclude.c 15 Apr 2004 21:02:10 -0000 @@ -27,8 +27,10 @@ #include "rsync.h" extern int verbose; +extern int protocol_version; struct exclude_list_struct exclude_list; +struct exclude_list_struct subdir_exclude_list; struct exclude_list_struct local_exclude_list; struct exclude_list_struct server_exclude_list; char *exclude_path_prefix = NULL; @@ -80,6 +82,8 @@ static void make_exclude(struct exclude_ for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++) ret->slash_cnt++; + ret->next = listp->extra; + if (!listp->tail) listp->head = listp->tail = ret; else { @@ -101,6 +105,13 @@ void free_exclude_list(struct exclude_li if (verbose > 2) rprintf(FINFO, "[%s] clearing exclude list\n", who_am_i()); + if (listp->extra) { + if (listp->tail) + listp->tail->next = NULL; + else + listp->head = NULL; + } + for (ent = listp->head; ent; ent = next) { next = ent->next; free_exclude(ent); @@ -109,6 +120,13 @@ void free_exclude_list(struct exclude_li memset(listp, 0, sizeof listp[0]); } +void clear_exclude_list(struct exclude_list_struct *listp, + struct exclude_struct *extra) +{ + listp->head = listp->extra = extra; + listp->tail = NULL; +} + static int check_one_exclude(char *name, struct exclude_struct *ex, int name_is_dir) { @@ -209,21 +227,24 @@ static void report_exclude_result(char c /* * Return true if file NAME is defined to be excluded by the specified - * exclude list. + * exclude list. Returns -1 for exclude, 0 for normal include, or 1 + * for super include. */ int check_exclude(struct exclude_list_struct *listp, char *name, int name_is_dir, - const char *type) + const char *type, int current_exclusion) { struct exclude_struct *ent; for (ent = listp->head; ent; ent = ent->next) { + if (current_exclusion < 0 && ent->include < 2) + continue; if (check_one_exclude(name, ent, name_is_dir)) { report_exclude_result(name, ent, name_is_dir, type); - return !ent->include; + return ent->include - 1; } } - return 0; + return current_exclusion; } @@ -249,10 +270,10 @@ static const char *get_exclude_tok(const p = (const char *)s; } - /* Is this a '+' or '-' followed by a space (not whitespace)? */ + /* Is this a +/-/& followed by a space (not whitespace)? */ if (!(xflags & XFLG_NO_PREFIXES) - && (*s == '-' || *s == '+') && s[1] == ' ') { - *incl_ptr = *s == '+'; + && (*s == '-' || *s == '+' || *s == '&') && s[1] == ' ') { + *incl_ptr = *s == '+' ? 1 : *s == '&' ? 2 : 0; s += 2; } else *incl_ptr = xflags & XFLG_DEF_INCLUDE; @@ -382,8 +403,12 @@ void send_exclude_list(int f) if (ent->include) { write_int(f, l + 2); - write_buf(f, "+ ", 2); - } else if ((*p == '-' || *p == '+') && p[1] == ' ') { + if (ent->include > 1 && protocol_version >= 28) + write_buf(f, "& ", 2); + else + write_buf(f, "+ ", 2); + } else if ((*p == '-' || *p == '+' || *p == '&') + && p[1] == ' ') { write_int(f, l + 2); write_buf(f, "- ", 2); } else --- flist.c 14 Apr 2004 23:33:34 -0000 1.213 +++ flist.c 15 Apr 2004 21:02:10 -0000 @@ -40,6 +40,7 @@ extern int ignore_errors; extern int numeric_ids; extern int cvs_exclude; +extern const char *subdir_exclude_filename; extern int recurse; extern char curr_dir[MAXPATHLEN]; @@ -66,6 +67,7 @@ extern int write_batch; extern struct exclude_list_struct exclude_list; extern struct exclude_list_struct server_exclude_list; +extern struct exclude_list_struct subdir_exclude_list; extern struct exclude_list_struct local_exclude_list; int io_error; @@ -211,6 +213,12 @@ int link_stat(const char *path, STRUCT_S */ static int check_exclude_file(char *fname, int is_dir, int exclude_level) { + static struct exclude_list_struct *elist[] = { + &exclude_list, &subdir_exclude_list, &local_exclude_list, NULL }; + static char *edesc[] = { + "pattern", "subdir-exclude", "local-ignore" }; + int i, rc; + #if 0 /* This currently never happens, so avoid a useless compare. */ if (exclude_level == NO_EXCLUDES) return 0; @@ -228,18 +236,18 @@ static int check_exclude_file(char *fnam } if (server_exclude_list.head && check_exclude(&server_exclude_list, fname, is_dir, - "server pattern")) + "server pattern", 0) < 0) return 1; if (exclude_level != ALL_EXCLUDES) return 0; - if (exclude_list.head - && check_exclude(&exclude_list, fname, is_dir, "pattern")) - return 1; - if (local_exclude_list.head - && check_exclude(&local_exclude_list, fname, is_dir, - "local-cvsignore")) - return 1; - return 0; + for (i = 0, rc = 0; elist[i]; i++) { + if (!elist[i]->head) + continue; + rc = check_exclude(elist[i], fname, is_dir, edesc[i], rc); + if (rc > 0) + return 0; + } + return rc < 0; } /* used by the one_file_system code */ @@ -947,8 +955,12 @@ void send_file_name(int f, struct file_l if (recursive && S_ISDIR(file->mode) && !(file->flags & FLAG_MOUNT_POINT)) { struct exclude_list_struct last_list = local_exclude_list; - memset(&local_exclude_list, 0, sizeof local_exclude_list); + struct exclude_list_struct sub_list = subdir_exclude_list; + clear_exclude_list(&local_exclude_list, NULL); + clear_exclude_list(&subdir_exclude_list, sub_list.head); send_directory(f, flist, f_name_to(file, fbuf)); + free_exclude_list(&subdir_exclude_list); + subdir_exclude_list = sub_list; free_exclude_list(&local_exclude_list); local_exclude_list = last_list; } @@ -994,6 +1006,18 @@ static void send_directory(int f, struct io_error |= IOERR_GENERAL; rprintf(FINFO, "cannot cvs-exclude in long-named directory %s\n", + full_fname(fname)); + } + } + + if (subdir_exclude_filename) { + if (strlcpy(p, subdir_exclude_filename, MAXPATHLEN - offset) + < MAXPATHLEN - offset) + add_exclude_file(&subdir_exclude_list, fname, 0); + else { + io_error |= IOERR_GENERAL; + rprintf(FINFO, + "cannot subdir-exclude in long-named directory %s\n", full_fname(fname)); } } --- options.c 14 Apr 2004 23:33:34 -0000 1.146 +++ options.c 15 Apr 2004 21:02:10 -0000 @@ -70,6 +70,7 @@ int am_server = 0; int am_sender = 0; int am_generator = 0; char *files_from = NULL; +char *subdir_exclude_filename = NULL; int filesfrom_fd = -1; char *remote_filesfrom_file = NULL; int eol_nulls = 0; @@ -273,6 +274,7 @@ void usage(enum logcode F) rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n"); rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n"); + rprintf(F," --subdir-exclude=FILE look in each subdir for exclude file FILE\n"); rprintf(F," --files-from=FILE read FILE for list of source-file names\n"); rprintf(F," -0 --from0 all *-from file lists are delimited by nulls\n"); rprintf(F," --version print version number\n"); @@ -335,6 +337,7 @@ static struct poptOption long_options[] {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 }, {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 }, {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 }, + {"subdir-exclude", 0, POPT_ARG_STRING, &subdir_exclude_filename, 0, 0, 0 }, {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 }, {"links", 'l', POPT_ARG_NONE, &preserve_links, 0, 0, 0 }, {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 }, --- proto.h 14 Apr 2004 23:33:30 -0000 1.188 +++ proto.h 15 Apr 2004 21:02:11 -0000 @@ -52,8 +52,10 @@ int daemon_main(void); void setup_protocol(int f_out,int f_in); int claim_connection(char *fname,int max_connections); void free_exclude_list(struct exclude_list_struct *listp); +void clear_exclude_list(struct exclude_list_struct *listp, + struct exclude_struct *extra); int check_exclude(struct exclude_list_struct *listp, char *name, int name_is_dir, - const char *type); + const char *type, int current_exclusion); void add_exclude(struct exclude_list_struct *listp, const char *pattern, int xflags); void add_exclude_file(struct exclude_list_struct *listp, const char *fname, --- rsync.h 14 Apr 2004 23:33:37 -0000 1.196 +++ rsync.h 15 Apr 2004 21:02:11 -0000 @@ -502,6 +502,7 @@ struct exclude_struct { struct exclude_list_struct { struct exclude_struct *head; struct exclude_struct *tail; + struct exclude_struct *extra; }; struct stats { --- rsync.yo 15 Apr 2004 18:32:24 -0000 1.157 +++ rsync.yo 15 Apr 2004 21:02:11 -0000 @@ -331,6 +331,7 @@ verb( --exclude-from=FILE exclude patterns listed in FILE --include=PATTERN don't exclude files matching PATTERN --include-from=FILE don't exclude patterns listed in FILE + --subdir-exclude=FILE look in each subdir for exclude file FILE --files-from=FILE read FILE for list of source-file names -0 --from0 all file lists are delimited by nulls --version print version number @@ -651,6 +652,15 @@ dit(bf(--exclude=PATTERN)) This option a certain files from the list of files to be transferred. This is most useful in combination with a recursive transfer. +dit(bf(--subdir-exclude=FILE)) In any given directory, patterns listed +in FILE (one per line) are excluded from the file lists associated with +that directory and all of its subdirectories. Rules specified in a subdir +take precedence over rules evaluated in a parent dir (think of each set +of rules being prefixed to the prior rules). If you don't want to +inherit the parent-dir rules, start the FILE with a single exclamation +mark ! to clear them out. You may prefix names with an explicit exclude, +include, or super-include prefix (see below). + You may use as many --exclude options on the command line as you like to build up the list of files to exclude. @@ -996,6 +1006,12 @@ itemize( it() if the pattern starts with "- " (a minus followed by a space) then it is always considered an exclude pattern, even if specified as part of an include option. The prefix is discarded before matching. + + it() if the pattern starts with "& " (an ampersand followed by a space) + then it is considered a super-include pattern. A super-include will + override an exclude from another exclude list (a normal include only + overrides an exclusion from further down in the same list). The + prefix is discarded before matching. it() if the pattern is a single exclamation mark ! then the current include/exclude list is reset, removing all previously defined patterns. --- util.c 14 Apr 2004 23:33:34 -0000 1.135 +++ util.c 15 Apr 2004 21:02:12 -0000 @@ -477,7 +477,7 @@ static int exclude_server_path(char *arg for (s = arg; (s = strchr(s, '/')) != NULL; ) { *s = '\0'; if (check_exclude(&server_exclude_list, arg, 1, - "server pattern")) { + "server pattern", 0) < 0) { /* We must leave arg truncated! */ return 1; }