Merge branch 'ab/wildmatch'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Jul 2017 20:42:51 +0000 (13:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jul 2017 20:42:51 +0000 (13:42 -0700)
Minor code cleanup.

* ab/wildmatch:
wildmatch: remove unused wildopts parameter

1  2 
apply.c
builtin/describe.c
builtin/name-rev.c
builtin/reflog.c
builtin/replace.c
builtin/show-branch.c
config.c
dir.c
ref-filter.c
refs.c
revision.c
diff --combined apply.c
index 946be4d2f553813a3df7b513c816f002591fd89f,bb411b5810d9550c16689bf77101e0f40c49ac6e..4050cebcfacc233f6d449221ec5c44b3551a4678
+++ b/apply.c
@@@ -8,7 -8,6 +8,7 @@@
   */
  
  #include "cache.h"
 +#include "config.h"
  #include "blob.h"
  #include "delta.h"
  #include "diff.h"
@@@ -211,7 -210,6 +211,7 @@@ struct patch 
        unsigned ws_rule;
        int lines_added, lines_deleted;
        int score;
 +      int extension_linenr; /* first line specifying delete/new/rename/copy */
        unsigned int is_toplevel_relative:1;
        unsigned int inaccurate_eof:1;
        unsigned int is_binary:1;
@@@ -976,7 -974,8 +976,7 @@@ static int gitdiff_verify_name(struct a
                }
                free(another);
        } else {
 -              /* expect "/dev/null" */
 -              if (memcmp("/dev/null", line, 9) || line[9] != '\n')
 +              if (!starts_with(line, "/dev/null\n"))
                        return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr);
        }
  
