1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 06:56:08 +02:00

Merge branch 'bw/config-h'

Fix configuration codepath to pay proper attention to commondir
that is used in multi-worktree situation, and isolate config API
into its own header file.

* 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
This commit is contained in:
Junio C Hamano 2017-06-24 14:28:40 -07:00
commit f31d23a399
147 changed files with 396 additions and 228 deletions

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
int advice_push_update_rejected = 1;
int advice_push_non_ff_current = 1;

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
struct config_alias_data {
const char *alias;

View File

@ -8,6 +8,7 @@
*/
#include "cache.h"
#include "config.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"

View File

@ -2,6 +2,7 @@
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#include "cache.h"
#include "config.h"
#include "tar.h"
#include "archive.h"
#include "streaming.h"

View File

@ -2,6 +2,7 @@
* Copyright (c) 2006 Rene Scharfe
*/
#include "cache.h"
#include "config.h"
#include "archive.h"
#include "streaming.h"
#include "utf8.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "commit.h"
#include "tree-walk.h"

1
attr.c
View File

@ -9,6 +9,7 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "exec_cmd.h"
#include "attr.h"
#include "dir.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"

View File

@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "cache.h"
#include "config.h"
#include "branch.h"
#include "refs.h"
#include "remote.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) 2006 Linus Torvalds
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "lockfile.h"
#include "dir.h"

View File

@ -4,6 +4,7 @@
* Based on git-am.sh by Junio C Hamano.
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"

View File

@ -6,6 +6,7 @@
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "diff.h"

View File

@ -6,6 +6,7 @@
*/
#include "cache.h"
#include "config.h"
#include "color.h"
#include "refs.h"
#include "commit.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "diff.h"
#include "parse-options.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "attr.h"
#include "quote.h"
#include "parse-options.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "quote.h"
#include "pathspec.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "mailmap.h"
#include "parse-options.h"
#include "string-list.h"

View File

@ -5,6 +5,7 @@
*
*/
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "refs.h"

View File

@ -8,6 +8,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"

View File

@ -9,6 +9,7 @@
*/
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "fetch-pack.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "strbuf.h"
#include "parse-options.h"
#include "string-list.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "tree.h"
#include "builtin.h"

View File

@ -6,6 +6,7 @@
*/
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "cache-tree.h"
#include "color.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "color.h"
#include "parse-options.h"
#include "urlmatch.h"
@ -242,8 +243,8 @@ static int get_value(const char *key_, const char *regex_)
}
}
git_config_with_options(collect_config, &values,
&given_config_source, &config_options);
config_with_options(collect_config, &values,
&given_config_source, &config_options);
ret = !values.nr;
@ -320,8 +321,8 @@ static void get_color(const char *var, const char *def_color)
get_color_slot = var;
get_color_found = 0;
parsed_color[0] = '\0';
git_config_with_options(git_get_color_config, NULL,
&given_config_source, &config_options);
config_with_options(git_get_color_config, NULL,
&given_config_source, &config_options);
if (!get_color_found && def_color) {
if (color_parse(def_color, parsed_color) < 0)
@ -352,8 +353,8 @@ static int get_colorbool(const char *var, int print)
get_colorbool_found = -1;
get_diff_color_found = -1;
get_color_ui_found = -1;
git_config_with_options(git_get_colorbool_config, NULL,
&given_config_source, &config_options);
config_with_options(git_get_colorbool_config, NULL,
&given_config_source, &config_options);
if (get_colorbool_found < 0) {
if (!strcmp(get_colorbool_slot, "color.diff"))
@ -441,8 +442,8 @@ static int get_urlmatch(const char *var, const char *url)
show_keys = 1;
}
git_config_with_options(urlmatch_config_entry, &config,
&given_config_source, &config_options);
config_with_options(urlmatch_config_entry, &config,
&given_config_source, &config_options);
ret = !values.nr;
@ -538,6 +539,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
config_options.respect_includes = !given_config_source.file;
else
config_options.respect_includes = respect_includes_opt;
if (!nongit) {
config_options.commondir = get_git_common_dir();
config_options.git_dir = get_git_dir();
}
if (end_null) {
term = '\0';
@ -582,9 +587,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (actions == ACTION_LIST) {
check_argc(argc, 0, 0);
if (git_config_with_options(show_all_config, NULL,
&given_config_source,
&config_options) < 0) {
if (config_with_options(show_all_config, NULL,
&given_config_source,
&config_options) < 0) {
if (given_config_source.file)
die_errno("unable to read config file '%s'",
given_config_source.file);

View File

@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "builtin.h"
#include "parse-options.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "tag.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "diff.h"
#include "commit.h"
#include "log-tree.h"

View File

@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "color.h"
#include "commit.h"

View File

@ -12,6 +12,7 @@
* Copyright (C) 2016 Johannes Schindelin
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "run-command.h"
#include "exec_cmd.h"

View File

@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "commit.h"
#include "object.h"

View File

@ -2,6 +2,7 @@
* "git fetch"
*/
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "commit.h"
#include "builtin.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "commit.h"
#include "diff.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "object.h"
#include "parse-options.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"

View File

@ -11,6 +11,7 @@
*/
#include "builtin.h"
#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "parse-options.h"

View File

@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"

View File

@ -5,6 +5,7 @@
* Copyright (C) Junio C Hamano, 2005
*/
#include "builtin.h"
#include "config.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"

View File

@ -2,6 +2,7 @@
* Builtin help command
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "delta.h"
#include "pack.h"
#include "csum-file.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "exec_cmd.h"

View File

@ -5,6 +5,7 @@
* 2006 Junio Hamano
*/
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "color.h"
#include "commit.h"

View File

@ -6,6 +6,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "quote.h"
#include "dir.h"
#include "builtin.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "xdiff/xdiff.h"
#include "xdiff-interface.h"
#include "parse-options.h"

View File

@ -7,6 +7,7 @@
*/
#include "cache.h"
#include "config.h"
#include "parse-options.h"
#include "builtin.h"
#include "lockfile.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) 2006 Johannes Schindelin
*/
#include "builtin.h"
#include "config.h"
#include "pathspec.h"
#include "lockfile.h"
#include "dir.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "tag.h"
#include "refs.h"

View File

@ -8,6 +8,7 @@
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "notes.h"
#include "blob.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "attr.h"
#include "object.h"
#include "blob.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
{

View File

@ -6,6 +6,7 @@
* Fetch one or more remote refs and merge it/them into the current HEAD.
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "exec_cmd.h"

View File

@ -2,6 +2,7 @@
* "git push"
*/
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "run-command.h"
#include "builtin.h"

View File

@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "object.h"
#include "tree.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "parse-options.h"
#include "sequencer.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "pack.h"
#include "refs.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "refs.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "parse-options.h"
#include "transport.h"
#include "remote.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "run-command.h"

View File

@ -9,6 +9,7 @@
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "parse-options.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"

View File

@ -8,6 +8,7 @@
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "tag.h"
#include "object.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "refs.h"
#include "quote.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "diff.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds 2006
*/
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "dir.h"
#include "cache-tree.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "commit.h"
#include "refs.h"
#include "pkt-line.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "string-list.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "refs.h"
#include "builtin.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "parse-options.h"
#include "strbuf.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "parse-options.h"
#include "quote.h"
#include "pathspec.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
#include "cache.h"
#include "refs.h"
#include "parse-options.h"

View File

@ -7,6 +7,7 @@
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "tag.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "config.h"
static char *create_temp_file(unsigned char *sha1)
{

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "object.h"
#include "delta.h"
#include "pack.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "parse-options.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Eric Biederman, 2005
*/
#include "builtin.h"
#include "config.h"
static const char var_usage[] = "git var (-l | <variable>)";

View File

@ -6,6 +6,7 @@
* Based on git-verify-tag
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "run-command.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "run-command.h"
#include "parse-options.h"

View File

@ -6,6 +6,7 @@
* Based on git-verify-tag.sh
*/
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "tag.h"
#include "run-command.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "dir.h"
#include "parse-options.h"

View File

@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"

202
cache.h
View File

@ -525,12 +525,15 @@ extern void set_git_work_tree(const char *tree);
extern void setup_work_tree(void);
/*
* Find GIT_DIR of the repository that contains the current working directory,
* without changing the working directory or other global state. The result is
* appended to gitdir. The return value is either NULL if no repository was
* found, or pointing to the path inside gitdir's buffer.
* Find the commondir and gitdir of the repository that contains the current
* working directory, without changing the working directory or other global
* state. The result is appended to commondir and gitdir. If the discovered
* gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
* both have the same result appended to the buffer. The return value is
* either 0 upon success and non-zero if no repository was found.
*/
extern const char *discover_git_directory(struct strbuf *gitdir);
extern int discover_git_directory(struct strbuf *commondir,
struct strbuf *gitdir);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
extern char *prefix_path(const char *prefix, int len, const char *path);
@ -1879,188 +1882,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
/* Dumb servers support */
extern int update_server_info(int);
/* git_config_parse_key() returns these negated: */
#define CONFIG_INVALID_KEY 1
#define CONFIG_NO_SECTION_OR_NAME 2
/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
#define CONFIG_NO_LOCK -1
#define CONFIG_INVALID_FILE 3
#define CONFIG_NO_WRITE 4
#define CONFIG_NOTHING_SET 5
#define CONFIG_INVALID_PATTERN 6
#define CONFIG_GENERIC_ERROR 7
#define CONFIG_REGEX_NONE ((void *)1)
struct git_config_source {
unsigned int use_stdin:1;
const char *file;
const char *blob;
};
enum config_origin_type {
CONFIG_ORIGIN_BLOB,
CONFIG_ORIGIN_FILE,
CONFIG_ORIGIN_STDIN,
CONFIG_ORIGIN_SUBMODULE_BLOB,
CONFIG_ORIGIN_CMDLINE
};
struct config_options {
unsigned int respect_includes : 1;
const char *git_dir;
};
typedef int (*config_fn_t)(const char *, const char *, void *);
extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
const char *name, const char *buf, size_t len, void *data);
extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
const unsigned char *sha1, void *data);
extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data);
extern void read_early_config(config_fn_t cb, void *data);
extern void git_config(config_fn_t fn, void *);
extern int git_config_with_options(config_fn_t fn, void *,
struct git_config_source *config_source,
const struct config_options *opts);
extern int git_parse_ulong(const char *, unsigned long *);
extern int git_parse_maybe_bool(const char *);
extern int git_config_int(const char *, const char *);
extern int64_t git_config_int64(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
extern ssize_t git_config_ssize_t(const char *, const char *);
extern int git_config_bool_or_int(const char *, const char *, int *);
extern int git_config_bool(const char *, const char *);
extern int git_config_maybe_bool(const char *, const char *);
extern int git_config_string(const char **, const char *, const char *);
extern int git_config_pathname(const char **, const char *, const char *);
extern int git_config_set_in_file_gently(const char *, const char *, const char *);
extern void git_config_set_in_file(const char *, const char *, const char *);
extern int git_config_set_gently(const char *, const char *);
extern void git_config_set(const char *, const char *);
extern int git_config_parse_key(const char *, char **, int *);
extern int git_config_key_is_valid(const char *key);
extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
extern void git_config_set_multivar(const char *, const char *, const char *, int);
extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
extern int git_config_rename_section(const char *, const char *);
extern int git_config_rename_section_in_file(const char *, const char *, const char *);
extern const char *git_etc_gitconfig(void);
extern int git_env_bool(const char *, int);
extern unsigned long git_env_ulong(const char *, unsigned long);
extern int git_config_system(void);
extern int config_error_nonbool(const char *);
#if defined(__GNUC__)
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
#endif
extern const char *get_log_output_encoding(void);
extern const char *get_commit_output_encoding(void);
extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
enum config_scope {
CONFIG_SCOPE_UNKNOWN = 0,
CONFIG_SCOPE_SYSTEM,
CONFIG_SCOPE_GLOBAL,
CONFIG_SCOPE_REPO,
CONFIG_SCOPE_CMDLINE,
};
extern enum config_scope current_config_scope(void);
extern const char *current_config_origin_type(void);
extern const char *current_config_name(void);
struct config_include_data {
int depth;
config_fn_t fn;
void *data;
const struct config_options *opts;
};
#define CONFIG_INCLUDE_INIT { 0 }
extern int git_config_include(const char *name, const char *value, void *data);
/*
* Match and parse a config key of the form:
*
* section.(subsection.)?key
*
* (i.e., what gets handed to a config_fn_t). The caller provides the section;
* we return -1 if it does not match, 0 otherwise. The subsection and key
* out-parameters are filled by the function (and *subsection is NULL if it is
* missing).
*
* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
* there is no subsection at all.
*/
extern int parse_config_key(const char *var,
const char *section,
const char **subsection, int *subsection_len,
const char **key);
struct config_set_element {
struct hashmap_entry ent;
char *key;
struct string_list value_list;
};
struct configset_list_item {
struct config_set_element *e;
int value_index;
};
/*
* the contents of the list are ordered according to their
* position in the config files and order of parsing the files.
* (i.e. key-value pair at the last position of .git/config will
* be at the last item of the list)
*/
struct configset_list {
struct configset_list_item *items;
unsigned int nr, alloc;
};
struct config_set {
struct hashmap config_hash;
int hash_initialized;
struct configset_list list;
};
extern void git_configset_init(struct config_set *cs);
extern int git_configset_add_file(struct config_set *cs, const char *filename);
extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
extern void git_configset_clear(struct config_set *cs);
extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
extern int git_config_get_value(const char *key, const char **value);
extern const struct string_list *git_config_get_value_multi(const char *key);
extern void git_config_clear(void);
extern void git_config_iter(config_fn_t fn, void *data);
extern int git_config_get_string_const(const char *key, const char **dest);
extern int git_config_get_string(const char *key, char **dest);
extern int git_config_get_int(const char *key, int *dest);
extern int git_config_get_ulong(const char *key, unsigned long *dest);
extern int git_config_get_bool(const char *key, int *dest);
extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
extern int git_config_get_maybe_bool(const char *key, int *dest);
extern int git_config_get_pathname(const char *key, const char **dest);
extern int git_config_get_untracked_cache(void);
extern int git_config_get_split_index(void);
extern int git_config_get_max_percent_split_change(void);
/* This dies if the configured or default date is in the future */
extern int git_config_get_expiry(const char *key, const char **output);
/*
* This is a hack for test programs like test-dump-untracked-cache to
* ensure that they do not modify the untracked cache when reading it.
@ -2068,16 +1892,6 @@ extern int git_config_get_expiry(const char *key, const char **output);
*/
extern int ignore_untracked_cache_config;
struct key_value_info {
const char *filename;
int linenr;
enum config_origin_type origin_type;
enum config_scope scope;
};
extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
extern int committer_ident_sufficiently_given(void);
extern int author_ident_sufficiently_given(void);

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "color.h"
static int git_use_color_default = GIT_COLOR_AUTO;

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "column.h"
#include "string-list.h"
#include "parse-options.h"

View File

@ -6,6 +6,7 @@
#define PRECOMPOSE_UNICODE_C
#include "cache.h"
#include "config.h"
#include "utf8.h"
#include "precompose_utf8.h"

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;
@ -1546,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;
@ -1580,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;
@ -1613,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
@ -1654,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
@ -1668,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);

194
config.h Normal file
View File

@ -0,0 +1,194 @@
#ifndef CONFIG_H
#define CONFIG_H
/* git_config_parse_key() returns these negated: */
#define CONFIG_INVALID_KEY 1
#define CONFIG_NO_SECTION_OR_NAME 2
/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
#define CONFIG_NO_LOCK -1
#define CONFIG_INVALID_FILE 3
#define CONFIG_NO_WRITE 4
#define CONFIG_NOTHING_SET 5
#define CONFIG_INVALID_PATTERN 6
#define CONFIG_GENERIC_ERROR 7
#define CONFIG_REGEX_NONE ((void *)1)
struct git_config_source {
unsigned int use_stdin:1;
const char *file;
const char *blob;
};
enum config_origin_type {
CONFIG_ORIGIN_BLOB,
CONFIG_ORIGIN_FILE,
CONFIG_ORIGIN_STDIN,
CONFIG_ORIGIN_SUBMODULE_BLOB,
CONFIG_ORIGIN_CMDLINE
};
struct config_options {
unsigned int respect_includes : 1;
const char *commondir;
const char *git_dir;
};
typedef int (*config_fn_t)(const char *, const char *, void *);
extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
const char *name, const char *buf, size_t len, void *data);
extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
const unsigned char *sha1, void *data);
extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data);
extern void read_early_config(config_fn_t cb, void *data);
extern void git_config(config_fn_t fn, void *);
extern int config_with_options(config_fn_t fn, void *,
struct git_config_source *config_source,
const struct config_options *opts);
extern int git_parse_ulong(const char *, unsigned long *);
extern int git_parse_maybe_bool(const char *);
extern int git_config_int(const char *, const char *);
extern int64_t git_config_int64(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
extern ssize_t git_config_ssize_t(const char *, const char *);
extern int git_config_bool_or_int(const char *, const char *, int *);
extern int git_config_bool(const char *, const char *);
extern int git_config_maybe_bool(const char *, const char *);
extern int git_config_string(const char **, const char *, const char *);
extern int git_config_pathname(const char **, const char *, const char *);
extern int git_config_set_in_file_gently(const char *, const char *, const char *);
extern void git_config_set_in_file(const char *, const char *, const char *);
extern int git_config_set_gently(const char *, const char *);
extern void git_config_set(const char *, const char *);
extern int git_config_parse_key(const char *, char **, int *);
extern int git_config_key_is_valid(const char *key);
extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
extern void git_config_set_multivar(const char *, const char *, const char *, int);
extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
extern int git_config_rename_section(const char *, const char *);
extern int git_config_rename_section_in_file(const char *, const char *, const char *);
extern const char *git_etc_gitconfig(void);
extern int git_env_bool(const char *, int);
extern unsigned long git_env_ulong(const char *, unsigned long);
extern int git_config_system(void);
extern int config_error_nonbool(const char *);
#if defined(__GNUC__)
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
#endif
extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
enum config_scope {
CONFIG_SCOPE_UNKNOWN = 0,
CONFIG_SCOPE_SYSTEM,
CONFIG_SCOPE_GLOBAL,
CONFIG_SCOPE_REPO,
CONFIG_SCOPE_CMDLINE,
};
extern enum config_scope current_config_scope(void);
extern const char *current_config_origin_type(void);
extern const char *current_config_name(void);
struct config_include_data {
int depth;
config_fn_t fn;
void *data;
const struct config_options *opts;
};
#define CONFIG_INCLUDE_INIT { 0 }
extern int git_config_include(const char *name, const char *value, void *data);
/*
* Match and parse a config key of the form:
*
* section.(subsection.)?key
*
* (i.e., what gets handed to a config_fn_t). The caller provides the section;
* we return -1 if it does not match, 0 otherwise. The subsection and key
* out-parameters are filled by the function (and *subsection is NULL if it is
* missing).
*
* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
* there is no subsection at all.
*/
extern int parse_config_key(const char *var,
const char *section,
const char **subsection, int *subsection_len,
const char **key);
struct config_set_element {
struct hashmap_entry ent;
char *key;
struct string_list value_list;
};
struct configset_list_item {
struct config_set_element *e;
int value_index;
};
/*
* the contents of the list are ordered according to their
* position in the config files and order of parsing the files.
* (i.e. key-value pair at the last position of .git/config will
* be at the last item of the list)
*/
struct configset_list {
struct configset_list_item *items;
unsigned int nr, alloc;
};
struct config_set {
struct hashmap config_hash;
int hash_initialized;
struct configset_list list;
};
extern void git_configset_init(struct config_set *cs);
extern int git_configset_add_file(struct config_set *cs, const char *filename);
extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
extern void git_configset_clear(struct config_set *cs);
extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
extern int git_config_get_value(const char *key, const char **value);
extern const struct string_list *git_config_get_value_multi(const char *key);
extern void git_config_clear(void);
extern int git_config_get_string_const(const char *key, const char **dest);
extern int git_config_get_string(const char *key, char **dest);
extern int git_config_get_int(const char *key, int *dest);
extern int git_config_get_ulong(const char *key, unsigned long *dest);
extern int git_config_get_bool(const char *key, int *dest);
extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
extern int git_config_get_maybe_bool(const char *key, int *dest);
extern int git_config_get_pathname(const char *key, const char **dest);
extern int git_config_get_untracked_cache(void);
extern int git_config_get_split_index(void);
extern int git_config_get_max_percent_split_change(void);
/* This dies if the configured or default date is in the future */
extern int git_config_get_expiry(const char *key, const char **output);
struct key_value_info {
const char *filename;
int linenr;
enum config_origin_type origin_type;
enum config_scope scope;
};
extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
#endif /* CONFIG_H */

View File

@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "cache.h"
#include "config.h"
#include "pkt-line.h"
#include "quote.h"
#include "refs.h"

View File

@ -1,5 +1,6 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "attr.h"
#include "run-command.h"
#include "quote.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "tempfile.h"
#include "credential.h"
#include "unix-socket.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "credential.h"
#include "string-list.h"
#include "run-command.h"

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "config.h"
#include "pkt-line.h"
#include "run-command.h"
#include "strbuf.h"

1
diff.c
View File

@ -2,6 +2,7 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "cache.h"
#include "config.h"
#include "tempfile.h"
#include "quote.h"
#include "diff.h"

1
dir.c
View File

@ -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"

Some files were not shown because too many files have changed in this diff Show More