Skip to content

Commit 3ee2ad1

Browse files
committed
apply: hoist use_patch() helper for path exclusion up
We will be adding a caller to the function a bit earlier in this file in a later patch. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d487b0b commit 3ee2ad1

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

builtin/apply.c

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,49 @@ static void prefix_patch(struct patch *p)
19371937
prefix_one(&p->old_name);
19381938
}
19391939

1940+
/*
1941+
* include/exclude
1942+
*/
1943+
1944+
static struct string_list limit_by_name;
1945+
static int has_include;
1946+
static void add_name_limit(const char *name, int exclude)
1947+
{
1948+
struct string_list_item *it;
1949+
1950+
it = string_list_append(&limit_by_name, name);
1951+
it->util = exclude ? NULL : (void *) 1;
1952+
}
1953+
1954+
static int use_patch(struct patch *p)
1955+
{
1956+
const char *pathname = p->new_name ? p->new_name : p->old_name;
1957+
int i;
1958+
1959+
/* Paths outside are not touched regardless of "--include" */
1960+
if (0 < prefix_length) {
1961+
int pathlen = strlen(pathname);
1962+
if (pathlen <= prefix_length ||
1963+
memcmp(prefix, pathname, prefix_length))
1964+
return 0;
1965+
}
1966+
1967+
/* See if it matches any of exclude/include rule */
1968+
for (i = 0; i < limit_by_name.nr; i++) {
1969+
struct string_list_item *it = &limit_by_name.items[i];
1970+
if (!fnmatch(it->string, pathname, 0))
1971+
return (it->util != NULL);
1972+
}
1973+
1974+
/*
1975+
* If we had any include, a path that does not match any rule is
1976+
* not used. Otherwise, we saw bunch of exclude rules (or none)
1977+
* and such a path is used.
1978+
*/
1979+
return !has_include;
1980+
}
1981+
1982+
19401983
/*
19411984
* Read the patch text in "buffer" that extends for "size" bytes; stop
19421985
* reading after seeing a single patch (i.e. changes to a single file).
@@ -4145,44 +4188,6 @@ static int write_out_results(struct patch *list)
41454188

41464189
static struct lock_file lock_file;
41474190

4148-
static struct string_list limit_by_name;
4149-
static int has_include;
4150-
static void add_name_limit(const char *name, int exclude)
4151-
{
4152-
struct string_list_item *it;
4153-
4154-
it = string_list_append(&limit_by_name, name);
4155-
it->util = exclude ? NULL : (void *) 1;
4156-
}
4157-
4158-
static int use_patch(struct patch *p)
4159-
{
4160-
const char *pathname = p->new_name ? p->new_name : p->old_name;
4161-
int i;
4162-
4163-
/* Paths outside are not touched regardless of "--include" */
4164-
if (0 < prefix_length) {
4165-
int pathlen = strlen(pathname);
4166-
if (pathlen <= prefix_length ||
4167-
memcmp(prefix, pathname, prefix_length))
4168-
return 0;
4169-
}
4170-
4171-
/* See if it matches any of exclude/include rule */
4172-
for (i = 0; i < limit_by_name.nr; i++) {
4173-
struct string_list_item *it = &limit_by_name.items[i];
4174-
if (!fnmatch(it->string, pathname, 0))
4175-
return (it->util != NULL);
4176-
}
4177-
4178-
/*
4179-
* If we had any include, a path that does not match any rule is
4180-
* not used. Otherwise, we saw bunch of exclude rules (or none)
4181-
* and such a path is used.
4182-
*/
4183-
return !has_include;
4184-
}
4185-
41864191
#define INACCURATE_EOF (1<<0)
41874192
#define RECOUNT (1<<1)
41884193

0 commit comments

Comments
 (0)