summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-05-24 08:10:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-01 17:10:16 (GMT)
commit6f27b941f2664c1653d0c4edcec5686119f0c023 (patch)
treeef2233617d2fd5e3b79ededbdccb0df566697aaa /builtin/apply.c
parent2fc0f1849bd0d6100719bb53f89f15fbd734157a (diff)
downloadgit-6f27b941f2664c1653d0c4edcec5686119f0c023.zip
git-6f27b941f2664c1653d0c4edcec5686119f0c023.tar.gz
git-6f27b941f2664c1653d0c4edcec5686119f0c023.tar.bz2
builtin/apply: move 'state' init into init_apply_state()
When the apply functionality will be libified, the 'struct apply_state' will be used by different pieces of code. To properly initialize a 'struct apply_state', let's provide a nice and easy to use init_apply_state() function. Let's also provide clear_apply_state() to release memory used by 'struct apply_state' members, so that a 'struct apply_state' instance can be easily reused without leaking memory. Note that clear_apply_state() does nothing for now, but it will later. While at it, let's rename 'prefix_' parameter to 'prefix'. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r--builtin/apply.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index ae068e7..52b5d3e 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -4522,7 +4522,25 @@ static int option_parse_directory(const struct option *opt,
return 0;
}
-int cmd_apply(int argc, const char **argv, const char *prefix_)
+static void init_apply_state(struct apply_state *state, const char *prefix)
+{
+ memset(state, 0, sizeof(*state));
+ state->prefix = prefix;
+ state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
+
+ git_apply_config();
+ if (apply_default_whitespace)
+ parse_whitespace_option(apply_default_whitespace);
+ if (apply_default_ignorewhitespace)
+ parse_ignorewhitespace_option(apply_default_ignorewhitespace);
+}
+
+static void clear_apply_state(struct apply_state *state)
+{
+ /* empty for now */
+}
+
+int cmd_apply(int argc, const char **argv, const char *prefix)
{
int i;
int errs = 0;
@@ -4603,15 +4621,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
OPT_END()
};
- memset(&state, 0, sizeof(state));
- state.prefix = prefix_;
- state.prefix_length = state.prefix ? strlen(state.prefix) : 0;
-
- git_apply_config();
- if (apply_default_whitespace)
- parse_whitespace_option(apply_default_whitespace);
- if (apply_default_ignorewhitespace)
- parse_ignorewhitespace_option(apply_default_ignorewhitespace);
+ init_apply_state(&state, prefix);
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
apply_usage, 0);
@@ -4695,5 +4705,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
die(_("Unable to write new index file"));
}
+ clear_apply_state(&state);
+
return !!errs;
}