Fixed failing hunks.
[rsync/rsync-patches.git] / filter.diff
index 1ed3c98..b8100bc 100644 (file)
@@ -1,7 +1,13 @@
+After applying this patch and running configure, you MUST run this
+command before "make":
+
+    make proto
+
 This patch adds the ability to merge rules into your excludes/includes
 using a ". FILE" idiom.  If you specify a name without slashes, that
 filename will be looked for in every subdirectory that rsync visits,
-and its rules will affect the current directory and its subdirectories.
+and the rules found in that subdirectory's file will affect that dir
+and its subdirectories.
 
 For example:
 
@@ -23,9 +29,9 @@ for the current dir because its name contained a slash.
 
 ..wayne..
 
---- exclude.c  27 Apr 2004 01:36:06 -0000      1.75
-+++ exclude.c  8 May 2004 18:38:51 -0000
-@@ -30,32 +30,65 @@ extern int verbose;
+--- exclude.c  16 May 2004 23:54:12 -0000      1.80
++++ exclude.c  17 May 2004 16:16:23 -0000
+@@ -30,13 +30,54 @@ extern int verbose;
  extern int eol_nulls;
  extern int list_only;
  extern int recurse;
@@ -34,47 +40,65 @@ for the current dir because its name contained a slash.
  
  extern char curr_dir[];
  
--struct exclude_list_struct exclude_list = { 0, 0, "" };
+ struct exclude_list_struct exclude_list = { 0, 0, "" };
 -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " };
--struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
-+struct exclude_list_struct exclude_list = { 0, 0, 0, 0, "" };
-+struct exclude_list_struct server_exclude_list = { 0, 0, 0, 0, "server " };
+ struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
  char *exclude_path_prefix = NULL;
-+struct exclude_list_root {
-+    struct exclude_list_struct *head;
-+    int cnt;
-+} local_lists;
++int merge_list_cnt = 0;
++
++struct mergelist_save {
++    struct exclude_list_struct *array;
++    int count;
++};
 +
 +static char dirbuf[MAXPATHLEN];
 +static unsigned int dirbuf_offset = 0;
 +
