Merge branches 'bw/ls-files-sans-the-index' and 'bw/config-h' into bw/repo-object

* bw/ls-files-sans-the-index:
  ls-files: factor out tag calculation
  ls-files: factor out debug info into a function
  ls-files: convert show_files to take an index
  ls-files: convert show_ce_entry to take an index
  ls-files: convert prune_cache to take an index
  ls-files: convert ce_excluded to take an index
  ls-files: convert show_ru_info to take an index
  ls-files: convert show_other_files to take an index
  ls-files: convert show_killed_files to take an index
  ls-files: convert write_eolinfo to take an index
  ls-files: convert overlay_tree_on_cache to take an index
  tree: convert read_tree to take an index parameter
  convert: convert renormalize_buffer to take an index
  convert: convert convert_to_git to take an index
  convert: convert convert_to_git_filter_fd to take an index
  convert: convert crlf_to_git to take an index
  convert: convert get_cached_convert_stats_ascii to take an index

* bw/config-h:
  config: don't implicitly use gitdir or commondir
  config: respect commondir
  setup: teach discover_git_directory to respect the commondir
  config: don't include config.h by default
  config: remove git_config_iter
  config: create config.h
  alias: use the early config machinery to expand aliases
  t7006: demonstrate a problem with aliases in subdirectories
  t1308: relax the test verifying that empty alias values are disallowed
  help: use early config when autocorrecting aliases
  config: report correct line number upon error
  discover_git_directory(): avoid setting invalid git_dir
This commit is contained in:
Junio C Hamano
2017-06-21 15:20:44 -07:00
155 changed files with 613 additions and 412 deletions

View File

@ -6,6 +6,7 @@
*
*/
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "exec_cmd.h"
#include "strbuf.h"
@ -218,8 +219,6 @@ static int include_by_gitdir(const struct config_options *opts,
if (opts->git_dir)
git_dir = opts->git_dir;
else if (have_git_dir())
git_dir = get_git_dir();
else
goto done;
@ -604,7 +603,8 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
*/
cf->linenr--;
ret = fn(name->buf, value, data);
cf->linenr++;
if (ret >= 0)
cf->linenr++;
return ret;
}
@ -1545,10 +1545,8 @@ static int do_git_config_sequence(const struct config_options *opts,
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;
@ -1579,9 +1577,9 @@ static int do_git_config_sequence(const struct config_options *opts,
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;
@ -1612,9 +1610,14 @@ 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)
if (have_git_dir()) {
opts.commondir = get_git_common_dir();
opts.git_dir = get_git_dir();
}
if (config_with_options(fn, data, NULL, &opts) < 0)
/*
* git_config_with_options() normally returns only
* 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
@ -1653,11 +1656,13 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
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
@ -1667,12 +1672,15 @@ void read_early_config(config_fn_t cb, void *data)
* notably, the current working directory is still the same after the
* call).
*/
else if (discover_git_directory(&buf))
opts.git_dir = buf.buf;
} else if (!discover_git_directory(&commondir, &gitdir)) {
opts.commondir = commondir.buf;
opts.git_dir = gitdir.buf;
}
git_config_with_options(cb, data, NULL, &opts);
config_with_options(cb, data, NULL, &opts);
strbuf_release(&buf);
strbuf_release(&commondir);
strbuf_release(&gitdir);
}
static void git_config_check_init(void);