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