-+static void clear_exclude_list(struct exclude_list_struct *listp,
-+                      struct exclude_struct *extra)
-+{
-+      listp->head = listp->extra = extra;
-+      listp->tail = NULL;
-+}
-+
- /** Build an exclude structure given a exclude pattern */
--static void make_exclude(struct exclude_list_struct *listp, const char *pattern,
--                       int pat_len, int include)
-+static void make_exclude(struct exclude_list_struct *listp, const char *pat,
-+                       unsigned int pat_len, int mflags)
- {
-       struct exclude_struct *ret;
++/* Each exclude_list_struct describes a singly-linked list by keeping track
++ * of both the head and tail pointers.  The list is slightly unusual in that
++ * a parent-dir's content can be appended to the end of the local list in a
++ * special way:  the last item in the local list has its "next" pointer set
++ * to point to the inherited list, but the local list's tail pointer points
++ * at the end of the local list.  Thus, if the local list is empty, the head
++ * will be pointing at the inherited content but the tail will be NULL.  To
++ * help you visualize this, here are the possible list arrangements:
++ *
++ * Completely Empty                     Local Content Only
++ * ==================================   ====================================
++ * head -> NULL                         head -> Local1 -> Local2 -> NULL
++ * tail -> NULL                         tail -------------^
++ *
++ * Inherited Content Only               Both Local and Inherited Content
++ * ==================================   ====================================
++ * head -> Parent1 -> Parent2 -> NULL   head -> L1 -> L2 -> P1 -> P2 -> NULL
++ * tail -> NULL                         tail ---------^
++ *
++ * This means that anyone wanting to traverse the whole list to USE it just
++ * needs to start at the head and use the "next" pointers until it goes
++ * NULL.  To add new local content, we insert the item after the tail item
++ * and update the tail (obviously, if "tail" was NULL, we insert it at the
++ * head).  To clear the local list, WE MUST NOT FREE THE INHERITED CONTENT
++ * because it is shared between the current list and our parent list(s).
++ * The easiest way to handle this is to simply truncate the list after the
++ * tail item and then free the local list from the head.  When inheriting
++ * the list for a new local dir, we just save off the exclude_list_struct
++ * values (so we can pop back to them later) and set the tail to NULL.
++ */
+ /** Build an exclude structure given an exclude pattern. */
+ static void make_exclude(struct exclude_list_struct *listp, const char *pat,
+@@ -46,6 +87,24 @@ static void make_exclude(struct exclude_
        const char *cp;
--      int ex_len;
-+      unsigned int ex_len;
-+
+       unsigned int ex_len;
 +      if (mflags & MATCHFLG_MERGE_FILE) {
 +              struct exclude_struct *ex;
 +              /* If the local include file was already mentioned, don't
 +               * add it again. */
 +              for (ex = listp->head; ex; ex = ex->next) {
-+                      if ((ex->match_flags & MATCHFLG_MERGE_FILE)
++                      if (ex->match_flags & MATCHFLG_MERGE_FILE
 +                          && strlen(ex->pattern) == pat_len
-+                          && strncmp(ex->pattern, pat, pat_len) == 0)
++                          && memcmp(ex->pattern, pat, pat_len) == 0)
 +                              return;
 +              }
 +              if ((pat_len == 10 || (pat_len > 10 && pat[pat_len-11] == '/'))
@@ -84,212 +108,206 @@ for the current dir because its name contained a slash.
 +              } else
 +                      mflags &= ~MATCHFLG_CVSIGNORE;
 +      }
++
        ret = new(struct exclude_struct);
        if (!ret)
                out_of_memory("make_exclude");
-       memset(ret, 0, sizeof ret[0]);
--      ret->include = include;
-       if (exclude_path_prefix)
--              ret->match_flags |= MATCHFLG_ABS_PATH;
--      if (exclude_path_prefix && *pattern == '/')
-+              mflags |= MATCHFLG_ABS_PATH;
-+      if (exclude_path_prefix && *pat == '/')
-               ex_len = strlen(exclude_path_prefix);
-       else
-               ex_len = 0;
-@@ -64,33 +97,52 @@ static void make_exclude(struct exclude_
-               out_of_memory("make_exclude");
-       if (ex_len)
-               memcpy(ret->pattern, exclude_path_prefix, ex_len);
--      strlcpy(ret->pattern + ex_len, pattern, pat_len + 1);
-+      strlcpy(ret->pattern + ex_len, pat, pat_len + 1);
-       pat_len += ex_len;
-       if (strpbrk(ret->pattern, "*[?")) {
--              ret->match_flags |= MATCHFLG_WILD;
-+              mflags |= MATCHFLG_WILD;
-               if ((cp = strstr(ret->pattern, "**")) != NULL) {
--                      ret->match_flags |= MATCHFLG_WILD2;
-+                      mflags |= MATCHFLG_WILD2;
-                       /* If the pattern starts with **, note that. */
-                       if (cp == ret->pattern)
--                              ret->match_flags |= MATCHFLG_WILD2_PREFIX;
-+                              mflags |= MATCHFLG_WILD2_PREFIX;
-               }
+@@ -81,14 +140,28 @@ static void make_exclude(struct exclude_
+               mflags |= MATCHFLG_DIRECTORY;
        }
  
-       if (pat_len > 1 && ret->pattern[pat_len-1] == '/') {
-               ret->pattern[pat_len-1] = 0;
--              ret->directory = 1;
-+              mflags |= MATCHFLG_DIRECTORY;
-       }
+-      for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
+-              ret->slash_cnt++;
++      if (mflags & MATCHFLG_MERGE_FILE) {
++              struct exclude_list_struct *lp
++                  = new_array(struct exclude_list_struct, 1);
++              if (!lp)
++                      out_of_memory("make_exclude");
++              lp->head = lp->tail = NULL;
++              if (asprintf(&lp->debug_type, "per-dir %s ", ret->pattern) < 0)
++                      out_of_memory("make_exclude");
++              ret->u.merge_list = lp;
++              merge_list_cnt++;
++      } else {
++              for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
++                      ret->u.slash_cnt++;
++      }
  
-       for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
-               ret->slash_cnt++;
+       ret->match_flags = mflags;
  
-+      ret->next = listp->extra;
-+
-       if (!listp->tail)
+-      if (!listp->tail)
++      if (!listp->tail) {
++              ret->next = listp->head;
                listp->head = listp->tail = ret;
-       else {
+-      else {
++      } else {
++              ret->next = listp->tail->next;
                listp->tail->next = ret;
                listp->tail = ret;
        }
-+
-+      if (mflags & MATCHFLG_MERGE_FILE) {
-+              struct exclude_list_struct *lp;
-+              int ndx = local_lists.cnt++;
-+              local_lists.head = realloc_array(local_lists.head,
-+                  struct exclude_list_struct, local_lists.cnt);
-+              if (!local_lists.head)
-+                      out_of_memory("make_exclude");
-+              lp = &local_lists.head[ndx];
-+              clear_exclude_list(lp, NULL);
-+              if (asprintf(&lp->debug_type, "per-dir %s ", ret->pattern) < 0)
-+                      out_of_memory("make_exclude");
-+              lp->parent = ret;
-+              ret->slash_cnt = ndx;
-+      }
-+
-+      ret->match_flags = mflags;
- }
+@@ -96,22 +169,128 @@ static void make_exclude(struct exclude_
  
  static void free_exclude(struct exclude_struct *ex)
-@@ -99,13 +151,15 @@ static void free_exclude(struct exclude_
+ {
++      if (ex->match_flags & MATCHFLG_MERGE_FILE) {
++              free(ex->u.merge_list->debug_type);
++              free(ex->u.merge_list);
++      }
+       free(ex->pattern);
        free(ex);
  }
  
--void free_exclude_list(struct exclude_list_struct *listp)
-+static void free_exclude_list(struct exclude_list_struct *listp)
+-void clear_exclude_list(struct exclude_list_struct *listp)
++static void clear_exclude_list(struct exclude_list_struct *listp)
  {
-       struct exclude_struct *ent, *next;
--      if (verbose > 2) {
--              rprintf(FINFO, "[%s] clearing %sexclude list\n",
--                      who_am_i(), listp->debug_type);
-+      if (listp->extra) {
-+              if (listp->tail)
-+                      listp->tail->next = NULL;
-+              else
-+                      listp->head = NULL;
+-      struct exclude_struct *ent, *next;
+-
+-      for (ent = listp->head; ent; ent = next) {
+-              next = ent->next;
+-              free_exclude(ent);
++      if (listp->tail) {
++              struct exclude_struct *ent, *next;
++              /* Truncate any inherited items from the local list. */
++              listp->tail->next = NULL;
++              for (ent = listp->head; ent; ent = next) {
++                      next = ent->next;
++                      free_exclude(ent);
++              }
        }
  
-       for (ent = listp->head; ent; ent = next) {
-@@ -113,7 +167,78 @@ void free_exclude_list(struct exclude_li
-               free_exclude(ent);
-       }
+       listp->head = listp->tail = NULL;
+ }
  
--      listp->head = listp->tail = NULL;
-+      clear_exclude_list(listp, NULL);
-+}
-+
-+void *push_local_excludes(char *fname, unsigned int offset)
++static struct exclude_list_struct *
++push_merge_files(struct exclude_struct *ent, struct exclude_list_struct *array)
 +{
-+      int i;
-+      struct exclude_list_root *push = new_array(struct exclude_list_root, 1);
-+
-+      if (!push)
-+              out_of_memory("push_local_excludes");
-+
-+      push->cnt = local_lists.cnt;
-+      push->head = new_array(struct exclude_list_struct, local_lists.cnt);
-+      if (!push->head)
-+              out_of_memory("push_local_excludes");
-+
-+      memcpy(push->head, local_lists.head,
-+          sizeof (struct exclude_list_struct) * local_lists.cnt);
-+
-+      /* Make it easy to construct the full path for a merge that has
-+       * a relative path by saving it off. */
-+      memcpy(dirbuf, fname, offset);
-+      dirbuf_offset = offset;
++      struct exclude_list_struct *lp;
 +
-+      for (i = 0; i < local_lists.cnt; i++) {
-+              struct exclude_list_struct *listp = &local_lists.head[i];
-+              struct exclude_struct *extra;
-+              char *file = listp->parent->pattern;
++      for (; ent; ent = ent->next) {
 +              int flags;
++              if (!(ent->match_flags & MATCHFLG_MERGE_FILE))
++                      continue;
++              lp = ent->u.merge_list;
 +
 +              if (verbose > 2) {
 +                      rprintf(FINFO, "[%s] pushing %sexclude list\n",
-+                              who_am_i(), listp->debug_type);
++                              who_am_i(), lp->debug_type);
 +              }
-+              if (listp->parent->match_flags & MATCHFLG_CVSIGNORE) {
++
++              memcpy(array++, lp, sizeof (struct exclude_list_struct));
++
++              array = push_merge_files(lp->head, array);
++
++              if (ent->match_flags & MATCHFLG_CVSIGNORE) {
++                      lp->head = NULL; /* CVS doesn't inherit rules. */
 +                      flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY;
-+                      extra = NULL;
 +              } else {
-+                      flags = listp->parent->match_flags & MATCHFLG_INCLUDE
++                      flags = ent->match_flags & MATCHFLG_INCLUDE
 +                          ? XFLG_DEF_INCLUDE : 0;
-+                      extra = listp->head; /* Subdirs inherit our rules. */
 +              }
-+              clear_exclude_list(listp, extra);
-+              if (strlcpy(fname +  offset, file, MAXPATHLEN - offset)
-+                  < MAXPATHLEN - offset)
-+                      add_exclude_file(listp, fname, flags);
++              lp->tail = NULL; /* Switch any local rules to inherited. */
++              if (strlcpy(dirbuf +  dirbuf_offset, ent->pattern,
++                  MAXPATHLEN - dirbuf_offset) < MAXPATHLEN - dirbuf_offset)
++                      add_exclude_file(lp, dirbuf, flags);
 +              else {
 +                      io_error |= IOERR_GENERAL;
 +                      rprintf(FINFO,
 +                          "cannot add local excludes in long-named directory %s\n",
-+                          full_fname(fname));
++                          full_fname(dirbuf));
 +              }
 +      }
 +
++      return array;
++}
++
++void *push_local_excludes(char *fname, unsigned int offset)
++{
++      struct mergelist_save *push;
++
++      /* Make it easy to construct the full path for a merge-file that was
++       * specified with a relative path by saving off the current dir. */
++      memcpy(dirbuf, fname, offset);
++      dirbuf_offset = offset;
++
++      if (!(push = new_array(struct mergelist_save, 1)))
++              out_of_memory("push_local_excludes");
++
++      push->count = merge_list_cnt;
++      push->array = new_array(struct exclude_list_struct, merge_list_cnt);
++      if (!push->array)
++              out_of_memory("push_local_excludes");
++
++      push_merge_files(exclude_list.head, push->array);
++
 +      return (void*)push;
 +}
 +
-+void pop_local_excludes(void *mem)
++static struct exclude_list_struct *
++pop_merge_files(struct exclude_struct *ent, struct exclude_list_struct *array)
 +{
-+      int i;
++      struct exclude_list_struct *lp;
++
++      for (; ent; ent = ent->next) {
++              if (!(ent->match_flags & MATCHFLG_MERGE_FILE))
++                      continue;
++              lp = ent->u.merge_list;
 +
-+      for (i = 0; i < local_lists.cnt; i++) {
-+              struct exclude_list_struct *listp = &local_lists.head[i];
 +              if (verbose > 2) {
 +                      rprintf(FINFO, "[%s] popping %sexclude list\n",
-+                              who_am_i(), listp->debug_type);
++                              who_am_i(), lp->debug_type);
 +              }
-+              free_exclude_list(listp);
++
++              clear_exclude_list(lp);
++              memcpy(lp, array++, sizeof (struct exclude_list_struct));
++
++              array = pop_merge_files(lp->head, array);
 +      }
-+      free(local_lists.head);
-+      local_lists = *(struct exclude_list_root*)mem;
-+      free(mem);
- }
++
++      return array;
++}
++
++void pop_local_excludes(void *mem)
++{
++      struct mergelist_save *pop = (struct mergelist_save*)mem;
++
++      pop_merge_files(exclude_list.head, pop->array);
++      merge_list_cnt = pop->count;
++
++      free(pop->array);
++      free(pop);
++}
++
  static int check_one_exclude(char *name, struct exclude_struct *ex,
-@@ -139,7 +264,8 @@ static int check_one_exclude(char *name,
-       if (!name[0]) return 0;
--      if (ex->directory && !name_is_dir) return 0;
-+      if ((ex->match_flags & MATCHFLG_DIRECTORY) && !name_is_dir)
-+              return 0;
-       if (*pattern == '/') {
-               match_start = 1;
-@@ -206,9 +332,11 @@ static void report_exclude_result(char c
-       if (verbose >= 2) {
-               rprintf(FINFO, "[%s] %scluding %s %s because of %spattern %s%s\n",
--                      who_am_i(), ent->include ? "in" : "ex",
-+                      who_am_i(),
-+                      ent->match_flags & MATCHFLG_INCLUDE ? "in" : "ex",
-                       name_is_dir ? "directory" : "file", name, type,
--                      ent->pattern, ent->directory ? "/" : "");
-+                      ent->pattern,
-+                      ent->match_flags & MATCHFLG_DIRECTORY ? "/" : "");
+                              int name_is_dir)
+ {
+@@ -122,7 +301,7 @@ static int check_one_exclude(char *name,
+       /* If the pattern does not have any slashes AND it does not have
+        * a "**" (which could match a slash), then we just match the
+        * name portion of the path. */
+-      if (!ex->slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
++      if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) {
+               if ((p = strrchr(name,'/')) != NULL)
+                       name = p+1;
        }
- }
-@@ -222,10 +350,18 @@ int check_exclude(struct exclude_list_st
+@@ -148,9 +327,9 @@ static int check_one_exclude(char *name,
+       if (ex->match_flags & MATCHFLG_WILD) {
+               /* A non-anchored match with an infix slash and no "**"
+                * needs to match the last slash_cnt+1 name elements. */
+-              if (!match_start && ex->slash_cnt
++              if (!match_start && ex->u.slash_cnt
+                   && !(ex->match_flags & MATCHFLG_WILD2)) {
+-                      int cnt = ex->slash_cnt + 1;
++                      int cnt = ex->u.slash_cnt + 1;
+                       for (p = name + strlen(name) - 1; p >= name; p--) {
+                               if (*p == '/' && !--cnt)
+                                       break;
+@@ -221,6 +400,13 @@ int check_exclude(struct exclude_list_st
        struct exclude_struct *ent;
  
        for (ent = listp->head; ent; ent = ent->next) {
 +              if (ent->match_flags & MATCHFLG_MERGE_FILE) {
-+                      struct exclude_list_struct *lp
-+                          = &local_lists.head[ent->slash_cnt];
-+                      int rc = check_exclude(lp, name, name_is_dir);
++                      int rc = check_exclude(ent->u.merge_list, name,
++                                             name_is_dir);
 +                      if (rc)
 +                              return rc;
 +                      continue;
@@ -297,26 +315,7 @@ for the current dir because its name contained a slash.
                if (check_one_exclude(name, ent, name_is_dir)) {
                        report_exclude_result(name, ent, name_is_dir,
                                              listp->debug_type);
--                      return ent->include ? 1 : -1;
-+                      return (ent->match_flags & MATCHFLG_INCLUDE) ? 1 : -1;
-               }
-       }
-@@ -241,11 +377,11 @@ int check_exclude(struct exclude_list_st
-  * *incl_ptr value will be 1 for an include, 0 for an exclude, and -1 for
-  * the list-clearing "!" token.
-  */
--static const char *get_exclude_tok(const char *p, int *len_ptr, int *incl_ptr,
-+static const char *get_exclude_tok(const char *p, int *len_ptr, int *flag_ptr,
-                                  int xflags)
- {
-       const unsigned char *s = (const unsigned char *)p;
--      int len;
-+      int len, mflags = 0;
-       if (xflags & XFLG_WORD_SPLIT) {
-               /* Skip over any initial whitespace. */
-@@ -255,13 +391,19 @@ static const char *get_exclude_tok(const
+@@ -254,11 +440,16 @@ static const char *get_exclude_tok(const
                p = (const char *)s;
        }
  
@@ -324,74 +323,28 @@ for the current dir because its name contained a slash.
 +      /* Is this a +/-/. followed by a space (not whitespace)? */
        if (!(xflags & XFLG_WORDS_ONLY)
 -          && (*s == '-' || *s == '+') && s[1] == ' ') {
--              *incl_ptr = *s == '+';
 +          && (*s == '-' || *s == '+' || *s == '.') && s[1] == ' ') {
-+              if (*s == '+')
-+                      mflags |= MATCHFLG_INCLUDE;
+               if (*s == '+')
+                       mflags |= MATCHFLG_INCLUDE;
 +              else if (*s == '.') {
 +                      mflags |= MATCHFLG_MERGE_FILE;
 +                      if (xflags & XFLG_DEF_INCLUDE)
 +                              mflags |= MATCHFLG_INCLUDE;
 +              }
                s += 2;
--      } else
--              *incl_ptr = xflags & XFLG_DEF_INCLUDE;
-+      } else if (xflags & XFLG_DEF_INCLUDE)
-+              mflags |= MATCHFLG_INCLUDE;
-       if (xflags & XFLG_WORD_SPLIT) {
-               const unsigned char *cp = s;
-@@ -273,9 +415,10 @@ static const char *get_exclude_tok(const
-               len = strlen(s);
-       if (*p == '!' && len == 1 && !(xflags & XFLG_WORDS_ONLY))
--              *incl_ptr = -1;
-+              mflags |= MATCHFLG_CLEAR_LIST;
-       *len_ptr = len;
-+      *flag_ptr = mflags;
-       return (const char *)s;
- }
-@@ -283,7 +426,7 @@ static const char *get_exclude_tok(const
- void add_exclude(struct exclude_list_struct *listp, const char *pattern,
-                int xflags)
- {
--      int pat_len, incl;
-+      int pat_len, mflags;
-       const char *cp;
+       } else if (xflags & XFLG_DEF_INCLUDE)
+               mflags |= MATCHFLG_INCLUDE;
+@@ -307,11 +498,42 @@ void add_exclude(struct exclude_list_str
+                       continue;
+               }
  
-       if (!pattern)
-@@ -292,22 +435,48 @@ void add_exclude(struct exclude_list_str
-       cp = pattern;
-       pat_len = 0;
-       while (1) {
--              cp = get_exclude_tok(cp + pat_len, &pat_len, &incl, xflags);
-+              cp = get_exclude_tok(cp + pat_len, &pat_len, &mflags, xflags);
-               if (!pat_len)
-                       break;
--              /* If we got the special "!" token, clear the list. */
--              if (incl < 0)
--                      free_exclude_list(listp);
--              else {
--                      make_exclude(listp, cp, pat_len, incl);
--
-+              if (mflags & MATCHFLG_CLEAR_LIST) {
-                       if (verbose > 2) {
--                              rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s)\n",
--                                      who_am_i(), pat_len, cp,
--                                      listp->debug_type,
--                                      incl ? "include" : "exclude");
-+                              rprintf(FINFO, "[%s] clearing %sexclude list\n",
-+                                      who_am_i(), listp->debug_type);
-+                      }
-+                      free_exclude_list(listp);
-+                      continue;
-+              }
 +              if (mflags & MATCHFLG_MERGE_FILE) {
 +                      char name[MAXPATHLEN];
-+                      if ((unsigned) pat_len >= sizeof name)
-+                              continue; /* XXX complain? */
++                      if (pat_len >= sizeof name) {
++                              rprintf(FERROR,
++                                      "merge filename too long: %s\n", cp);
++                              continue;
++                      }
 +                      strlcpy(name, cp, pat_len+1);
 +                      if (strchr(name, '/') != NULL) {
 +                              if (sanitize_paths)
@@ -401,39 +354,32 @@ for the current dir because its name contained a slash.
 +                              else {
 +                                      if (strlcpy(dirbuf + dirbuf_offset,
 +                                          name, MAXPATHLEN - dirbuf_offset)
-+                                          >= MAXPATHLEN - dirbuf_offset)
-+                                              continue; /* XXX complain? */
++                                          >= MAXPATHLEN - dirbuf_offset) {
++                                              rprintf(FERROR,
++                                                  "merge filename too long: %s...\n",
++                                                  dirbuf);
++                                              continue;
++                                      }
 +                                      cp = dirbuf;
 +                              }
 +                              add_exclude_file(listp, cp,
 +                                  xflags | XFLG_FATAL_ERRORS);
 +                              continue;
-                       }
-               }
-+
-+              make_exclude(listp, cp, pat_len, mflags);
++                      }
++              }
 +
-+              if (verbose > 2) {
+               make_exclude(listp, cp, pat_len, mflags);
+               if (verbose > 2) {
+-                      rprintf(FINFO, "[%s] add_exclude(%.*s, %s%sclude)\n",
 +                      rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s%sclude)\n",
-+                              who_am_i(), pat_len, cp, listp->debug_type,
+                               who_am_i(), pat_len, cp, listp->debug_type,
 +                              mflags & MATCHFLG_MERGE_FILE ? "FILE " : "",
-+                              mflags & MATCHFLG_INCLUDE ? "in" : "ex");
-+              }
-       }
- }
-@@ -383,15 +552,19 @@ void send_exclude_list(int f)
-               l = strlcpy(p, ent->pattern, sizeof p);
-               if (l == 0 || l >= MAXPATHLEN)
-                       continue;
--              if (ent->directory) {
-+              if (ent->match_flags & MATCHFLG_DIRECTORY) {
-                       p[l++] = '/';
-                       p[l] = '\0';
+                               mflags & MATCHFLG_INCLUDE ? "in" : "ex");
                }
--              if (ent->include) {
-+              if (ent->match_flags & MATCHFLG_INCLUDE) {
+       }
+@@ -403,7 +625,11 @@ void send_exclude_list(int f)
+               if (ent->match_flags & MATCHFLG_INCLUDE) {
                        write_int(f, l + 2);
                        write_buf(f, "+ ", 2);
 -              } else if ((*p == '-' || *p == '+') && p[1] == ' ') {
@@ -445,7 +391,7 @@ for the current dir because its name contained a slash.
                        write_int(f, l + 2);
                        write_buf(f, "- ", 2);
                } else
-@@ -432,6 +605,7 @@ void add_cvs_excludes(void)
+@@ -444,6 +670,7 @@ void add_cvs_excludes(void)
        char fname[MAXPATHLEN];
        char *p;
  
@@ -453,8 +399,8 @@ for the current dir because its name contained a slash.
        add_exclude(&exclude_list, default_cvsignore,
                    XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
  
---- flist.c    3 May 2004 01:24:10 -0000       1.220
-+++ flist.c    8 May 2004 18:38:52 -0000
+--- flist.c    16 May 2004 23:54:12 -0000      1.224
++++ flist.c    17 May 2004 16:16:24 -0000
 @@ -39,8 +39,6 @@ extern int module_id;
  extern int ignore_errors;
  extern int numeric_ids;
@@ -464,7 +410,7 @@ for the current dir because its name contained a slash.
  extern int recurse;
  extern char curr_dir[MAXPATHLEN];
  extern char *files_from;
-@@ -66,7 +64,6 @@ extern int write_batch;
+@@ -65,7 +63,6 @@ extern int write_batch;
  
  extern struct exclude_list_struct exclude_list;
  extern struct exclude_list_struct server_exclude_list;
@@ -472,7 +418,7 @@ for the current dir because its name contained a slash.
  
  int io_error;
  
-@@ -211,8 +208,6 @@ int link_stat(const char *path, STRUCT_S
+@@ -210,8 +207,6 @@ int link_stat(const char *path, STRUCT_S
   */
  static int check_exclude_file(char *fname, int is_dir, int exclude_level)
  {
@@ -481,7 +427,7 @@ for the current dir because its name contained a slash.
  #if 0 /* This currently never happens, so avoid a useless compare. */
        if (exclude_level == NO_EXCLUDES)
                return 0;
-@@ -234,10 +229,7 @@ static int check_exclude_file(char *fnam
+@@ -233,10 +228,7 @@ static int check_exclude_file(char *fnam
        if (exclude_level != ALL_EXCLUDES)
                return 0;
        if (exclude_list.head
@@ -493,19 +439,23 @@ for the current dir because its name contained a slash.
                return 1;
        return 0;
  }
-@@ -947,11 +939,7 @@ void send_file_name(int f, struct file_l
+@@ -946,15 +938,7 @@ 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;
 -              local_exclude_list.head = local_exclude_list.tail = NULL;
                send_directory(f, flist, f_name_to(file, fbuf));
--              free_exclude_list(&local_exclude_list);
+-              if (verbose > 2) {
+-                      rprintf(FINFO, "[%s] popping %sexclude list\n",
+-                              who_am_i(), local_exclude_list.debug_type);
+-              }
+-              clear_exclude_list(&local_exclude_list);
 -              local_exclude_list = last_list;
        }
  }
  
-@@ -962,6 +950,7 @@ static void send_directory(int f, struct
+@@ -965,6 +949,7 @@ static void send_directory(int f, struct
        struct dirent *di;
        char fname[MAXPATHLEN];
        unsigned int offset;
@@ -513,7 +463,7 @@ for the current dir because its name contained a slash.
        char *p;
  
        d = opendir(dir);
-@@ -986,18 +975,7 @@ static void send_directory(int f, struct
+@@ -988,18 +973,7 @@ static void send_directory(int f, struct
                offset++;
        }
  
@@ -533,57 +483,37 @@ for the current dir because its name contained a slash.
  
        for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
                char *dname = d_name(di);
-@@ -1018,6 +996,8 @@ static void send_directory(int f, struct
-               rprintf(FERROR, "readdir(%s): (%d) %s\n",
-                       dir, errno, strerror(errno));
+@@ -1019,6 +993,8 @@ static void send_directory(int f, struct
+               io_error |= IOERR_GENERAL;
+               rsyserr(FERROR, errno, "readdir(%s)", dir);
        }
 +
 +      pop_local_excludes(save_excludes);
  
        closedir(d);
  }
---- proto.h    22 Apr 2004 09:58:09 -0000      1.189
-+++ proto.h    8 May 2004 18:38:52 -0000
-@@ -51,7 +51,8 @@ int start_daemon(int f_in, int f_out);
- 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 *push_local_excludes(char *fname, unsigned int offset);
-+void pop_local_excludes(void *mem);
- int check_exclude(struct exclude_list_struct *listp, char *name, int name_is_dir);
- void add_exclude(struct exclude_list_struct *listp, const char *pattern,
-                int xflags);
---- rsync.h    2 May 2004 16:34:33 -0000       1.200
-+++ rsync.h    8 May 2004 18:38:52 -0000
-@@ -490,18 +490,21 @@ struct map_struct {
- #define MATCHFLG_WILD2                (1<<1) /* pattern has '**' */
- #define MATCHFLG_WILD2_PREFIX (1<<2) /* pattern starts with '**' */
- #define MATCHFLG_ABS_PATH     (1<<3) /* path-match on absolute path */
-+#define MATCHFLG_INCLUDE      (1<<4) /* this is an include, not an exclude */
-+#define MATCHFLG_CLEAR_LIST   (1<<5) /* this item is the "!" token */
-+#define MATCHFLG_DIRECTORY    (1<<6) /* this matches only directories */
+--- rsync.h    16 May 2004 07:28:24 -0000      1.204
++++ rsync.h    17 May 2004 16:16:25 -0000
+@@ -496,11 +496,16 @@ struct map_struct {
+ #define MATCHFLG_INCLUDE      (1<<4) /* this is an include, not an exclude */
+ #define MATCHFLG_DIRECTORY    (1<<5) /* this matches only directories */
+ #define MATCHFLG_CLEAR_LIST   (1<<6) /* this item is the "!" token */
 +#define MATCHFLG_MERGE_FILE   (1<<7) /* specifies a file to merge */
 +#define MATCHFLG_CVSIGNORE    (1<<8) /* parse this as a .cvsignore file */
  struct exclude_struct {
        struct exclude_struct *next;
        char *pattern;
-       int match_flags;
--      int include;
--      int directory;
-       int slash_cnt;
+       unsigned int match_flags;
+-      int slash_cnt;
++      union {
++              int slash_cnt;
++              struct exclude_list_struct *merge_list;
++      } u;
  };
  
  struct exclude_list_struct {
--      struct exclude_struct *head;
--      struct exclude_struct *tail;
-+      struct exclude_struct *head, *tail;
-+      struct exclude_struct *extra, *parent;
-       char *debug_type;
- };
 --- rsync.yo   7 May 2004 00:18:37 -0000       1.169
-+++ rsync.yo   8 May 2004 18:38:53 -0000
++++ rsync.yo   17 May 2004 16:16:26 -0000
 @@ -1075,6 +1075,72 @@ itemize(
    it would be excluded by the "*")
  )
@@ -597,11 +527,11 @@ for the current dir because its name contained a slash.
 +
 +itemize(
 +  it() If the filename has no slashes in it, it is a per-directory merge;
-+  rsync scans every directory that is traversed and merges the named file's
-+  contents (when it exists), putting the contents of each subdirectory's
-+  file at the start of this per-directory sub-list (so subdirectories
-+  inherit the contents of their parent directories by default, but each
-+  subdirectory's rules have precedence over the parent's rules).
++  rsync scans every directory that it traverses for the named file, merging
++  its contents (when it exists) file at the start of this per-directory
++  sub-list (subdirectories inherit the contents of their parent directories
++  by default, and each subdirectory's rules have precedence over the parent
++  directory's rules).
 +
 +  it() If a filename has a slash in it, it is a single-instance merge; the
 +  named file's contents will be merged into the current exclude file,
@@ -612,12 +542,12 @@ for the current dir because its name contained a slash.
 +
 +Note also that you can eliminate all the inherited rules for the current
 +per-directory ruleset by putting the list-clearing token (!) in the file.
-+This clears only the rules of the current per-directory sub-list (up
-+through the token) and only for the current directory and its
++This only clears the rules for the current per-directory sub-list (up
++through the token) and only for the current directory and its
 +subdirectories.
 +
-+Here's an example. Specify the file that holds this set of rules via a
-+normal --exclude-from option:
++Here's an example exclude file (which you'd specify via the normal
++--exclude-from option):
 +
 +verb(
 +    . /home/user/.global_excludes
@@ -634,7 +564,7 @@ for the current dir because its name contained a slash.
 +
 +Additionally, you can affect where the --cvs-exclude (-C) option's
 +inclusion of a per-directory .cvsignore file gets placed into your rules by
-+adding an explicit merge rule for ".cvsignore".  For instance, specifying
++adding an explicit merge rule for ".cvsignore".  For instance, specifying
 +this:
 +
 +verb(