- if (ent->match_flags & MATCHFLG_PERDIR_MERGE) {
- char buf[MAX_RULE_PREFIX], *op = buf;
- if (protocol_version < 29) {
- rprintf(FERROR,
- "remote rsync is too old to understand per-directory merge files.\n");
- exit_cleanup(RERR_SYNTAX);
- }
- *op++ = ':';
- if (ent->match_flags & MATCHFLG_WORD_SPLIT)
- *op++ = 's';
- if (ent->match_flags & MATCHFLG_NO_INHERIT)
- *op++ = 'n';
- if (ent->match_flags & MATCHFLG_EXCLUDE_SELF)
- *op++ = 'e';
- if (ent->match_flags & MATCHFLG_NO_PREFIXES) {
- if (ent->match_flags & MATCHFLG_INCLUDE)
- *op++ = '+';
- else
- *op++ = '-';
- }
- *op++ = ' ';
- if (op - buf > MAX_RULE_PREFIX)
- overflow("send_filter_list");
- write_int(f, l + (op - buf));
- write_buf(f, buf, op - buf);
- } else if (ent->match_flags & MATCHFLG_INCLUDE) {
- write_int(f, l + 2);
- write_buf(f, "+ ", 2);
- } else if (protocol_version >= 29
- || ((*p == '-' || *p == '+') && p[1] == ' ')) {
- write_int(f, l + 2);
- write_buf(f, "- ", 2);
+static void send_rules(int f_out, struct filter_list_struct *flp)
+{
+ struct filter_struct *ent, *prev = NULL;
+
+ for (ent = flp->head; ent; ent = ent->next) {
+ unsigned int len, plen, dlen;
+ int elide = 0;
+ char *p;
+
+ /* Note we need to check delete_excluded here in addition to
+ * the code in parse_rule_tok() because some rules may have
+ * been added before we found the --delete-excluded option.
+ * We must also elide any CVS merge-file rules to avoid a
+ * backward compatibility problem, and we elide any no-prefix
+ * merge files as an optimization (since they can only have
+ * include/exclude rules). */
+ if (ent->match_flags & MATCHFLG_SENDER_SIDE)
+ elide = am_sender ? 1 : -1;
+ if (ent->match_flags & MATCHFLG_RECEIVER_SIDE)
+ elide = elide ? 0 : am_sender ? -1 : 1;
+ else if (delete_excluded && !elide
+ && (!(ent->match_flags & MATCHFLG_PERDIR_MERGE)
+ || ent->match_flags & MATCHFLG_NO_PREFIXES))
+ elide = am_sender ? 1 : -1;
+ if (elide < 0) {
+ if (prev)
+ prev->next = ent->next;
+ else
+ flp->head = ent->next;