@@@ -1001,27 -1000,20 +1001,27 @@@ static int gitdiff_newname(struct apply
                                   DIFF_NEW_NAME);
  }
  
 +static int parse_mode_line(const char *line, int linenr, unsigned int *mode)
 +{
 +      char *end;
 +      *mode = strtoul(line, &end, 8);
 +      if (end == line || !isspace(*end))
 +              return error(_("invalid mode on line %d: %s"), linenr, line);
 +      return 0;
 +}
 +
  static int gitdiff_oldmode(struct apply_state *state,
                           const char *line,
                           struct patch *patch)
  {
 -      patch->old_mode = strtoul(line, NULL, 8);
 -      return 0;
 +      return parse_mode_line(line, state->linenr, &patch->old_mode);
  }
  
  static int gitdiff_newmode(struct apply_state *state,
                           const char *line,
                           struct patch *patch)
  {
 -      patch->new_mode = strtoul(line, NULL, 8);
 -      return 0;
 +      return parse_mode_line(line, state->linenr, &patch->new_mode);
  }
  
  static int gitdiff_delete(struct apply_state *state,
@@@ -1135,7 -1127,7 +1135,7 @@@ static int gitdiff_index(struct apply_s
        memcpy(patch->new_sha1_prefix, line, len);
        patch->new_sha1_prefix[len] = 0;
        if (*ptr == ' ')
 -              patch->old_mode = strtoul(ptr+1, NULL, 8);
 +              return gitdiff_oldmode(state, ptr + 1, patch);
        return 0;
  }
  
@@@ -1319,18 -1311,6 +1319,18 @@@ static char *git_header_name(struct app
        }
  }
  
 +static int check_header_line(struct apply_state *state, struct patch *patch)
 +{
 +      int extensions = (patch->is_delete == 1) + (patch->is_new == 1) +
 +                       (patch->is_rename == 1) + (patch->is_copy == 1);
 +      if (extensions > 1)
 +              return error(_("inconsistent header lines %d and %d"),
 +                           patch->extension_linenr, state->linenr);
 +      if (extensions && !patch->extension_linenr)
 +              patch->extension_linenr = state->linenr;
 +      return 0;
 +}
 +
  /* Verify that we recognize the lines following a git header */
  static int parse_git_header(struct apply_state *state,
                            const char *line,
                        res = p->fn(state, line + oplen, patch);
                        if (res < 0)
                                return -1;
 +                      if (check_header_line(state, patch))
 +                              return -1;
                        if (res > 0)
                                return offset;
                        break;
@@@ -1596,8 -1574,7 +1596,8 @@@ static int find_header(struct apply_sta
                                patch->old_name = xstrdup(patch->def_name);
                                patch->new_name = xstrdup(patch->def_name);
                        }
 -                      if (!patch->is_delete && !patch->new_name) {
 +                      if ((!patch->new_name && !patch->is_delete) ||
 +                          (!patch->old_name && !patch->is_new)) {
                                error(_("git diff header lacks filename information "
                                             "(line %d)"), state->linenr);
                                return -128;
@@@ -2100,7 -2077,7 +2100,7 @@@ static int use_patch(struct apply_stat
        /* See if it matches any of exclude/include rule */
        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))
+               if (!wildmatch(it->string, pathname, 0))
                        return (it->util != NULL);
        }
  
@@@ -2279,7 -2256,7 +2279,7 @@@ static int read_old_data(struct stat *s
        case S_IFREG:
                if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
                        return error(_("unable to open or read %s"), path);
 -              convert_to_git(path, buf->buf, buf->len, buf, 0);
 +              convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
                return 0;
        default:
                return -1;
@@@ -3717,7 -3694,8 +3717,7 @@@ static int check_preimage(struct apply_
   is_new:
        patch->is_new = 1;
        patch->is_delete = 0;
 -      free(patch->old_name);
 -      patch->old_name = NULL;
 +      FREE_AND_NULL(patch->old_name);
        return 0;
  }
  
diff --combined builtin/describe.c
index 70eb1446089583cd859ea1f05b260283cd78067f,2fe05f5324ee5b25b59e911874569599f804fd0d..19eacdd170d98ea583cc2eb373247df600be24d7
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "config.h"
  #include "lockfile.h"
  #include "commit.h"
  #include "tag.h"
@@@ -143,7 -142,7 +143,7 @@@ static int get_name(const char *path, c
                        return 0;
  
                for_each_string_list_item(item, &exclude_patterns) {
-                       if (!wildmatch(item->string, path + 10, 0, NULL))
+                       if (!wildmatch(item->string, path + 10, 0))
                                return 0;
                }
        }
                        return 0;
  
                for_each_string_list_item(item, &patterns) {
-                       if (!wildmatch(item->string, path + 10, 0, NULL))
+                       if (!wildmatch(item->string, path + 10, 0))
                                break;
  
                        /* If we get here, no pattern matched. */
diff --combined builtin/name-rev.c
index e21715f1d0874171bcda2486adb4d27ea5cbbc99,d21a5002a7ecbcb6e8921fdab1b1bfdd16dcbe7a..c41ea7c2a62ba868061884e511256c24f4d020d9
@@@ -1,6 -1,5 +1,6 @@@
  #include "builtin.h"
  #include "cache.h"
 +#include "config.h"
  #include "commit.h"
  #include "tag.h"
  #include "refs.h"
@@@ -130,7 -129,7 +130,7 @@@ static int subpath_matches(const char *
        const char *subpath = path;
  
        while (subpath) {
-               if (!wildmatch(filter, subpath, 0, NULL))
+               if (!wildmatch(filter, subpath, 0))
                        return subpath - path;
                subpath = strchr(subpath, '/');
                if (subpath)
diff --combined builtin/reflog.c
index 44cdc2dbd0cbf64be1672428e930223425ed7b04,96c82b4f5ef419f14425f47b2be699e7c87c3540..e237d927a0881b56135a21a1b0041e7de6ff39ab
@@@ -1,5 -1,4 +1,5 @@@
  #include "builtin.h"
 +#include "config.h"
  #include "lockfile.h"
  #include "commit.h"
  #include "refs.h"
@@@ -486,7 -485,7 +486,7 @@@ static void set_reflog_expiry_param(str
                return; /* both given explicitly -- nothing to tweak */
  
        for (ent = reflog_expire_cfg; ent; ent = ent->next) {
-               if (!wildmatch(ent->pattern, ref, 0, NULL)) {
+               if (!wildmatch(ent->pattern, ref, 0)) {
                        if (!(slot & EXPIRE_TOTAL))
                                cb->expire_total = ent->expire_total;
                        if (!(slot & EXPIRE_UNREACH))
diff --combined builtin/replace.c
index 80a15cf35f3fa5a1a7c038924a84e34fdc15aa0b,89262df5a19c3dcf9b39bb7f1be8c1df7e9305f0..fba336a68a375e20e9b40d332eb58a3f302249fa
@@@ -9,7 -9,6 +9,7 @@@
   */
  
  #include "cache.h"
 +#include "config.h"
  #include "builtin.h"
  #include "refs.h"
  #include "parse-options.h"
@@@ -41,7 -40,7 +41,7 @@@ static int show_reference(const char *r
  {
        struct show_data *data = cb_data;
  
-       if (!wildmatch(data->pattern, refname, 0, NULL)) {
+       if (!wildmatch(data->pattern, refname, 0)) {
                if (data->format == REPLACE_FORMAT_SHORT)
                        printf("%s\n", refname);
                else if (data->format == REPLACE_FORMAT_MEDIUM)
diff --combined builtin/show-branch.c
index 527f69e283fd592c7b862b4ad6467d08d33e561c,82f378e7f59f306499bf38f802f09187617dde00..7073a3eb9769cae1f00e714a93528b33ca651d9c
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "config.h"
  #include "commit.h"
  #include "refs.h"
  #include "builtin.h"
@@@ -438,7 -437,7 +438,7 @@@ static int append_matching_ref(const ch
                        slash--;
        if (!*tail)
                return 0;
-       if (wildmatch(match_ref_pattern, tail, 0, NULL))
+       if (wildmatch(match_ref_pattern, tail, 0))
                return 0;
        if (starts_with(refname, "refs/heads/"))
                return append_head_ref(refname, oid, flag, cb_data);
diff --combined config.c
index 4638b0696ab8885afe1fc696dd6e0a25dcc1c89f,260caf27b87809363aa5ee4d1ffe4fd95ddb8874..a9356c1383861ecf7f33ee0262c8a60bbe20864f
+++ b/config.c
@@@ -6,8 -6,6 +6,8 @@@
   *
   */
  #include "cache.h"
 +#include "config.h"
 +#include "repository.h"
  #include "lockfile.h"
  #include "exec_cmd.h"
  #include "strbuf.h"
@@@ -73,6 -71,13 +73,6 @@@ static int core_compression_seen
  static int pack_compression_seen;
  static int zlib_compression_seen;
  
 -/*
 - * Default config_set that contains key-value pairs from the usual set of config
 - * config files (i.e repo specific .git/config, user wide ~/.gitconfig, XDG
 - * config file and the global /etc/gitconfig)
 - */
 -static struct config_set the_config_set;
 -
  static int config_file_fgetc(struct config_source *conf)
  {
        return getc_unlocked(conf->u.file);
@@@ -213,6 -218,8 +213,6 @@@ static int include_by_gitdir(const stru
  
        if (opts->git_dir)
                git_dir = opts->git_dir;
 -      else if (have_git_dir())
 -              git_dir = get_git_dir();
        else
                goto done;
  
@@@ -238,7 -245,7 +238,7 @@@ again
        }
  
        ret = !wildmatch(pattern.buf + prefix, text.buf + prefix,
-                        icase ? WM_CASEFOLD : 0, NULL);
+                        icase ? WM_CASEFOLD : 0);
  
        if (!ret && !already_tried_absolute) {
                /*
@@@ -388,7 -395,8 +388,7 @@@ static int git_config_parse_key_1(cons
  
  out_free_ret_1:
        if (store_key) {
 -              free(*store_key);
 -              *store_key = NULL;
 +              FREE_AND_NULL(*store_key);
        }
        return -CONFIG_INVALID_KEY;
  }
@@@ -596,8 -604,7 +596,8 @@@ static int get_value(config_fn_t fn, vo
         */
        cf->linenr--;
        ret = fn(name->buf, value, data);
 -      cf->linenr++;
 +      if (ret >= 0)
 +              cf->linenr++;
        return ret;
  }
  
@@@ -1538,8 -1545,10 +1538,8 @@@ static int do_git_config_sequence(cons
        char *user_config = expand_user_path("~/.gitconfig", 0);
        char *repo_config;
  
 -      if (opts->git_dir)
 -              repo_config = mkpathdup("%s/config", opts->git_dir);
 -      else if (have_git_dir())
 -              repo_config = git_pathdup("config");
 +      if (opts->commondir)
 +              repo_config = mkpathdup("%s/config", opts->commondir);
        else
                repo_config = NULL;
  
        return ret;
  }
  
 -int git_config_with_options(config_fn_t fn, void *data,
 -                          struct git_config_source *config_source,
 -                          const struct config_options *opts)
 +int config_with_options(config_fn_t fn, void *data,
 +                      struct git_config_source *config_source,
 +                      const struct config_options *opts)
  {
        struct config_include_data inc = CONFIG_INCLUDE_INIT;
  
        return do_git_config_sequence(opts, fn, data);
  }
  
 -static void git_config_raw(config_fn_t fn, void *data)
 -{
 -      struct config_options opts = {0};
 -
 -      opts.respect_includes = 1;
 -      if (git_config_with_options(fn, data, NULL, &opts) < 0)
 -              /*
 -               * git_config_with_options() normally returns only
 -               * zero, as most errors are fatal, and
 -               * non-fatal potential errors are guarded by "if"
 -               * statements that are entered only when no error is
 -               * possible.
 -               *
 -               * If we ever encounter a non-fatal error, it means
 -               * something went really wrong and we should stop
 -               * immediately.
 -               */
 -              die(_("unknown error occurred while reading the configuration files"));
 -}
 -
  static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
  {
        int i, value_index;
  void read_early_config(config_fn_t cb, void *data)
  {
        struct config_options opts = {0};
 -      struct strbuf buf = STRBUF_INIT;
 +      struct strbuf commondir = STRBUF_INIT;
 +      struct strbuf gitdir = STRBUF_INIT;
  
        opts.respect_includes = 1;
  
 -      if (have_git_dir())
 +      if (have_git_dir()) {
 +              opts.commondir = get_git_common_dir();
                opts.git_dir = get_git_dir();
        /*
         * When setup_git_directory() was not yet asked to discover the
         * notably, the current working directory is still the same after the
         * call).
         */
 -      else if (discover_git_directory(&buf))
 -              opts.git_dir = buf.buf;
 -
 -      git_config_with_options(cb, data, NULL, &opts);
 -
 -      strbuf_release(&buf);
 -}
 +      } else if (!discover_git_directory(&commondir, &gitdir)) {
 +              opts.commondir = commondir.buf;
 +              opts.git_dir = gitdir.buf;
 +      }
  
 -static void git_config_check_init(void);
 +      config_with_options(cb, data, NULL, &opts);
  
 -void git_config(config_fn_t fn, void *data)
 -{
 -      git_config_check_init();
 -      configset_iter(&the_config_set, fn, data);
 +      strbuf_release(&commondir);
 +      strbuf_release(&gitdir);
  }
  
  static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
@@@ -1860,194 -1892,87 +1860,194 @@@ int git_configset_get_pathname(struct c
                return 1;
  }
  
 -static void git_config_check_init(void)
 +/* Functions use to read configuration from a repository */
 +static void repo_read_config(struct repository *repo)
 +{
 +      struct config_options opts;
 +
 +      opts.respect_includes = 1;
 +      opts.commondir = repo->commondir;
 +      opts.git_dir = repo->gitdir;
 +
 +      if (!repo->config)
 +              repo->config = xcalloc(1, sizeof(struct config_set));
 +      else
 +              git_configset_clear(repo->config);
 +
 +      git_configset_init(repo->config);
 +
 +      if (config_with_options(config_set_callback, repo->config, NULL, &opts) < 0)
 +              /*
 +               * config_with_options() normally returns only
 +               * zero, as most errors are fatal, and
 +               * non-fatal potential errors are guarded by "if"
 +               * statements that are entered only when no error is
 +               * possible.
 +               *
 +               * If we ever encounter a non-fatal error, it means
 +               * something went really wrong and we should stop
 +               * immediately.
 +               */
 +              die(_("unknown error occurred while reading the configuration files"));
 +}
 +
 +static void git_config_check_init(struct repository *repo)
  {
 -      if (the_config_set.hash_initialized)
 +      if (repo->config && repo->config->hash_initialized)
                return;
 -      git_configset_init(&the_config_set);
 -      git_config_raw(config_set_callback, &the_config_set);
 +      repo_read_config(repo);
  }
  
 -void git_config_clear(void)
 +static void repo_config_clear(struct repository *repo)
  {
 -      if (!the_config_set.hash_initialized)
 +      if (!repo->config || !repo->config->hash_initialized)
                return;
 -      git_configset_clear(&the_config_set);
 +      git_configset_clear(repo->config);
  }
  
 -int git_config_get_value(const char *key, const char **value)
 +void repo_config(struct repository *repo, config_fn_t fn, void *data)
  {
 -      git_config_check_init();
 -      return git_configset_get_value(&the_config_set, key, value);
 +      git_config_check_init(repo);
 +      configset_iter(repo->config, fn, data);
  }
  
 -const struct string_list *git_config_get_value_multi(const char *key)
 +int repo_config_get_value(struct repository *repo,
 +                        const char *key, const char **value)
  {
 -      git_config_check_init();
 -      return git_configset_get_value_multi(&the_config_set, key);
 +      git_config_check_init(repo);
 +      return git_configset_get_value(repo->config, key, value);
  }
  
 -int git_config_get_string_const(const char *key, const char **dest)
 +const struct string_list *repo_config_get_value_multi(struct repository *repo,
 +                                                    const char *key)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_value_multi(repo->config, key);
 +}
 +
 +int repo_config_get_string_const(struct repository *repo,
 +                               const char *key, const char **dest)
  {
        int ret;
 -      git_config_check_init();
 -      ret = git_configset_get_string_const(&the_config_set, key, dest);
 +      git_config_check_init(repo);
 +      ret = git_configset_get_string_const(repo->config, key, dest);
        if (ret < 0)
                git_die_config(key, NULL);
        return ret;
  }
  
 +int repo_config_get_string(struct repository *repo,
 +                         const char *key, char **dest)
 +{
 +      git_config_check_init(repo);
 +      return repo_config_get_string_const(repo, key, (const char **)dest);
 +}
 +
 +int repo_config_get_int(struct repository *repo,
 +                      const char *key, int *dest)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_int(repo->config, key, dest);
 +}
 +
 +int repo_config_get_ulong(struct repository *repo,
 +                        const char *key, unsigned long *dest)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_ulong(repo->config, key, dest);
 +}
 +
 +int repo_config_get_bool(struct repository *repo,
 +                       const char *key, int *dest)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_bool(repo->config, key, dest);
 +}
 +
 +int repo_config_get_bool_or_int(struct repository *repo,
 +                              const char *key, int *is_bool, int *dest)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_bool_or_int(repo->config, key, is_bool, dest);
 +}
 +
 +int repo_config_get_maybe_bool(struct repository *repo,
 +                             const char *key, int *dest)
 +{
 +      git_config_check_init(repo);
 +      return git_configset_get_maybe_bool(repo->config, key, dest);
 +}
 +
 +int repo_config_get_pathname(struct repository *repo,
 +                           const char *key, const char **dest)
 +{
 +      int ret;
 +      git_config_check_init(repo);
 +      ret = git_configset_get_pathname(repo->config, key, dest);
 +      if (ret < 0)
 +              git_die_config(key, NULL);
 +      return ret;
 +}
 +
 +/* Functions used historically to read configuration from 'the_repository' */
 +void git_config(config_fn_t fn, void *data)
 +{
 +      repo_config(the_repository, fn, data);
 +}
 +
 +void git_config_clear(void)
 +{
 +      repo_config_clear(the_repository);
 +}
 +
 +int git_config_get_value(const char *key, const char **value)
 +{
 +      return repo_config_get_value(the_repository, key, value);
 +}
 +
 +const struct string_list *git_config_get_value_multi(const char *key)
 +{
 +      return repo_config_get_value_multi(the_repository, key);
 +}
 +
 +int git_config_get_string_const(const char *key, const char **dest)
 +{
 +      return repo_config_get_string_const(the_repository, key, dest);
 +}
 +
  int git_config_get_string(const char *key, char **dest)
  {
 -      git_config_check_init();
 -      return git_config_get_string_const(key, (const char **)dest);
 +      return repo_config_get_string(the_repository, key, dest);
  }
  
  int git_config_get_int(const char *key, int *dest)
  {
 -      git_config_check_init();
 -      return git_configset_get_int(&the_config_set, key, dest);
 +      return repo_config_get_int(the_repository, key, dest);
  }
  
  int git_config_get_ulong(const char *key, unsigned long *dest)
  {
 -      git_config_check_init();
 -      return git_configset_get_ulong(&the_config_set, key, dest);
 +      return repo_config_get_ulong(the_repository, key, dest);
  }
  
  int git_config_get_bool(const char *key, int *dest)
  {
 -      git_config_check_init();
 -      return git_configset_get_bool(&the_config_set, key, dest);
 +      return repo_config_get_bool(the_repository, key, dest);
  }
  
  int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)
  {
 -      git_config_check_init();
 -      return git_configset_get_bool_or_int(&the_config_set, key, is_bool, dest);
 +      return repo_config_get_bool_or_int(the_repository, key, is_bool, dest);
  }
  
  int git_config_get_maybe_bool(const char *key, int *dest)
  {
 -      git_config_check_init();
 -      return git_configset_get_maybe_bool(&the_config_set, key, dest);
 +      return repo_config_get_maybe_bool(the_repository, key, dest);
  }
  
  int git_config_get_pathname(const char *key, const char **dest)
  {
 -      int ret;
 -      git_config_check_init();
 -      ret = git_configset_get_pathname(&the_config_set, key, dest);
 -      if (ret < 0)
 -              git_die_config(key, NULL);
 -      return ret;
 +      return repo_config_get_pathname(the_repository, key, dest);
  }
  
  int git_config_get_expiry(const char *key, const char **output)
diff --combined dir.c
index 332f9d8095faf0ec4549cab41811167aecea31d3,c64965f237461fd9a40a6850c6d74f65bd2c201e..ae6f5c9636abd34d026579b7ddc8452825af9b30
--- 1/dir.c
--- 2/dir.c
+++ b/dir.c
@@@ -9,7 -9,6 +9,7 @@@
   */
  #define NO_THE_INDEX_COMPATIBILITY_MACROS
  #include "cache.h"
 +#include "config.h"
  #include "dir.h"
  #include "attr.h"
  #include "refs.h"
@@@ -92,13 -91,11 +92,11 @@@ int git_fnmatch(const struct pathspec_i
        if (item->magic & PATHSPEC_GLOB)
                return wildmatch(pattern, string,
                                 WM_PATHNAME |
-                                (item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0),
-                                NULL);
+                                (item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0));
        else
                /* wildmatch has not learned no FNM_PATHNAME mode yet */
                return wildmatch(pattern, string,
-                                item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0,
-                                NULL);
+                                item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0);
  }
  
  static int fnmatch_icase_mem(const char *pattern, int patternlen,
  
        if (ignore_case)
                flags |= WM_CASEFOLD;
-       match_status = wildmatch(use_pat, use_str, flags, NULL);
+       match_status = wildmatch(use_pat, use_str, flags);
  
        strbuf_release(&pat_buf);
        strbuf_release(&str_buf);
@@@ -805,7 -802,7 +803,7 @@@ static int add_excludes(const char *fna
                                 (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
                                 !ce_stage(istate->cache[pos]) &&
                                 ce_uptodate(istate->cache[pos]) &&
 -                               !would_convert_to_git(fname))
 +                               !would_convert_to_git(istate, fname))
                                hashcpy(sha1_stat->sha1,
                                        istate->cache[pos]->oid.hash);
                        else
@@@ -2127,7 -2124,8 +2125,7 @@@ int read_directory(struct dir_struct *d
                for (i = j = 0; j < dir->nr; j++) {
                        if (i &&
                            check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
 -                              free(dir->entries[j]);
 -                              dir->entries[j] = NULL;
 +                              FREE_AND_NULL(dir->entries[j]);
                        } else {
                                dir->entries[i++] = dir->entries[j];
                        }
                     dir->untracked->dir_invalidated))
                        istate->cache_changed |= UNTRACKED_CHANGED;
                if (dir->untracked != istate->untracked) {
 -                      free(dir->untracked);
 -                      dir->untracked = NULL;
 +                      FREE_AND_NULL(dir->untracked);
                }
        }
        return dir->nr;
@@@ -2496,7 -2495,8 +2494,7 @@@ void write_untracked_extension(struct s
        strbuf_addbuf(out, &untracked->ident);
  
        strbuf_add(out, ouc, ouc_size(len));
 -      free(ouc);
 -      ouc = NULL;
 +      FREE_AND_NULL(ouc);
  
        if (!untracked->root) {
                varint_len = encode_varint(0, varbuf);
diff --combined ref-filter.c
index 72e6cb8ecc3e46481239314d27f48a1c8a392518,718def443a0862c5ba90ce45b24abc22fa0aaf5b..e0578d8b5ae1a467082ee94ff798d054db1450bf
@@@ -1624,7 -1624,7 +1624,7 @@@ static int match_pattern(const struct r
               skip_prefix(refname, "refs/", &refname));
  
        for (; *patterns; patterns++) {
-               if (!wildmatch(*patterns, refname, flags, NULL))
+               if (!wildmatch(*patterns, refname, flags))
                        return 1;
        }
        return 0;
@@@ -1655,7 -1655,7 +1655,7 @@@ static int match_name_as_path(const str
                     refname[plen] == '/' ||
                     p[plen-1] == '/'))
                        return 1;
-               if (!wildmatch(p, refname, WM_PATHNAME, NULL))
+               if (!wildmatch(p, refname, WM_PATHNAME))
                        return 1;
        }
        return 0;
@@@ -1891,7 -1891,8 +1891,7 @@@ void ref_array_clear(struct ref_array *
  
        for (i = 0; i < array->nr; i++)
                free_array_item(array->items[i]);
 -      free(array->items);
 -      array->items = NULL;
 +      FREE_AND_NULL(array->items);
        array->nr = array->alloc = 0;
  }
  
diff --combined refs.c
index 88658ba76960401e4ab246b597d1212f5b435de1,32626a4cd144ff1e06896f246d0d88344000f841..7aae78cb551fd2743982d7f9fc60e6de45df9a11
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -3,7 -3,6 +3,7 @@@
   */
  
  #include "cache.h"
 +#include "config.h"
  #include "hashmap.h"
  #include "lockfile.h"
  #include "iterator.h"
@@@ -230,7 -229,7 +230,7 @@@ static int filter_refs(const char *refn
  {
        struct ref_filter *filter = (struct ref_filter *)data;
  
-       if (wildmatch(filter->pattern, refname, 0, NULL))
+       if (wildmatch(filter->pattern, refname, 0))
                return 0;
        return filter->fn(refname, oid, flags, filter->cb_data);
  }
@@@ -1342,18 -1341,6 +1342,18 @@@ int for_each_ref_in_submodule(const cha
                                    prefix, fn, cb_data);
  }
  
 +int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
 +                                each_ref_fn fn, void *cb_data,
 +                                unsigned int broken)
 +{
 +      unsigned int flag = 0;
 +
 +      if (broken)
 +              flag = DO_FOR_EACH_INCLUDE_BROKEN;
 +      return do_for_each_ref(get_submodule_ref_store(submodule),
 +                             prefix, fn, 0, flag, cb_data);
 +}
 +
  int for_each_replace_ref(each_ref_fn fn, void *cb_data)
  {
        return do_for_each_ref(get_main_ref_store(),
diff --combined revision.c
index e181ad1b70d06a0f64869a925c98cbc8558ef684,4ab8344ee87cfcaa64c038411693f12ed3c38dc7..9ff120b30518aa2b3f7cc214a1c921d739108d7c
@@@ -1142,7 -1142,7 +1142,7 @@@ int ref_excluded(struct string_list *re
        if (!ref_excludes)
                return 0;
        for_each_string_list_item(item, ref_excludes) {
-               if (!wildmatch(item->string, path, 0, NULL))
+               if (!wildmatch(item->string, path, 0))
                        return 1;
        }
        return 0;
@@@ -2075,7 -2075,7 +2075,7 @@@ static int for_each_bisect_ref(const ch
        struct strbuf bisect_refs = STRBUF_INIT;
        int status;
        strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
 -      status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
 +      status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
        strbuf_release(&bisect_refs);
        return status;
  }