| 1 | This patch causes the --cvs-exclude option to prefix the names listed |
| 2 | in each dir's CVS/Entries file as per-dir includes before the dir's list |
| 3 | of excludes taken from the .cvsignore file. |
| 4 | |
| 5 | --- old/exclude.c |
| 6 | +++ new/exclude.c |
| 7 | @@ -221,6 +221,8 @@ static void add_rule(struct filter_list_ |
| 8 | if (!(lp = new_array(struct filter_list_struct, 1))) |
| 9 | out_of_memory("add_rule"); |
| 10 | lp->head = lp->tail = NULL; |
| 11 | + if (mflags & MATCHFLG_CVS_IGNORE) |
| 12 | + cp = "CVS"; |
| 13 | if (asprintf(&lp->debug_type, " [per-dir %s]", cp) < 0) |
| 14 | out_of_memory("add_rule"); |
| 15 | ret->u.mergelist = lp; |
| 16 | @@ -454,6 +456,14 @@ void *push_local_filters(const char *dir |
| 17 | set_filter_dir(dir, dirlen); |
| 18 | } |
| 19 | |
| 20 | + if (ex->match_flags & MATCHFLG_CVS_IGNORE |
| 21 | + && strlcpy(dirbuf + dirbuf_len, "CVS/Entries", |
| 22 | + MAXPATHLEN - dirbuf_len) < MAXPATHLEN - dirbuf_len) { |
| 23 | + /* Start by adding include rules for all the names in CVS/Entries. */ |
| 24 | + parse_filter_file(lp, dirbuf, |
| 25 | + MATCHFLG_NO_PREFIXES | MATCHFLG_INCLUDE, |
| 26 | + XFLG_CVS_ENTRIES); |
| 27 | + } |
| 28 | if (strlcpy(dirbuf + dirbuf_len, ex->pattern, |
| 29 | MAXPATHLEN - dirbuf_len) < MAXPATHLEN - dirbuf_len) { |
| 30 | parse_filter_file(lp, dirbuf, ex->match_flags, |
| 31 | @@ -970,6 +980,7 @@ void parse_filter_file(struct filter_lis |
| 32 | char line[BIGPATHBUFLEN]; |
| 33 | char *eob = line + sizeof line - 1; |
| 34 | int word_split = mflags & MATCHFLG_WORD_SPLIT; |
| 35 | + int slash_parse = xflags & XFLG_CVS_ENTRIES ? 1 : 0; |
| 36 | |
| 37 | if (!fname || !*fname) |
| 38 | return; |
| 39 | @@ -1016,6 +1027,24 @@ void parse_filter_file(struct filter_lis |
| 40 | } |
| 41 | break; |
| 42 | } |
| 43 | + switch (slash_parse) { /* CVS/Entries parsing: */ |
| 44 | + case 1: /* Ignore starting chars until first slash. */ |
| 45 | + if (ch == '/') |
| 46 | + slash_parse = 2; |
| 47 | + continue; |
| 48 | + case 2: /* Name ends at 2nd slash on the line. */ |
| 49 | + if (ch == '/') { |
| 50 | + slash_parse = 3; |
| 51 | + continue; |
| 52 | + } |
| 53 | + break; |
| 54 | + case 3: /* Ignore trailing chars until EOL. */ |
| 55 | + if (ch == '\n' || ch == '\r') { |
| 56 | + slash_parse = 1; |
| 57 | + goto end_the_line; |
| 58 | + } |
| 59 | + continue; |
| 60 | + } |
| 61 | if (word_split && isspace(ch)) |
| 62 | break; |
| 63 | if (eol_nulls? !ch : (ch == '\n' || ch == '\r')) |
| 64 | @@ -1025,13 +1054,15 @@ void parse_filter_file(struct filter_lis |
| 65 | else |
| 66 | overflow = 1; |
| 67 | } |
| 68 | + end_the_line: |
| 69 | if (overflow) { |
| 70 | rprintf(FERROR, "discarding over-long filter: %s...\n", line); |
| 71 | s = line; |
| 72 | } |
| 73 | *s = '\0'; |
| 74 | /* Skip an empty token and (when line parsing) comments. */ |
| 75 | - if (*line && (word_split || (*line != ';' && *line != '#'))) |
| 76 | + if (*line && (word_split || slash_parse |
| 77 | + || (*line != ';' && *line != '#'))) |
| 78 | parse_rule(listp, line, mflags, xflags); |
| 79 | if (ch == EOF) |
| 80 | break; |
| 81 | --- old/rsync.h |
| 82 | +++ new/rsync.h |
| 83 | @@ -116,6 +116,7 @@ |
| 84 | #define XFLG_OLD_PREFIXES (1<<1) |
| 85 | #define XFLG_ANCHORED2ABS (1<<2) |
| 86 | #define XFLG_ABS_IF_SLASH (1<<3) |
| 87 | +#define XFLG_CVS_ENTRIES (1<<4) |
| 88 | |
| 89 | #define ATTRS_REPORT (1<<0) |
| 90 | #define ATTRS_SKIP_MTIME (1<<1) |
| 91 | --- old/testsuite/exclude.test |
| 92 | +++ new/testsuite/exclude.test |
| 93 | @@ -19,6 +19,7 @@ export CVSIGNORE |
| 94 | |
| 95 | makepath "$fromdir/foo/down/to/you" |
| 96 | makepath "$fromdir/foo/sub" |
| 97 | +makepath "$fromdir/bar/down/to/CVS" |
| 98 | makepath "$fromdir/bar/down/to/foo/too" |
| 99 | makepath "$fromdir/bar/down/to/bar/baz" |
| 100 | makepath "$fromdir/mid/for/foo/and/that/is/who" |
| 101 | @@ -57,6 +58,9 @@ echo cvsout >"$fromdir/bar/down/to/foo/f |
| 102 | echo gone >"$fromdir/bar/down/to/foo/file3" |
| 103 | echo lost >"$fromdir/bar/down/to/foo/file4" |
| 104 | echo weird >"$fromdir/bar/down/to/foo/+ file3" |
| 105 | +echo cvsin >"$fromdir/bar/down/to/not.junk" |
| 106 | +echo cvsout >"$fromdir/bar/down/to/not.good" |
| 107 | +echo cvsout >"$fromdir/bar/down/to/D" |
| 108 | echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk" |
| 109 | echo smashed >"$fromdir/bar/down/to/foo/to" |
| 110 | cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF |
| 111 | @@ -103,7 +107,18 @@ cat >"$excl" <<EOF |
| 112 | EOF |
| 113 | |
| 114 | cat >"$scratchdir/.cvsignore" <<EOF |
| 115 | -home-cvs-exclude |
| 116 | +home-cvs-exclude D |
| 117 | +EOF |
| 118 | +cat >"$fromdir/bar/down/to/CVS/Entries" <<EOF |
| 119 | +/not.junk/1.1/Mon Jan 1 11:11:11 2001// |
| 120 | +filt2 |
| 121 | +/another.file/1.1/Tue Jan 1 22:22:22 2002// |
| 122 | +invalid lines should just be ignored... |
| 123 | +D/directory//// |
| 124 | +D |
| 125 | +EOF |
| 126 | +cat >"$fromdir/bar/down/to/.cvsignore" <<EOF |
| 127 | +not.good |
| 128 | EOF |
| 129 | |
| 130 | # Create the chk dir with what we expect to be excluded |
| 131 | @@ -132,6 +147,10 @@ checkit "$RSYNC -avv --exclude-from=\"$e |
| 132 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
| 133 | |
| 134 | rm "$chkdir"/foo/*.old |
| 135 | +rm "$chkdir"/bar/down/to/D |
| 136 | +rm "$chkdir"/bar/down/to/CVS/Entries |
| 137 | +rmdir "$chkdir"/bar/down/to/CVS |
| 138 | +rm "$chkdir"/bar/down/to/not.good |
| 139 | rm "$chkdir"/bar/down/to/foo/*.bak |
| 140 | rm "$chkdir"/bar/down/to/foo/*.junk |
| 141 | rm "$chkdir"/bar/down/to/home-cvs-exclude |
| 142 | @@ -147,8 +166,12 @@ checkit "$RSYNC -avvC --filter=\"merge $ |
| 143 | |
| 144 | # Modify the chk dir for our merge-exclude test and then tweak the dir times. |
| 145 | |
| 146 | +makepath "$chkdir/bar/down/to/CVS" |
| 147 | rm "$chkdir"/foo/file1 |
| 148 | rm "$chkdir"/bar/down/to/bar/baz/*.deep |
| 149 | +cp -p "$fromdir"/bar/down/to/D "$chkdir"/bar/down/to/D |
| 150 | +cp -p "$fromdir"/bar/down/to/not.good "$chkdir"/bar/down/to/not.good |
| 151 | +cp -p "$fromdir"/bar/down/to/CVS/Entries "$chkdir"/bar/down/to/CVS/Entries |
| 152 | cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo |
| 153 | cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo |
| 154 | |