Skip to content

Commit

Permalink
for-each-ref: load config earlier
Browse files Browse the repository at this point in the history
In most commands we load config before parsing command line
options, since it lets the latter override the former with a
simple variable assignment. In the case of for-each-ref,
though, we do it in the reverse order. This is OK with
the current code, since there's no interaction between the
config and command-line options.

However, as the ref-filter code starts to care about config
during verify_ref_format(), we'll want to make sure the
config is loaded. Let's bump the config to the usual spot
near the top of the function.

We can drop the comment there; it's impossible to keep a
"why we load the config" comment like this up to date with
every config option we might be interested in. And indeed,
it's already stale; we'd care about core.abbrev, for
instance, when %(objectname:short) is used.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Jul 13, 2017
1 parent 136c8c8 commit d8b6868
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions builtin/for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)

format.format = "%(objectname) %(objecttype)\t%(refname)";

git_config(git_default_config, NULL);

parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
if (maxcount < 0) {
error("invalid --count argument: `%d'", maxcount);
Expand All @@ -71,9 +73,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
sorting->ignore_case = icase;
filter.ignore_case = icase;

/* for warn_ambiguous_refs */
git_config(git_default_config, NULL);

filter.name_patterns = argv;
filter.match_as_path = 1;
filter_refs(&array, &filter, FILTER_REFS_ALL | FILTER_REFS_INCLUDE_BROKEN);
Expand Down

0 comments on commit d8b6868

Please sign in to comment.