]> granicus.if.org Git - git/commitdiff
Merge branch 'jk/string-list-static-init'
authorJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2016 20:38:07 +0000 (13:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2016 20:38:08 +0000 (13:38 -0700)
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

1  2 
builtin/apply.c
builtin/blame.c
builtin/log.c
builtin/remote.c
t/helper/test-parse-options.c

diff --cc builtin/apply.c
index ecb7f1b258cb802c934dc37f8d6af511e7b33ed1,955af4db6cc11321cae85bf320ea25fb1220d4d6..7fc5c3e30745d50a05accb3a83ccfa8871963df6
@@@ -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 builtin/blame.c
Simple merge
diff --cc builtin/log.c
Simple merge
Simple merge
index 8a1235d03e2daab4b9e90d31c5da6708e5c712f2,37a196781dc1a53b925dd68235fe17284978777e..2c63298fab10563bcd8c98c3d0b6d563164e2283
@@@ -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 */