summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-05-24 10:11:07 +0200
committerJunio C Hamano <gitster@pobox.com>2016-06-01 10:10:16 -0700
commit82f0dfca542e95b74ff967f10fb4247e11a2d9d9 (patch)
tree6e93ab00327b9ad839b4aa1c51dc10424b7a2a28
parentb802355863814b331ffc4ae029b228472e874d1f (diff)
downloadgit-82f0dfca542e95b74ff967f10fb4247e11a2d9d9.tar.gz
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>
-rw-r--r--builtin/apply.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index fa9002898c..0e3de17d05 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -52,6 +52,9 @@ struct apply_state {
const char *patch_input_file;
int line_termination;
unsigned int p_context;
+
+ /* Exclude and include path parameters */
+ struct string_list limit_by_name;
};
static int newfd = -1;
@@ -1958,13 +1961,14 @@ static void prefix_patch(struct apply_state *state, struct patch *p)
* include/exclude
*/
-static struct string_list limit_by_name;
static int has_include;
-static void add_name_limit(const char *name, int exclude)
+static void add_name_limit(struct apply_state *state,
+ const char *name,
+ int exclude)
{
struct string_list_item *it;
- it = string_list_append(&limit_by_name, name);
+ it = string_list_append(&state->limit_by_name, name);
it->util = exclude ? NULL : (void *) 1;
}
@@ -1982,8 +1986,8 @@ static int use_patch(struct apply_state *state, struct patch *p)
}
/* See if it matches any of exclude/include rule */
- for (i = 0; i < limit_by_name.nr; i++) {
- struct string_list_item *it = &limit_by_name.items[i];
+ for (i = 0; i < state->limit_by_name.nr; i++) {
+ struct string_list_item *it = &state->limit_by_name.items[i];
if (!wildmatch(it->string, pathname, 0, NULL))
return (it->util != NULL);
}
@@ -4520,14 +4524,16 @@ static void git_apply_config(void)
static int option_parse_exclude(const struct option *opt,
const char *arg, int unset)
{
- add_name_limit(arg, 1);
+ struct apply_state *state = opt->value;
+ add_name_limit(state, arg, 1);
return 0;
}
static int option_parse_include(const struct option *opt,
const char *arg, int unset)
{
- add_name_limit(arg, 0);
+ struct apply_state *state = opt->value;
+ add_name_limit(state, arg, 0);
has_include = 1;
return 0;
}
@@ -4587,7 +4593,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
static void clear_apply_state(struct apply_state *state)
{
- /* empty for now */
+ string_list_clear(&state->limit_by_name, 0);
}
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)
const char *whitespace_option = NULL;
struct option builtin_apply_options[] = {
- { OPTION_CALLBACK, 0, "exclude", NULL, N_("path"),
+ { OPTION_CALLBACK, 0, "exclude", &state, N_("path"),
N_("don't apply changes matching the given path"),
0, option_parse_exclude },
- { OPTION_CALLBACK, 0, "include", NULL, N_("path"),
+ { OPTION_CALLBACK, 0, "include", &state, N_("path"),
N_("apply changes matching the given path"),
0, option_parse_include },
{ OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),