Commit | Line | Data |
---|---|---|
8a529471 WD |
1 | After applying this patch and running configure, you MUST run this |
2 | command before "make": | |
3 | ||
4 | make proto | |
5 | ||
524989ae WD |
6 | This patch adds the ability to merge rules into your excludes/includes |
7 | using a ". FILE" idiom. If you specify a name without slashes, that | |
8 | filename will be looked for in every subdirectory that rsync visits, | |
0c7d1fd8 WD |
9 | and the rules found in that subdirectory's file will affect that dir |
10 | and its subdirectories. | |
a55d21aa WD |
11 | |
12 | For example: | |
13 | ||
14 | rsync -av --exclude='. .excl' from/ to | |
15 | ||
16 | The above will look for a file named ".excl" in every directory of the | |
524989ae WD |
17 | hierarchy that rsync visits, and it will exclude (by default) names |
18 | based on the rules found therein. If one of the .excl files contains | |
19 | this: | |
a55d21aa WD |
20 | |
21 | + *.c | |
524989ae WD |
22 | . .excl2 |
23 | . ./.excl3 | |
24 | *.o | |
a55d21aa | 25 | |
524989ae WD |
26 | Then the file ".excl2" will also be read in the current dir, and all |
27 | subdirs of the current dir. The file ".excl3" would just be read in | |
28 | for the current dir because its name contained a slash. | |
a55d21aa WD |
29 | |
30 | ..wayne.. | |
31 | ||
066e3b3e WD |
32 | --- exclude.c 22 May 2004 05:32:20 -0000 1.82 |
33 | +++ exclude.c 22 May 2004 06:02:55 -0000 | |
eabda998 | 34 | @@ -30,13 +30,56 @@ extern int verbose; |
a55d21aa WD |
35 | extern int eol_nulls; |
36 | extern int list_only; | |
37 | extern int recurse; | |
38 | +extern int io_error; | |
39 | +extern int sanitize_paths; | |
40 | ||
41 | extern char curr_dir[]; | |
42 | ||
d8af8661 | 43 | struct exclude_list_struct exclude_list = { 0, 0, "" }; |
524989ae | 44 | -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " }; |
d8af8661 | 45 | struct exclude_list_struct server_exclude_list = { 0, 0, "server " }; |
a55d21aa | 46 | char *exclude_path_prefix = NULL; |
eabda998 WD |
47 | +struct exclude_struct **mergelist_parents; |
48 | +int mergelist_cnt = 0; | |
49 | +int mergelist_size = 0; | |
d8af8661 | 50 | + |
eabda998 | 51 | +struct mergelist_save_struct { |
d1e7c1c8 | 52 | + struct exclude_list_struct *array; |
d8af8661 WD |
53 | + int count; |
54 | +}; | |
524989ae | 55 | + |
a55d21aa WD |
56 | +static char dirbuf[MAXPATHLEN]; |
57 | +static unsigned int dirbuf_offset = 0; | |
a55d21aa | 58 | + |
d1e7c1c8 WD |
59 | +/* Each exclude_list_struct describes a singly-linked list by keeping track |
60 | + * of both the head and tail pointers. The list is slightly unusual in that | |
61 | + * a parent-dir's content can be appended to the end of the local list in a | |
62 | + * special way: the last item in the local list has its "next" pointer set | |
0c7d1fd8 | 63 | + * to point to the inherited list, but the local list's tail pointer points |
d1e7c1c8 | 64 | + * at the end of the local list. Thus, if the local list is empty, the head |
0c7d1fd8 | 65 | + * will be pointing at the inherited content but the tail will be NULL. To |
d1e7c1c8 WD |
66 | + * help you visualize this, here are the possible list arrangements: |
67 | + * | |
68 | + * Completely Empty Local Content Only | |
69 | + * ================================== ==================================== | |
70 | + * head -> NULL head -> Local1 -> Local2 -> NULL | |
71 | + * tail -> NULL tail -------------^ | |
72 | + * | |
73 | + * Inherited Content Only Both Local and Inherited Content | |
74 | + * ================================== ==================================== | |
75 | + * head -> Parent1 -> Parent2 -> NULL head -> L1 -> L2 -> P1 -> P2 -> NULL | |
76 | + * tail -> NULL tail ---------^ | |
77 | + * | |
78 | + * This means that anyone wanting to traverse the whole list to USE it just | |
79 | + * needs to start at the head and use the "next" pointers until it goes | |
80 | + * NULL. To add new local content, we insert the item after the tail item | |
81 | + * and update the tail (obviously, if "tail" was NULL, we insert it at the | |
82 | + * head). To clear the local list, WE MUST NOT FREE THE INHERITED CONTENT | |
bc95f62b WD |
83 | + * because it is shared between the current list and our parent list(s). |
84 | + * The easiest way to handle this is to simply truncate the list after the | |
85 | + * tail item and then free the local list from the head. When inheriting | |
86 | + * the list for a new local dir, we just save off the exclude_list_struct | |
0c7d1fd8 | 87 | + * values (so we can pop back to them later) and set the tail to NULL. |
d1e7c1c8 | 88 | + */ |
d8af8661 | 89 | |
0c7d1fd8 WD |
90 | /** Build an exclude structure given an exclude pattern. */ |
91 | static void make_exclude(struct exclude_list_struct *listp, const char *pat, | |
eabda998 | 92 | @@ -46,6 +89,24 @@ static void make_exclude(struct exclude_ |
a55d21aa | 93 | const char *cp; |
0c7d1fd8 WD |
94 | unsigned int ex_len; |
95 | ||
524989ae | 96 | + if (mflags & MATCHFLG_MERGE_FILE) { |
eabda998 | 97 | + int i; |
a55d21aa | 98 | + /* If the local include file was already mentioned, don't |
524989ae | 99 | + * add it again. */ |
eabda998 WD |
100 | + for (i = 0; i < mergelist_cnt; i++) { |
101 | + struct exclude_struct *ex = mergelist_parents[i]; | |
102 | + if (strlen(ex->pattern) == pat_len | |
d8af8661 | 103 | + && memcmp(ex->pattern, pat, pat_len) == 0) |
a55d21aa WD |
104 | + return; |
105 | + } | |
524989ae WD |
106 | + if ((pat_len == 10 || (pat_len > 10 && pat[pat_len-11] == '/')) |
107 | + && strncmp(pat+pat_len-10, ".cvsignore", 10) == 0) { | |
a55d21aa WD |
108 | + mflags |= MATCHFLG_CVSIGNORE; |
109 | + mflags &= ~MATCHFLG_INCLUDE; | |
110 | + } else | |
111 | + mflags &= ~MATCHFLG_CVSIGNORE; | |
112 | + } | |
0c7d1fd8 | 113 | + |
a55d21aa WD |
114 | ret = new(struct exclude_struct); |
115 | if (!ret) | |
116 | out_of_memory("make_exclude"); | |
eabda998 | 117 | @@ -81,14 +142,36 @@ static void make_exclude(struct exclude_ |
7b22909b | 118 | mflags |= MATCHFLG_DIRECTORY; |
a55d21aa WD |
119 | } |
120 | ||
7b22909b | 121 | - for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++) |
bc95f62b | 122 | - ret->slash_cnt++; |
524989ae | 123 | + if (mflags & MATCHFLG_MERGE_FILE) { |
d8af8661 WD |
124 | + struct exclude_list_struct *lp |
125 | + = new_array(struct exclude_list_struct, 1); | |
126 | + if (!lp) | |
a55d21aa | 127 | + out_of_memory("make_exclude"); |
7cb7ae4e | 128 | + lp->head = lp->tail = NULL; |
524989ae | 129 | + if (asprintf(&lp->debug_type, "per-dir %s ", ret->pattern) < 0) |
a55d21aa | 130 | + out_of_memory("make_exclude"); |
eabda998 WD |
131 | + ret->u.mergelist = lp; |
132 | + if (mergelist_cnt == mergelist_size) { | |
133 | + mergelist_size += 5; | |
134 | + mergelist_parents = realloc_array(mergelist_parents, | |
135 | + struct exclude_struct *, | |
136 | + mergelist_size); | |
137 | + if (!mergelist_parents) | |
138 | + out_of_memory("make_exclude"); | |
139 | + } | |
140 | + mergelist_parents[mergelist_cnt++] = ret; | |
7b22909b WD |
141 | + } else { |
142 | + for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++) | |
143 | + ret->u.slash_cnt++; | |
abe86b1f | 144 | + } |
7b22909b | 145 | |
0c7d1fd8 | 146 | ret->match_flags = mflags; |
a55d21aa | 147 | |
7b22909b WD |
148 | - if (!listp->tail) |
149 | + if (!listp->tail) { | |
150 | + ret->next = listp->head; | |
151 | listp->head = listp->tail = ret; | |
152 | - else { | |
153 | + } else { | |
154 | + ret->next = listp->tail->next; | |
155 | listp->tail->next = ret; | |
156 | listp->tail = ret; | |
157 | } | |
eabda998 | 158 | @@ -96,22 +179,115 @@ static void make_exclude(struct exclude_ |
d8af8661 WD |
159 | |
160 | static void free_exclude(struct exclude_struct *ex) | |
161 | { | |
162 | + if (ex->match_flags & MATCHFLG_MERGE_FILE) { | |
eabda998 WD |
163 | + free(ex->u.mergelist->debug_type); |
164 | + free(ex->u.mergelist); | |
d8af8661 WD |
165 | + } |
166 | free(ex->pattern); | |
a55d21aa WD |
167 | free(ex); |
168 | } | |
169 | ||
d8af8661 WD |
170 | -void clear_exclude_list(struct exclude_list_struct *listp) |
171 | +static void clear_exclude_list(struct exclude_list_struct *listp) | |
a55d21aa | 172 | { |
7cb7ae4e WD |
173 | - struct exclude_struct *ent, *next; |
174 | - | |
175 | - for (ent = listp->head; ent; ent = next) { | |
176 | - next = ent->next; | |
177 | - free_exclude(ent); | |
178 | + if (listp->tail) { | |
179 | + struct exclude_struct *ent, *next; | |
bc95f62b | 180 | + /* Truncate any inherited items from the local list. */ |
7cb7ae4e WD |
181 | + listp->tail->next = NULL; |
182 | + for (ent = listp->head; ent; ent = next) { | |
183 | + next = ent->next; | |
184 | + free_exclude(ent); | |
185 | + } | |
524989ae WD |
186 | } |
187 | ||
7cb7ae4e WD |
188 | listp->head = listp->tail = NULL; |
189 | } | |
a55d21aa | 190 | |
eabda998 | 191 | +void *push_local_excludes(char *fname, unsigned int offset) |
a55d21aa | 192 | +{ |
eabda998 WD |
193 | + struct mergelist_save_struct *push; |
194 | + struct exclude_list_struct *ap; | |
195 | + int i; | |
196 | + | |
197 | + /* Make it easy to construct the full path for a merge-file that was | |
198 | + * specified with a relative path by saving off the current dir. */ | |
199 | + memcpy(dirbuf, fname, offset); | |
200 | + dirbuf_offset = offset; | |
201 | + | |
202 | + if (!(push = new_array(struct mergelist_save_struct, 1))) | |
203 | + out_of_memory("push_local_excludes"); | |
204 | + | |
205 | + push->count = mergelist_cnt; | |
206 | + push->array = new_array(struct exclude_list_struct, mergelist_cnt); | |
207 | + if (!push->array) | |
208 | + out_of_memory("push_local_excludes"); | |
524989ae | 209 | + |
eabda998 WD |
210 | + for (i = 0, ap = push->array; i < mergelist_cnt; i++) { |
211 | + memcpy(ap++, mergelist_parents[i]->u.mergelist, | |
212 | + sizeof (struct exclude_list_struct)); | |
213 | + } | |
214 | + | |
215 | + /* Note: add_exclude_file() might increase mergelist_cnt, so keep | |
216 | + * this loop separate from the above loop. */ | |
217 | + for (i = 0; i < mergelist_cnt; i++) { | |
218 | + struct exclude_struct *ex = mergelist_parents[i]; | |
219 | + struct exclude_list_struct *lp = ex->u.mergelist; | |
a55d21aa | 220 | + int flags; |
524989ae WD |
221 | + |
222 | + if (verbose > 2) { | |
223 | + rprintf(FINFO, "[%s] pushing %sexclude list\n", | |
d8af8661 | 224 | + who_am_i(), lp->debug_type); |
524989ae | 225 | + } |
d8af8661 | 226 | + |
eabda998 | 227 | + if (ex->match_flags & MATCHFLG_CVSIGNORE) { |
d8af8661 | 228 | + lp->head = NULL; /* CVS doesn't inherit rules. */ |
ee1af13c | 229 | + flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY; |
a55d21aa | 230 | + } else { |
eabda998 | 231 | + flags = ex->match_flags & MATCHFLG_INCLUDE |
524989ae | 232 | + ? XFLG_DEF_INCLUDE : 0; |
a55d21aa | 233 | + } |
d8af8661 | 234 | + lp->tail = NULL; /* Switch any local rules to inherited. */ |
eabda998 | 235 | + if (strlcpy(dirbuf + dirbuf_offset, ex->pattern, |
d8af8661 WD |
236 | + MAXPATHLEN - dirbuf_offset) < MAXPATHLEN - dirbuf_offset) |
237 | + add_exclude_file(lp, dirbuf, flags); | |
524989ae | 238 | + else { |
a55d21aa WD |
239 | + io_error |= IOERR_GENERAL; |
240 | + rprintf(FINFO, | |
241 | + "cannot add local excludes in long-named directory %s\n", | |
d8af8661 | 242 | + full_fname(dirbuf)); |
a55d21aa WD |
243 | + } |
244 | + } | |
245 | + | |
524989ae | 246 | + return (void*)push; |
a55d21aa WD |
247 | +} |
248 | + | |
eabda998 | 249 | +void pop_local_excludes(void *mem) |
a55d21aa | 250 | +{ |
eabda998 WD |
251 | + struct mergelist_save_struct *pop = (struct mergelist_save_struct*)mem; |
252 | + struct exclude_list_struct *ap; | |
253 | + int i; | |
d8af8661 | 254 | + |
066e3b3e | 255 | + for (i = mergelist_cnt; i-- > 0; ) { |
eabda998 WD |
256 | + struct exclude_struct *ex = mergelist_parents[i]; |
257 | + struct exclude_list_struct *lp = ex->u.mergelist; | |
524989ae | 258 | + |
524989ae WD |
259 | + if (verbose > 2) { |
260 | + rprintf(FINFO, "[%s] popping %sexclude list\n", | |
d8af8661 | 261 | + who_am_i(), lp->debug_type); |
524989ae | 262 | + } |
d8af8661 WD |
263 | + |
264 | + clear_exclude_list(lp); | |
a55d21aa | 265 | + } |
d8af8661 | 266 | + |
eabda998 WD |
267 | + mergelist_cnt = pop->count; |
268 | + for (i = 0, ap = pop->array; i < mergelist_cnt; i++) { | |
269 | + memcpy(mergelist_parents[i]->u.mergelist, ap++, | |
270 | + sizeof (struct exclude_list_struct)); | |
271 | + } | |
d8af8661 WD |
272 | + |
273 | + free(pop->array); | |
274 | + free(pop); | |
7cb7ae4e WD |
275 | +} |
276 | + | |
a55d21aa | 277 | static int check_one_exclude(char *name, struct exclude_struct *ex, |
7cb7ae4e WD |
278 | int name_is_dir) |
279 | { | |
eabda998 | 280 | @@ -122,7 +298,7 @@ static int check_one_exclude(char *name, |
bc95f62b WD |
281 | /* If the pattern does not have any slashes AND it does not have |
282 | * a "**" (which could match a slash), then we just match the | |
283 | * name portion of the path. */ | |
284 | - if (!ex->slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) { | |
285 | + if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) { | |
286 | if ((p = strrchr(name,'/')) != NULL) | |
287 | name = p+1; | |
288 | } | |
eabda998 | 289 | @@ -148,9 +324,9 @@ static int check_one_exclude(char *name, |
bc95f62b WD |
290 | if (ex->match_flags & MATCHFLG_WILD) { |
291 | /* A non-anchored match with an infix slash and no "**" | |
292 | * needs to match the last slash_cnt+1 name elements. */ | |
0c7d1fd8 WD |
293 | - if (!match_start && ex->slash_cnt |
294 | + if (!match_start && ex->u.slash_cnt | |
295 | && !(ex->match_flags & MATCHFLG_WILD2)) { | |
bc95f62b WD |
296 | - int cnt = ex->slash_cnt + 1; |
297 | + int cnt = ex->u.slash_cnt + 1; | |
298 | for (p = name + strlen(name) - 1; p >= name; p--) { | |
299 | if (*p == '/' && !--cnt) | |
300 | break; | |
eabda998 | 301 | @@ -221,6 +397,13 @@ int check_exclude(struct exclude_list_st |
a55d21aa WD |
302 | struct exclude_struct *ent; |
303 | ||
304 | for (ent = listp->head; ent; ent = ent->next) { | |
524989ae | 305 | + if (ent->match_flags & MATCHFLG_MERGE_FILE) { |
eabda998 | 306 | + int rc = check_exclude(ent->u.mergelist, name, |
d8af8661 | 307 | + name_is_dir); |
a55d21aa WD |
308 | + if (rc) |
309 | + return rc; | |
310 | + continue; | |
311 | + } | |
312 | if (check_one_exclude(name, ent, name_is_dir)) { | |
313 | report_exclude_result(name, ent, name_is_dir, | |
314 | listp->debug_type); | |
066e3b3e | 315 | @@ -253,11 +436,16 @@ static const char *get_exclude_tok(const |
a55d21aa WD |
316 | p = (const char *)s; |
317 | } | |
318 | ||
319 | - /* Is this a '+' or '-' followed by a space (not whitespace)? */ | |
320 | + /* Is this a +/-/. followed by a space (not whitespace)? */ | |
ee1af13c | 321 | if (!(xflags & XFLG_WORDS_ONLY) |
a55d21aa | 322 | - && (*s == '-' || *s == '+') && s[1] == ' ') { |
a55d21aa | 323 | + && (*s == '-' || *s == '+' || *s == '.') && s[1] == ' ') { |
0c7d1fd8 WD |
324 | if (*s == '+') |
325 | mflags |= MATCHFLG_INCLUDE; | |
a55d21aa | 326 | + else if (*s == '.') { |
524989ae | 327 | + mflags |= MATCHFLG_MERGE_FILE; |
a55d21aa WD |
328 | + if (xflags & XFLG_DEF_INCLUDE) |
329 | + mflags |= MATCHFLG_INCLUDE; | |
330 | + } | |
331 | s += 2; | |
0c7d1fd8 WD |
332 | } else if (xflags & XFLG_DEF_INCLUDE) |
333 | mflags |= MATCHFLG_INCLUDE; | |
066e3b3e | 334 | @@ -306,11 +494,42 @@ void add_exclude(struct exclude_list_str |
0c7d1fd8 WD |
335 | continue; |
336 | } | |
a55d21aa | 337 | |
524989ae | 338 | + if (mflags & MATCHFLG_MERGE_FILE) { |
a55d21aa | 339 | + char name[MAXPATHLEN]; |
bc95f62b WD |
340 | + if (pat_len >= sizeof name) { |
341 | + rprintf(FERROR, | |
342 | + "merge filename too long: %s\n", cp); | |
343 | + continue; | |
344 | + } | |
a55d21aa | 345 | + strlcpy(name, cp, pat_len+1); |
524989ae | 346 | + if (strchr(name, '/') != NULL) { |
a55d21aa WD |
347 | + if (sanitize_paths) |
348 | + sanitize_path(name, curr_dir); | |
349 | + if (*name == '/') | |
350 | + cp = name; | |
351 | + else { | |
352 | + if (strlcpy(dirbuf + dirbuf_offset, | |
353 | + name, MAXPATHLEN - dirbuf_offset) | |
bc95f62b WD |
354 | + >= MAXPATHLEN - dirbuf_offset) { |
355 | + rprintf(FERROR, | |
356 | + "merge filename too long: %s...\n", | |
357 | + dirbuf); | |
358 | + continue; | |
359 | + } | |
a55d21aa WD |
360 | + cp = dirbuf; |
361 | + } | |
362 | + add_exclude_file(listp, cp, | |
363 | + xflags | XFLG_FATAL_ERRORS); | |
364 | + continue; | |
0c7d1fd8 WD |
365 | + } |
366 | + } | |
a55d21aa | 367 | + |
0c7d1fd8 WD |
368 | make_exclude(listp, cp, pat_len, mflags); |
369 | ||
370 | if (verbose > 2) { | |
371 | - rprintf(FINFO, "[%s] add_exclude(%.*s, %s%sclude)\n", | |
a55d21aa | 372 | + rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s%sclude)\n", |
eabda998 | 373 | who_am_i(), (int)pat_len, cp, listp->debug_type, |
524989ae | 374 | + mflags & MATCHFLG_MERGE_FILE ? "FILE " : "", |
0c7d1fd8 | 375 | mflags & MATCHFLG_INCLUDE ? "in" : "ex"); |
a55d21aa | 376 | } |
0c7d1fd8 | 377 | } |
066e3b3e | 378 | @@ -402,7 +621,11 @@ void send_exclude_list(int f) |
0c7d1fd8 | 379 | if (ent->match_flags & MATCHFLG_INCLUDE) { |
a55d21aa WD |
380 | write_int(f, l + 2); |
381 | write_buf(f, "+ ", 2); | |
382 | - } else if ((*p == '-' || *p == '+') && p[1] == ' ') { | |
524989ae | 383 | + } else if (ent->match_flags & MATCHFLG_MERGE_FILE) { |
a55d21aa WD |
384 | + write_int(f, l + 2); |
385 | + write_buf(f, ". ", 2); | |
386 | + } else if ((*p == '-' || *p == '+' || *p == '.') | |
387 | + && p[1] == ' ') { | |
388 | write_int(f, l + 2); | |
389 | write_buf(f, "- ", 2); | |
390 | } else | |
066e3b3e | 391 | @@ -443,6 +666,7 @@ void add_cvs_excludes(void) |
a55d21aa WD |
392 | char fname[MAXPATHLEN]; |
393 | char *p; | |
394 | ||
395 | + add_exclude(&exclude_list, ". .cvsignore", 0); | |
396 | add_exclude(&exclude_list, default_cvsignore, | |
ee1af13c | 397 | XFLG_WORD_SPLIT | XFLG_WORDS_ONLY); |
a55d21aa | 398 | |
eabda998 | 399 | --- flist.c 21 May 2004 23:22:14 -0000 1.225 |
066e3b3e | 400 | +++ flist.c 22 May 2004 06:02:55 -0000 |
a55d21aa WD |
401 | @@ -39,8 +39,6 @@ extern int module_id; |
402 | extern int ignore_errors; | |
403 | extern int numeric_ids; | |
404 | ||
405 | -extern int cvs_exclude; | |
406 | - | |
407 | extern int recurse; | |
408 | extern char curr_dir[MAXPATHLEN]; | |
409 | extern char *files_from; | |
7cb7ae4e | 410 | @@ -65,7 +63,6 @@ extern int write_batch; |
a55d21aa WD |
411 | |
412 | extern struct exclude_list_struct exclude_list; | |
413 | extern struct exclude_list_struct server_exclude_list; | |
414 | -extern struct exclude_list_struct local_exclude_list; | |
415 | ||
416 | int io_error; | |
417 | ||
7cb7ae4e | 418 | @@ -210,8 +207,6 @@ int link_stat(const char *path, STRUCT_S |
a55d21aa WD |
419 | */ |
420 | static int check_exclude_file(char *fname, int is_dir, int exclude_level) | |
421 | { | |
422 | - int rc; | |
423 | - | |
424 | #if 0 /* This currently never happens, so avoid a useless compare. */ | |
425 | if (exclude_level == NO_EXCLUDES) | |
426 | return 0; | |
7cb7ae4e | 427 | @@ -233,10 +228,7 @@ static int check_exclude_file(char *fnam |
a55d21aa WD |
428 | if (exclude_level != ALL_EXCLUDES) |
429 | return 0; | |
430 | if (exclude_list.head | |
431 | - && (rc = check_exclude(&exclude_list, fname, is_dir)) != 0) | |
432 | - return rc < 0; | |
433 | - if (local_exclude_list.head | |
434 | - && check_exclude(&local_exclude_list, fname, is_dir) < 0) | |
435 | + && check_exclude(&exclude_list, fname, is_dir) < 0) | |
436 | return 1; | |
437 | return 0; | |
438 | } | |
eabda998 | 439 | @@ -942,15 +934,7 @@ void send_file_name(int f, struct file_l |
a55d21aa WD |
440 | |
441 | if (recursive && S_ISDIR(file->mode) | |
442 | && !(file->flags & FLAG_MOUNT_POINT)) { | |
443 | - struct exclude_list_struct last_list = local_exclude_list; | |
444 | - local_exclude_list.head = local_exclude_list.tail = NULL; | |
445 | send_directory(f, flist, f_name_to(file, fbuf)); | |
7cb7ae4e WD |
446 | - if (verbose > 2) { |
447 | - rprintf(FINFO, "[%s] popping %sexclude list\n", | |
448 | - who_am_i(), local_exclude_list.debug_type); | |
449 | - } | |
d8af8661 | 450 | - clear_exclude_list(&local_exclude_list); |
a55d21aa WD |
451 | - local_exclude_list = last_list; |
452 | } | |
453 | } | |
454 | ||
eabda998 | 455 | @@ -961,6 +945,7 @@ static void send_directory(int f, struct |
a55d21aa WD |
456 | struct dirent *di; |
457 | char fname[MAXPATHLEN]; | |
458 | unsigned int offset; | |
459 | + void *save_excludes; | |
460 | char *p; | |
461 | ||
462 | d = opendir(dir); | |
eabda998 | 463 | @@ -984,18 +969,7 @@ static void send_directory(int f, struct |
a55d21aa WD |
464 | offset++; |
465 | } | |
466 | ||
467 | - if (cvs_exclude) { | |
468 | - if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset) | |
469 | - < MAXPATHLEN - offset) { | |
470 | - add_exclude_file(&local_exclude_list, fname, | |
ee1af13c | 471 | - XFLG_WORD_SPLIT | XFLG_WORDS_ONLY); |
a55d21aa WD |
472 | - } else { |
473 | - io_error |= IOERR_GENERAL; | |
474 | - rprintf(FINFO, | |
475 | - "cannot cvs-exclude in long-named directory %s\n", | |
476 | - full_fname(fname)); | |
477 | - } | |
478 | - } | |
479 | + save_excludes = push_local_excludes(fname, offset); | |
480 | ||
481 | for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) { | |
482 | char *dname = d_name(di); | |
eabda998 | 483 | @@ -1016,6 +990,8 @@ static void send_directory(int f, struct |
bc95f62b | 484 | rsyserr(FERROR, errno, "readdir(%s)", dir); |
a55d21aa | 485 | } |
a55d21aa | 486 | |
eabda998 WD |
487 | + pop_local_excludes(save_excludes); |
488 | + | |
a55d21aa WD |
489 | closedir(d); |
490 | } | |
eabda998 | 491 | |
0c7d1fd8 | 492 | --- rsync.h 16 May 2004 07:28:24 -0000 1.204 |
066e3b3e | 493 | +++ rsync.h 22 May 2004 06:02:56 -0000 |
d8af8661 | 494 | @@ -496,11 +496,16 @@ struct map_struct { |
0c7d1fd8 WD |
495 | #define MATCHFLG_INCLUDE (1<<4) /* this is an include, not an exclude */ |
496 | #define MATCHFLG_DIRECTORY (1<<5) /* this matches only directories */ | |
497 | #define MATCHFLG_CLEAR_LIST (1<<6) /* this item is the "!" token */ | |
524989ae | 498 | +#define MATCHFLG_MERGE_FILE (1<<7) /* specifies a file to merge */ |
a55d21aa WD |
499 | +#define MATCHFLG_CVSIGNORE (1<<8) /* parse this as a .cvsignore file */ |
500 | struct exclude_struct { | |
501 | struct exclude_struct *next; | |
502 | char *pattern; | |
0c7d1fd8 | 503 | unsigned int match_flags; |
bc95f62b | 504 | - int slash_cnt; |
bc95f62b WD |
505 | + union { |
506 | + int slash_cnt; | |
eabda998 | 507 | + struct exclude_list_struct *mergelist; |
bc95f62b | 508 | + } u; |
a55d21aa WD |
509 | }; |
510 | ||
511 | struct exclude_list_struct { | |
eabda998 | 512 | --- rsync.yo 21 May 2004 09:44:32 -0000 1.170 |
066e3b3e | 513 | +++ rsync.yo 22 May 2004 06:02:57 -0000 |
eabda998 | 514 | @@ -1090,6 +1090,72 @@ itemize( |
524989ae WD |
515 | it would be excluded by the "*") |
516 | ) | |
517 | ||
518 | +manpagesection(MERGING EXCLUDE FILES) | |
519 | + | |
520 | +You can merge whole files into an exclude file using a rule that starts | |
521 | +with a ". " (a dot followed by a space) and has a filename in place of the | |
522 | +pattern. There are two types of merge rules, single-instance and | |
523 | +per-directory: | |
524 | + | |
525 | +itemize( | |
526 | + it() If the filename has no slashes in it, it is a per-directory merge; | |
bc95f62b WD |
527 | + rsync scans every directory that it traverses for the named file, merging |
528 | + its contents (when it exists) file at the start of this per-directory | |
529 | + sub-list (subdirectories inherit the contents of their parent directories | |
530 | + by default, and each subdirectory's rules have precedence over the parent | |
531 | + directory's rules). | |
524989ae WD |
532 | + |
533 | + it() If a filename has a slash in it, it is a single-instance merge; the | |
534 | + named file's contents will be merged into the current exclude file, | |
535 | + replacing the merge rule. Thus, you should use the name ./foo instead of | |
536 | + foo if you don't want to scan for "foo" in all the subdirectories of the | |
537 | + current directory. | |
538 | +) | |
539 | + | |
540 | +Note also that you can eliminate all the inherited rules for the current | |
541 | +per-directory ruleset by putting the list-clearing token (!) in the file. | |
bc95f62b WD |
542 | +This only clears the rules for the current per-directory sub-list (up |
543 | +through the ! token) and only for the current directory and its | |
524989ae WD |
544 | +subdirectories. |
545 | + | |
bc95f62b WD |
546 | +Here's an example exclude file (which you'd specify via the normal |
547 | +--exclude-from option): | |
524989ae WD |
548 | + |
549 | +verb( | |
550 | + . /home/user/.global_excludes | |
551 | + - *.gz | |
552 | + . .excl | |
553 | + + *.[ch] | |
554 | + - *.o | |
555 | +) | |
556 | + | |
557 | +This will merge the contents of the /home/user/.global_excludes file at the | |
558 | +start of the list and also turns the ".excl" filename into a per-directory | |
559 | +exclude file whose local contents will be merged into the list in place of | |
560 | +the .excl line. | |
561 | + | |
562 | +Additionally, you can affect where the --cvs-exclude (-C) option's | |
563 | +inclusion of a per-directory .cvsignore file gets placed into your rules by | |
bc95f62b | 564 | +adding an explicit merge rule for ".cvsignore". For instance, specifying |
524989ae WD |
565 | +this: |
566 | + | |
567 | +verb( | |
568 | + rsync -avC --exclude='. .cvsignore' --exclude-from=foo a/ b | |
569 | +) | |
570 | + | |
571 | +will merge all the per-directory .cvsignore rules at the start of your list | |
572 | +rather than at the end. This allows their dir-specific rules to supersede | |
573 | +your rules instead of being subservient to them. (The global rules taken | |
574 | +from the $HOME/.cvsignore file and from $CVSIGNORE are not affected by | |
575 | +this.) | |
576 | + | |
577 | +Note also that the parsing of any merge-file named ".cvsignore" is always | |
578 | +done in a CVS-compatible manner (even if -C wasn't specified) -- i.e. the | |
579 | +rules are always exclude rules (even when specified by an include option), | |
580 | +they are split on whitespace, no special prefixes or list-clearing tokens | |
581 | +are honored, and (for per-directory files) subdirectories don't inherit the | |
582 | +parent directory's rules. | |
583 | + | |
584 | manpagesection(BATCH MODE) | |
585 | ||
586 | bf(Note:) Batch mode should be considered experimental in this version |