Restore the old include behavior where a command-line include could
[rsync/rsync.git] / exclude.c
index 3e6c4df..81aaed9 100644 (file)
--- a/exclude.c
+++ b/exclude.c
 #include "rsync.h"
 
 extern int verbose;
+extern int eol_nulls;
+extern int list_only;
+extern int recurse;
 
-struct exclude_list_struct exclude_list;
-struct exclude_list_struct local_exclude_list;
-struct exclude_list_struct server_exclude_list;
+extern char curr_dir[];
+
+struct exclude_list_struct exclude_list = { 0, 0, "" };
+struct exclude_list_struct local_exclude_list = { 0, 0, "local-cvsignore " };
+struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
 char *exclude_path_prefix = NULL;
 
 /** Build an exclude structure given a exclude pattern */
@@ -98,15 +103,17 @@ void free_exclude_list(struct exclude_list_struct *listp)
 {
        struct exclude_struct *ent, *next;
 
-       if (verbose > 2)
-               rprintf(FINFO, "[%s] clearing exclude list\n", who_am_i());
+       if (verbose > 2) {
+               rprintf(FINFO, "[%s] clearing %sexclude list\n",
+                       who_am_i(), listp->debug_type);
+       }
 
        for (ent = listp->head; ent; ent = next) {
                next = ent->next;
                free_exclude(ent);
        }
 
-       memset(listp, 0, sizeof listp[0]);
+       listp->head = listp->tail = NULL;
 }
 
 static int check_one_exclude(char *name, struct exclude_struct *ex,
@@ -125,7 +132,6 @@ static int check_one_exclude(char *name, struct exclude_struct *ex,
        }
        else if ((ex->match_flags & MATCHFLG_ABS_PATH) && *name != '/') {
                static char full_name[MAXPATHLEN];
-               extern char curr_dir[];
                int plus = curr_dir[1] == '\0'? 1 : 0;
                pathjoin(full_name, sizeof full_name, curr_dir+plus, name);
                name = full_name;
@@ -199,7 +205,7 @@ static void report_exclude_result(char const *name,
         * case we add it back in here. */
 
        if (verbose >= 2) {
-               rprintf(FINFO, "[%s] %scluding %s %s because of %s %s%s\n",
+               rprintf(FINFO, "[%s] %scluding %s %s because of %spattern %s%s\n",
                        who_am_i(), ent->include ? "in" : "ex",
                        name_is_dir ? "directory" : "file", name, type,
                        ent->pattern, ent->directory ? "/" : "");
@@ -209,17 +215,18 @@ static void report_exclude_result(char const *name,
 
 /*
  * Return true if file NAME is defined to be excluded by the specified
- * exclude list.
+ * exclude list.  Returns -1 for an exclude, 1 for an include, and 0 if
+ * no match.
  */
-int check_exclude(struct exclude_list_struct *listp, char *name, int name_is_dir,
-                 const char *type)
+int check_exclude(struct exclude_list_struct *listp, char *name, int name_is_dir)
 {
        struct exclude_struct *ent;
 
        for (ent = listp->head; ent; ent = ent->next) {
                if (check_one_exclude(name, ent, name_is_dir)) {
-                       report_exclude_result(name, ent, name_is_dir, type);
-                       return !ent->include;
+                       report_exclude_result(name, ent, name_is_dir,
+                                             listp->debug_type);
+                       return ent->include ? 1 : -1;
                }
        }
 
@@ -296,8 +303,9 @@ void add_exclude(struct exclude_list_struct *listp, const char *pattern,
                        make_exclude(listp, cp, pat_len, incl);
 
                        if (verbose > 2) {
-                               rprintf(FINFO, "[%s] add_exclude(%s,%s)\n",
-                                       who_am_i(), cp,
+                               rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s)\n",
+                                       who_am_i(), pat_len, cp,
+                                       listp->debug_type,
                                        incl ? "include" : "exclude");
                        }
                }
@@ -311,7 +319,7 @@ void add_exclude_file(struct exclude_list_struct *listp, const char *fname,
        FILE *fp;
        char line[MAXPATHLEN];
        char *eob = line + MAXPATHLEN - 1;
-       extern int eol_nulls;
+       int word_split = xflags & XFLG_WORD_SPLIT;
 
        if (!fname || !*fname)
                return;
@@ -340,6 +348,8 @@ void add_exclude_file(struct exclude_list_struct *listp, const char *fname,
                                        continue;
                                break;
                        }
+                       if (word_split && isspace(ch))
+                               break;
                        if (eol_nulls? !ch : (ch == '\n' || ch == '\r'))
                                break;
                        if (s < eob)
@@ -359,7 +369,6 @@ void add_exclude_file(struct exclude_list_struct *listp, const char *fname,
 void send_exclude_list(int f)
 {
        struct exclude_struct *ent;
-       extern int list_only, recurse;
 
        /* This is a complete hack - blame Rusty.
         *