builtin/apply: move 'limit_by_name' global into 'struct apply_state'
To libify the apply functionality the 'limit_by_name' variable should not be static and global to the file. Let's move it into 'struct apply_state'. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 24, 2016 at 10:11 UTC
82f0dfca542e95b74ff967f10fb4247e11a2d9d9
1 file changed
+16
-10
builtin/apply.c
+16
-10
@@ -52,6 +52,9 @@ struct apply_state {
52
const char *patch_input_file;
53
int line_termination;
54
unsigned int p_context;
55
+
56
+ /* Exclude and include path parameters */
57
+ struct string_list limit_by_name;
58
};
59
60
static int newfd = -1;
@@ -1958,13 +1961,14 @@ static void prefix_patch(struct apply_state *state, struct patch *p)
1961
* include/exclude
1962
*/
1963
1961
-static struct string_list limit_by_name;
1964
static int has_include;
1963
-static void add_name_limit(const char *name, int exclude)
1965
+static void add_name_limit(struct apply_state *state,
1966
+ const char *name,
1967
+ int exclude)
1968
{
1969
struct string_list_item *it;
1970
1967
- it = string_list_append(&limit_by_name, name);
1971
+ it = string_list_append(&state->limit_by_name, name);
1972
it->util = exclude ? NULL : (void *) 1;
1973
}
1974
@@ -1982,8 +1986,8 @@ static int use_patch(struct apply_state *state, struct patch *p)
1986
}
1987
1988
/* See if it matches any of exclude/include rule */
1985
- for (i = 0; i < limit_by_name.nr; i++) {
1986
- struct string_list_item *it = &limit_by_name.items[i];
1989
+ for (i = 0; i < state->limit_by_name.nr; i++) {
1990
+ struct string_list_item *it = &state->limit_by_name.items[i];
1991
if (!wildmatch(it->string, pathname, 0, NULL))
1992
return (it->util != NULL);
1993
}
@@ -4520,14 +4524,16 @@ static void git_apply_config(void)
4524
static int option_parse_exclude(const struct option *opt,
4525
const char *arg, int unset)
4526
{
4523
- add_name_limit(arg, 1);
4527
+ struct apply_state *state = opt->value;
4528
+ add_name_limit(state, arg, 1);
4529
return 0;
4530
}
4531
4532
static int option_parse_include(const struct option *opt,
4533
const char *arg, int unset)
4534
{
4530
- add_name_limit(arg, 0);
4535
+ struct apply_state *state = opt->value;
4536
+ add_name_limit(state, arg, 0);
4537
has_include = 1;
4538
return 0;
4539
}
@@ -4587,7 +4593,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
4593
4594
static void clear_apply_state(struct apply_state *state)
4595
{
4590
- /* empty for now */
4596
+ string_list_clear(&state->limit_by_name, 0);
4597
}
4598
4599
int cmd_apply(int argc, const char **argv, const char *prefix)
@@ -4603,10 +4609,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4609
const char *whitespace_option = NULL;
4610
4611
struct option builtin_apply_options[] = {
4606
- { OPTION_CALLBACK, 0, "exclude", NULL, N_("path"),
4612
+ { OPTION_CALLBACK, 0, "exclude", &state, N_("path"),
4613
N_("don't apply changes matching the given path"),
4614
0, option_parse_exclude },
4609
- { OPTION_CALLBACK, 0, "include", NULL, N_("path"),
4615
+ { OPTION_CALLBACK, 0, "include", &state, N_("path"),
4616
N_("apply changes matching the given path"),
4617
0, option_parse_include },
4618
{ OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),