2994
2995
static struct lock_file lock_file;
2996
2997
-static struct excludes {
2998
- struct excludes *next;
2999
- const char *path;
3000
-} *excludes;
2997
+static struct string_list limit_by_name;
2998
+static int has_include;
2999
+static void add_name_limit(const char *name, int exclude)
3000
+{
3001
+ struct string_list_item *it;
3002
+
3003
+ it = string_list_append(name, &limit_by_name);
3004
+ it->util = exclude ? NULL : (void *) 1;
3005
+}
3006
3007
static int use_patch(struct patch *p)
3008
{
3009
const char *pathname = p->new_name ? p->new_name : p->old_name;
3005
- struct excludes *x = excludes;
3006
- while (x) {
3007
- if (fnmatch(x->path, pathname, 0) == 0)
3008
- return 0;
3009
- x = x->next;
3010
- }
3010
+ int i;
3011
+
3012
+ /* Paths outside are not touched regardless of "--include" */
3013
if (0 < prefix_length) {
3014
int pathlen = strlen(pathname);
3015
if (pathlen <= prefix_length ||
3016
memcmp(prefix, pathname, prefix_length))
3017
return 0;
3018
}
3017
- return 1;
3019
+
3020
+ /* See if it matches any of exclude/include rule */
3021
+ for (i = 0; i < limit_by_name.nr; i++) {
3022
+ struct string_list_item *it = &limit_by_name.items[i];
3023
+ if (!fnmatch(it->string, pathname, 0))
3024
+ return (it->util != NULL);
3025
+ }
3026
+
3027
+ /*
3028
+ * If we had any include, a path that does not match any rule is
3029
+ * not used. Otherwise, we saw bunch of exclude rules (or none)
3030
+ * and such a path is used.
3031
+ */
3032
+ return !has_include;
3033
}
3034
3035
+
3036
static void prefix_one(char **name)
3037
{
3038
char *old_name = *name;
3173
continue;
3174
}
3175
if (!prefixcmp(arg, "--exclude=")) {
3160
- struct excludes *x = xmalloc(sizeof(*x));
3161
- x->path = arg + 10;
3162
- x->next = excludes;
3163
- excludes = x;
3176
+ add_name_limit(arg + 10, 1);
3177
+ continue;
3178
+ }
3179
+ if (!prefixcmp(arg, "--include=")) {
3180
+ add_name_limit(arg + 10, 0);
3181
+ has_include = 1;
3182
continue;
3183
}
3184
if (!prefixcmp(arg, "-p")) {