From: Junio C Hamano Date: Wed, 6 Jul 2016 20:38:07 +0000 (-0700) Subject: Merge branch 'jk/string-list-static-init' X-Git-Tag: v2.10.0-rc0~166 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8b6365a8a214f2427f2cf9334fd43ace0be619c;p=git Merge branch 'jk/string-list-static-init' Instead of taking advantage of a struct string_list that is allocated with all NULs happens to be STRING_LIST_INIT_NODUP kind, initialize them explicitly as such, to document their behaviour better. * jk/string-list-static-init: use string_list initializer consistently blame,shortlog: don't make local option variables static interpret-trailers: don't duplicate option strings parse_opt_string_list: stop allocating new strings --- b8b6365a8a214f2427f2cf9334fd43ace0be619c diff --cc builtin/apply.c index ecb7f1b258,955af4db6c..7fc5c3e307 --- a/builtin/apply.c +++ b/builtin/apply.c @@@ -4650,75 -4495,7 +4650,78 @@@ static int option_parse_directory(cons 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, + struct lock_file *lock_file) +{ + memset(state, 0, sizeof(*state)); + state->prefix = prefix; + state->prefix_length = state->prefix ? strlen(state->prefix) : 0; + state->lock_file = lock_file; + state->newfd = -1; + state->apply = 1; + state->line_termination = '\n'; + state->p_value = 1; + state->p_context = UINT_MAX; + state->squelch_whitespace_errors = 5; + state->ws_error_action = warn_on_ws_error; + state->ws_ignore_action = ignore_ws_none; + state->linenr = 1; ++ string_list_init(&state->fn_table, 0); ++ string_list_init(&state->limit_by_name, 0); ++ string_list_init(&state->symlink_changes, 0); + strbuf_init(&state->root, 0); + + git_apply_config(); + if (apply_default_whitespace) + parse_whitespace_option(state, apply_default_whitespace); + if (apply_default_ignorewhitespace) + parse_ignorewhitespace_option(state, apply_default_ignorewhitespace); +} + +static void clear_apply_state(struct apply_state *state) +{ + string_list_clear(&state->limit_by_name, 0); + string_list_clear(&state->symlink_changes, 0); + strbuf_release(&state->root); + + /* &state->fn_table is cleared at the end of apply_patch() */ +} + +static void check_apply_state(struct apply_state *state, int force_apply) +{ + int is_not_gitdir = !startup_info->have_repository; + + if (state->apply_with_reject && state->threeway) + die("--reject and --3way cannot be used together."); + if (state->cached && state->threeway) + die("--cached and --3way cannot be used together."); + if (state->threeway) { + if (is_not_gitdir) + die(_("--3way outside a repository")); + state->check_index = 1; + } + if (state->apply_with_reject) + state->apply = state->apply_verbosely = 1; + if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor)) + state->apply = 0; + if (state->check_index && is_not_gitdir) + die(_("--index outside a repository")); + if (state->cached) { + if (is_not_gitdir) + die(_("--cached outside a repository")); + state->check_index = 1; + } + if (state->check_index) + state->unsafe_paths = 0; + if (!state->lock_file) + die("BUG: state->lock_file should not be NULL"); +} + +static int apply_all_patches(struct apply_state *state, + int argc, + const char **argv, + int options) { int i; int errs = 0; diff --cc t/helper/test-parse-options.c index 8a1235d03e,37a196781d..2c63298fab --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@@ -12,20 -11,12 +12,20 @@@ static int dry_run = 0, quiet = 0 static char *string = NULL; static char *file = NULL; static int ambiguous; - static struct string_list list; + static struct string_list list = STRING_LIST_INIT_NODUP; +static struct { + int called; + const char *arg; + int unset; +} length_cb; + static int length_callback(const struct option *opt, const char *arg, int unset) { - printf("Callback: \"%s\", %d\n", - (arg ? arg : "not set"), unset); + length_cb.called = 1; + length_cb.arg = arg; + length_cb.unset = unset; + if (unset) return 1; /* do not support unset */