git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/4] config.h
@ 2017-06-12 21:34 Brandon Williams
  2017-06-12 21:34 ` [PATCH 1/4] config: create config.h Brandon Williams
                   ` (6 more replies)
  0 siblings, 7 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:34 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, jrnieder, Brandon Williams

After some discussion I realized that my 'repository object' series was getting
to be rather long and increase in scope.  So I've decided to break off these
couple patches into their own series so they can be reviewed more easily.  This
should also let them be merged in faster as I suspect it'll take a while for my
'repository object' series to be reviewed thourouly and these couple patches
could result in a lot of merge conflicts as it touches a lot of files.

Brandon Williams (4):
  config: create config.h
  config: remove git_config_iter
  config: don't include config.h by default
  config: don't implicitly use gitdir

 advice.c                         |   1 +
 alias.c                          |   1 +
 apply.c                          |   1 +
 archive-tar.c                    |   1 +
 archive-zip.c                    |   1 +
 archive.c                        |   1 +
 attr.c                           |   1 +
 bisect.c                         |   1 +
 branch.c                         |   1 +
 builtin/add.c                    |   1 +
 builtin/am.c                     |   1 +
 builtin/blame.c                  |   2 +
 builtin/branch.c                 |   1 +
 builtin/cat-file.c               |   1 +
 builtin/check-attr.c             |   1 +
 builtin/check-ignore.c           |   1 +
 builtin/check-mailmap.c          |   1 +
 builtin/checkout-index.c         |   1 +
 builtin/checkout.c               |   1 +
 builtin/clean.c                  |   1 +
 builtin/clone.c                  |   1 +
 builtin/column.c                 |   1 +
 builtin/commit-tree.c            |   1 +
 builtin/commit.c                 |   1 +
 builtin/config.c                 |   3 +
 builtin/count-objects.c          |   1 +
 builtin/describe.c               |   1 +
 builtin/diff-files.c             |   1 +
 builtin/diff-index.c             |   1 +
 builtin/diff-tree.c              |   1 +
 builtin/diff.c                   |   1 +
 builtin/difftool.c               |   1 +
 builtin/fast-export.c            |   1 +
 builtin/fetch.c                  |   1 +
 builtin/fmt-merge-msg.c          |   1 +
 builtin/for-each-ref.c           |   1 +
 builtin/fsck.c                   |   1 +
 builtin/gc.c                     |   1 +
 builtin/grep.c                   |   1 +
 builtin/hash-object.c            |   1 +
 builtin/help.c                   |   1 +
 builtin/index-pack.c             |   1 +
 builtin/init-db.c                |   1 +
 builtin/log.c                    |   1 +
 builtin/ls-files.c               |   1 +
 builtin/ls-tree.c                |   1 +
 builtin/merge-base.c             |   1 +
 builtin/merge-file.c             |   1 +
 builtin/merge.c                  |   1 +
 builtin/mv.c                     |   1 +
 builtin/name-rev.c               |   1 +
 builtin/notes.c                  |   1 +
 builtin/pack-objects.c           |   1 +
 builtin/patch-id.c               |   1 +
 builtin/pull.c                   |   1 +
 builtin/push.c                   |   1 +
 builtin/read-tree.c              |   1 +
 builtin/rebase--helper.c         |   1 +
 builtin/receive-pack.c           |   1 +
 builtin/reflog.c                 |   1 +
 builtin/remote.c                 |   1 +
 builtin/repack.c                 |   1 +
 builtin/replace.c                |   1 +
 builtin/rerere.c                 |   1 +
 builtin/reset.c                  |   1 +
 builtin/rev-list.c               |   1 +
 builtin/rev-parse.c              |   1 +
 builtin/revert.c                 |   1 +
 builtin/rm.c                     |   1 +
 builtin/send-pack.c              |   1 +
 builtin/shortlog.c               |   1 +
 builtin/show-branch.c            |   1 +
 builtin/stripspace.c             |   1 +
 builtin/submodule--helper.c      |   1 +
 builtin/symbolic-ref.c           |   1 +
 builtin/tag.c                    |   1 +
 builtin/unpack-file.c            |   1 +
 builtin/unpack-objects.c         |   1 +
 builtin/update-index.c           |   1 +
 builtin/update-ref.c             |   1 +
 builtin/update-server-info.c     |   1 +
 builtin/var.c                    |   1 +
 builtin/verify-commit.c          |   1 +
 builtin/verify-pack.c            |   1 +
 builtin/verify-tag.c             |   1 +
 builtin/worktree.c               |   1 +
 builtin/write-tree.c             |   1 +
 cache.h                          | 189 --------------------------------------
 color.c                          |   1 +
 column.c                         |   1 +
 config.c                         |   7 +-
 config.h                         | 193 +++++++++++++++++++++++++++++++++++++++
 connect.c                        |   1 +
 convert.c                        |   1 +
 credential-cache--daemon.c       |   1 +
 credential.c                     |   1 +
 daemon.c                         |   1 +
 diff.c                           |   1 +
 dir.c                            |   1 +
 environment.c                    |   1 +
 fast-import.c                    |   1 +
 fetch-pack.c                     |   1 +
 git.c                            |   1 +
 gpg-interface.c                  |   1 +
 graph.c                          |   1 +
 grep.c                           |   1 +
 help.c                           |   1 +
 http-backend.c                   |   1 +
 http-fetch.c                     |   1 +
 http.c                           |   1 +
 ident.c                          |   1 +
 imap-send.c                      |   1 +
 ll-merge.c                       |   1 +
 log-tree.c                       |   1 +
 mailinfo.c                       |   1 +
 merge-recursive.c                |   1 +
 notes-utils.c                    |   1 +
 notes.c                          |   1 +
 pager.c                          |   1 +
 parse-options.c                  |   1 +
 pathspec.c                       |   1 +
 pretty.c                         |   1 +
 prompt.c                         |   1 +
 read-cache.c                     |   1 +
 refs.c                           |   1 +
 refs/files-backend.c             |   1 +
 remote-curl.c                    |   1 +
 remote.c                         |   1 +
 rerere.c                         |   1 +
 send-pack.c                      |   1 +
 sequencer.c                      |   1 +
 setup.c                          |   1 +
 sha1_file.c                      |   1 +
 sha1_name.c                      |   1 +
 submodule-config.c               |   1 +
 submodule.c                      |   1 +
 t/helper/test-config.c           |   1 +
 t/helper/test-submodule-config.c |   1 +
 trailer.c                        |   1 +
 transport.c                      |   1 +
 unpack-trees.c                   |   1 +
 upload-pack.c                    |   1 +
 userdiff.c                       |   1 +
 versioncmp.c                     |   1 +
 wrapper.c                        |   1 +
 xdiff-interface.c                |   1 +
 146 files changed, 342 insertions(+), 193 deletions(-)
 create mode 100644 config.h

-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply	[flat|nested] 57+ messages in thread

* [PATCH 1/4] config: create config.h
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
@ 2017-06-12 21:34 ` Brandon Williams
  2017-06-12 21:34 ` [PATCH 2/4] config: remove git_config_iter Brandon Williams
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:34 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, jrnieder, Brandon Williams

Move all config related declarations from cache.h to a new config.h
header file.  This makes cache.h smaller and allows for the opportunity
in a following patch to only include config.h when needed.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h  | 190 +------------------------------------------------------------
 config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+), 189 deletions(-)
 create mode 100644 config.h

diff --git a/cache.h b/cache.h
index 4d92aae0e..ed56f8818 100644
--- a/cache.h
+++ b/cache.h
@@ -11,6 +11,7 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
+#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
@@ -1872,188 +1873,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.
@@ -2061,16 +1883,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);
 
diff --git a/config.h b/config.h
new file mode 100644
index 000000000..f7f8b66c5
--- /dev/null
+++ b/config.h
@@ -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 *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 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);
+
+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 */
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH 2/4] config: remove git_config_iter
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
  2017-06-12 21:34 ` [PATCH 1/4] config: create config.h Brandon Williams
@ 2017-06-12 21:34 ` Brandon Williams
  2017-06-13  0:49   ` Jonathan Nieder
  2017-06-12 21:34 ` [PATCH 3/4] config: don't include config.h by default Brandon Williams
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:34 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, jrnieder, Brandon Williams

Since there is no implementation of the function 'git_config_iter' lets
stop exporting it and remove the prototype from config.h.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 config.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.h b/config.h
index f7f8b66c5..c70599bd5 100644
--- a/config.h
+++ b/config.h
@@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, co
 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);
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH 3/4] config: don't include config.h by default
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
  2017-06-12 21:34 ` [PATCH 1/4] config: create config.h Brandon Williams
  2017-06-12 21:34 ` [PATCH 2/4] config: remove git_config_iter Brandon Williams
@ 2017-06-12 21:34 ` Brandon Williams
  2017-06-12 21:34 ` [PATCH 4/4] config: don't implicitly use gitdir Brandon Williams
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:34 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, jrnieder, Brandon Williams

Stop including config.h by default in cache.h.  Instead only include
config.h in those files which require use of the config system.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 advice.c                         | 1 +
 alias.c                          | 1 +
 apply.c                          | 1 +
 archive-tar.c                    | 1 +
 archive-zip.c                    | 1 +
 archive.c                        | 1 +
 attr.c                           | 1 +
 bisect.c                         | 1 +
 branch.c                         | 1 +
 builtin/add.c                    | 1 +
 builtin/am.c                     | 1 +
 builtin/blame.c                  | 2 ++
 builtin/branch.c                 | 1 +
 builtin/cat-file.c               | 1 +
 builtin/check-attr.c             | 1 +
 builtin/check-ignore.c           | 1 +
 builtin/check-mailmap.c          | 1 +
 builtin/checkout-index.c         | 1 +
 builtin/checkout.c               | 1 +
 builtin/clean.c                  | 1 +
 builtin/clone.c                  | 1 +
 builtin/column.c                 | 1 +
 builtin/commit-tree.c            | 1 +
 builtin/commit.c                 | 1 +
 builtin/config.c                 | 1 +
 builtin/count-objects.c          | 1 +
 builtin/describe.c               | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/diff-tree.c              | 1 +
 builtin/diff.c                   | 1 +
 builtin/difftool.c               | 1 +
 builtin/fast-export.c            | 1 +
 builtin/fetch.c                  | 1 +
 builtin/fmt-merge-msg.c          | 1 +
 builtin/for-each-ref.c           | 1 +
 builtin/fsck.c                   | 1 +
 builtin/gc.c                     | 1 +
 builtin/grep.c                   | 1 +
 builtin/hash-object.c            | 1 +
 builtin/help.c                   | 1 +
 builtin/index-pack.c             | 1 +
 builtin/init-db.c                | 1 +
 builtin/log.c                    | 1 +
 builtin/ls-files.c               | 1 +
 builtin/ls-tree.c                | 1 +
 builtin/merge-base.c             | 1 +
 builtin/merge-file.c             | 1 +
 builtin/merge.c                  | 1 +
 builtin/mv.c                     | 1 +
 builtin/name-rev.c               | 1 +
 builtin/notes.c                  | 1 +
 builtin/pack-objects.c           | 1 +
 builtin/patch-id.c               | 1 +
 builtin/pull.c                   | 1 +
 builtin/push.c                   | 1 +
 builtin/read-tree.c              | 1 +
 builtin/rebase--helper.c         | 1 +
 builtin/receive-pack.c           | 1 +
 builtin/reflog.c                 | 1 +
 builtin/remote.c                 | 1 +
 builtin/repack.c                 | 1 +
 builtin/replace.c                | 1 +
 builtin/rerere.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-list.c               | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/rm.c                     | 1 +
 builtin/send-pack.c              | 1 +
 builtin/shortlog.c               | 1 +
 builtin/show-branch.c            | 1 +
 builtin/stripspace.c             | 1 +
 builtin/submodule--helper.c      | 1 +
 builtin/symbolic-ref.c           | 1 +
 builtin/tag.c                    | 1 +
 builtin/unpack-file.c            | 1 +
 builtin/unpack-objects.c         | 1 +
 builtin/update-index.c           | 1 +
 builtin/update-ref.c             | 1 +
 builtin/update-server-info.c     | 1 +
 builtin/var.c                    | 1 +
 builtin/verify-commit.c          | 1 +
 builtin/verify-pack.c            | 1 +
 builtin/verify-tag.c             | 1 +
 builtin/worktree.c               | 1 +
 builtin/write-tree.c             | 1 +
 cache.h                          | 1 -
 color.c                          | 1 +
 column.c                         | 1 +
 config.c                         | 1 +
 connect.c                        | 1 +
 convert.c                        | 1 +
 credential-cache--daemon.c       | 1 +
 credential.c                     | 1 +
 daemon.c                         | 1 +
 diff.c                           | 1 +
 dir.c                            | 1 +
 environment.c                    | 1 +
 fast-import.c                    | 1 +
 fetch-pack.c                     | 1 +
 git.c                            | 1 +
 gpg-interface.c                  | 1 +
 graph.c                          | 1 +
 grep.c                           | 1 +
 help.c                           | 1 +
 http-backend.c                   | 1 +
 http-fetch.c                     | 1 +
 http.c                           | 1 +
 ident.c                          | 1 +
 imap-send.c                      | 1 +
 ll-merge.c                       | 1 +
 log-tree.c                       | 1 +
 mailinfo.c                       | 1 +
 merge-recursive.c                | 1 +
 notes-utils.c                    | 1 +
 notes.c                          | 1 +
 pager.c                          | 1 +
 parse-options.c                  | 1 +
 pathspec.c                       | 1 +
 pretty.c                         | 1 +
 prompt.c                         | 1 +
 read-cache.c                     | 1 +
 refs.c                           | 1 +
 refs/files-backend.c             | 1 +
 remote-curl.c                    | 1 +
 remote.c                         | 1 +
 rerere.c                         | 1 +
 send-pack.c                      | 1 +
 sequencer.c                      | 1 +
 setup.c                          | 1 +
 sha1_file.c                      | 1 +
 sha1_name.c                      | 1 +
 submodule-config.c               | 1 +
 submodule.c                      | 1 +
 t/helper/test-config.c           | 1 +
 t/helper/test-submodule-config.c | 1 +
 trailer.c                        | 1 +
 transport.c                      | 1 +
 unpack-trees.c                   | 1 +
 upload-pack.c                    | 1 +
 userdiff.c                       | 1 +
 versioncmp.c                     | 1 +
 wrapper.c                        | 1 +
 xdiff-interface.c                | 1 +
 145 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/advice.c b/advice.c
index b84ae4960..3fa04fca0 100644
--- a/advice.c
+++ b/advice.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
diff --git a/alias.c b/alias.c
index 3b90397a9..052f34136 100644
--- a/alias.c
+++ b/alias.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 char *alias_lookup(const char *alias)
 {
diff --git a/apply.c b/apply.c
index c49cef063..87db9618d 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 073e60ebd..c6ed96ee7 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -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"
diff --git a/archive-zip.c b/archive-zip.c
index 27563e9e2..e8913e5a2 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2006 Rene Scharfe
  */
 #include "cache.h"
+#include "config.h"
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
diff --git a/archive.c b/archive.c
index b15a922da..60b3035a7 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 7e2134471..9f8b02936 100644
--- a/attr.c
+++ b/attr.c
@@ -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"
diff --git a/bisect.c b/bisect.c
index c952df692..d8587d11c 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/branch.c b/branch.c
index 985316eb7..a8a548ccf 100644
--- a/branch.c
+++ b/branch.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "config.h"
 #include "branch.h"
 #include "refs.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index d9a2491e4..f2415e99f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5ee146bfb..242d70361 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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"
diff --git a/builtin/blame.c b/builtin/blame.c
index d7a2df3b4..381927920 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,6 +6,8 @@
  */
 
 #include "cache.h"
+#include "config.h"
+#include "refs.h"
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 83fcda43d..c958e9325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4bffd7a2d..7efbc4019 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 4d01ca0c8..91444dc04 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index c7b8c0889..3e280b9c7 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cf0f54f6b..cdce144f3 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 07631d0c9..39c8be05d 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -5,6 +5,7 @@
  *
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a6b2af39d..45fab5a4d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 142bf668c..ed954134d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 743f16ae2..4922a5496 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
diff --git a/builtin/column.c b/builtin/column.c
index 33314b4d7..0c3223d64 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index f39c2b273..a4a923d7c 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index da1ba4c86..805da4915 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
diff --git a/builtin/config.c b/builtin/config.c
index 7f6c25d4d..753c40a5c 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "parse-options.h"
 #include "urlmatch.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index acb05940f..1d82e61f2 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 893c8789f..70eb14460 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index a572da9d5..965f2fb76 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index f084826a2..ad9971f64 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e40111204..36c220f93 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "log-tree.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 0c8f86e40..0d59e99ef 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index b9a892f26..9199227f6 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -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"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 24e29ad7e..0dfd980dd 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "object.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 47708451b..65317bd6c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2,6 +2,7 @@
  * "git fetch"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 70137b0b7..10cbb4341 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index eca365bf8..52be99cba 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index cb2ba6cd1..90593491e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index f484eda43..bd91f136f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7df9c253e..7f720ca6c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -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"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index bbeaf20bc..d04baf999 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -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"
diff --git a/builtin/help.c b/builtin/help.c
index 49f7a07f8..334a8494a 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -2,6 +2,7 @@
  * Builtin help command
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 04b9dcaf0..edc1a91d8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "delta.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 8a6acb0ec..47823f9aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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"
diff --git a/builtin/log.c b/builtin/log.c
index e89ec941c..01d7213c1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
  *		 2006 Junio Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc31..c4357dc30 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -6,6 +6,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ee7b293b1..ef965408e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 0c36a70ad..6dbd167d3 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 47dde7c39..b08803e61 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -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"
diff --git a/builtin/merge.c b/builtin/merge.c
index a4a098f40..2512370c1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "builtin.h"
 #include "lockfile.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 61d20037a..dcf6736b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Johannes Schindelin
  */
 #include "builtin.h"
+#include "config.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7fc7e66e8..e21715f1d 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 7196bff0e..8d14f434a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "notes.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f672225de..d5e96ed2d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 81552e02e..970d0d30b 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -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)
 {
diff --git a/builtin/pull.c b/builtin/pull.c
index da8b60fc8..0c77381da 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -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"
diff --git a/builtin/push.c b/builtin/push.c
index a597759d8..76aa713d2 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -2,6 +2,7 @@
  * "git push"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "run-command.h"
 #include "builtin.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 78d319365..6eb2a0e57 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "tree.h"
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index ca1ebb2fa..c82b4dce6 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "sequencer.h"
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b1706a573..71c0c768d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 920c16dac..44cdc2dbd 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe26..6273c0c23 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 38ba4ef82..f17a68a17 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index c921bc976..80a15cf35 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -9,6 +9,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1bf72423b..ffb66e290 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 430602d10..d0b604103 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 718c6059c..f8e2b7bf5 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index efdc14473..c78b7b33d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 345d9586a..16028b9ea 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 7c323d012..824d1de9e 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -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"
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index b8e2e74fe..633e0c3cd 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7cff1839f..43c4799ea 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "string-list.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 4a6cc6f49..e4cf1b5bb 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "builtin.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e62a008c..bdf032886 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8cc648d85..4dcbfb952 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 70addef15..df75cb9d4 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "cache.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 1f74a56db..01154ea8d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "tag.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6fc6bcdf7..73f133419 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 
 static char *create_temp_file(unsigned char *sha1)
 {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 8bc999776..193f8b9d5 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ebfc09faa..0a4c23648 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -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"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0b2ecf41a..40ccfc193 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6c8cc3edc..873070e51 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53a2..6c6f46b4a 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,6 +4,7 @@
  * Copyright (C) Eric Biederman, 2005
  */
 #include "builtin.h"
+#include "config.h"
 
 static const char var_usage[] = "git var (-l | <variable>)";
 
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05b734e6d..ba38ac9b1 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -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"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c94e15693..c2a1a5c50 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "parse-options.h"
 
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5199553d9..f9a5f7535 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -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"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 793306ea5..0c5476ee9 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "dir.h"
 #include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 084c0df78..bd0a78aa3 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
diff --git a/cache.h b/cache.h
index ed56f8818..fd45b8c55 100644
--- a/cache.h
+++ b/cache.h
@@ -11,7 +11,6 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
-#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
diff --git a/color.c b/color.c
index dee61557e..31b6207a0 100644
--- a/color.c
+++ b/color.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/column.c b/column.c
index d55ead18e..ff7bdab1a 100644
--- a/column.c
+++ b/column.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "column.h"
 #include "string-list.h"
 #include "parse-options.h"
diff --git a/config.c b/config.c
index 146cb3452..2390f98e3 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
diff --git a/connect.c b/connect.c
index c72b1d115..e78d3f43d 100644
--- a/connect.c
+++ b/connect.c
@@ -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"
diff --git a/convert.c b/convert.c
index f1e168bc3..5f4a4b1f5 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index f3814cc47..0d5c62509 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "credential.h"
 #include "unix-socket.h"
diff --git a/credential.c b/credential.c
index aa996669f..67a523353 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/daemon.c b/daemon.c
index ac7181a48..30747075f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index 5275c4b78..3458ec640 100644
--- a/diff.c
+++ b/diff.c
@@ -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"
diff --git a/dir.c b/dir.c
index 9efcf1eab..d4e4258ea 100644
--- a/dir.c
+++ b/dir.c
@@ -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"
diff --git a/environment.c b/environment.c
index aa478e71d..d40b21fb7 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
 #include "commit.h"
diff --git a/fast-import.c b/fast-import.c
index e69d21968..2881d4898 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -154,6 +154,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "blob.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index cd86865be..fbbc99c88 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/git.c b/git.c
index 8ff44f081..594436e43 100644
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "help.h"
 #include "run-command.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index e44cc27da..8ab32df45 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "gpg-interface.h"
diff --git a/graph.c b/graph.c
index 8b9049dd2..e7e20650d 100644
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "graph.h"
diff --git a/grep.c b/grep.c
index d03d424e5..62c7cf970 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "grep.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/help.c b/help.c
index db7f3d79a..5d44f811a 100644
--- a/help.c
+++ b/help.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/http-backend.c b/http-backend.c
index ba5ff1aa2..519025d2c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "object.h"
diff --git a/http-fetch.c b/http-fetch.c
index 3b556d661..8af380050 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "http.h"
 #include "walker.h"
diff --git a/http.c b/http.c
index d2e11ec6f..013bb0cc6 100644
--- a/http.c
+++ b/http.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "http.h"
+#include "config.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/ident.c b/ident.c
index bea871c8e..d41fc9119 100644
--- a/ident.c
+++ b/ident.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2005 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
diff --git a/imap-send.c b/imap-send.c
index 857591660..59e9b12d2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,6 +23,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/ll-merge.c b/ll-merge.c
index ac0d4a5d7..24ff94e1d 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
diff --git a/log-tree.c b/log-tree.c
index a4ec11c2b..7e1dfd749 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/mailinfo.c b/mailinfo.c
index f92cb9f72..f59162453 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index ae5238d82..c2494f34f 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -4,6 +4,7 @@
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
 #include "cache.h"
+#include "config.h"
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/notes-utils.c b/notes-utils.c
index 031503d7b..3f6cbdc47 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index 542563b28..dbcfef4d7 100644
--- a/notes.c
+++ b/notes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "notes.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/pager.c b/pager.c
index c113d898a..4dd9e1b26 100644
--- a/pager.c
+++ b/pager.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
 
diff --git a/parse-options.c b/parse-options.c
index e5ad34a2c..0dd9fc6a0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "utf8.h"
diff --git a/pathspec.c b/pathspec.c
index 828405021..ecc5331c2 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "attr.h"
diff --git a/pretty.c b/pretty.c
index 09701bd2f..9c9f81b5b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/prompt.c b/prompt.c
index 75406390c..6d5885d00 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
diff --git a/read-cache.c b/read-cache.c
index bc156a133..c8c766dab 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/refs.c b/refs.c
index f0685c925..84112c88e 100644
--- a/refs.c
+++ b/refs.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "lockfile.h"
 #include "iterator.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d8b3f7314..621a4086c 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,5 @@
 #include "../cache.h"
+#include "../config.h"
 #include "../refs.h"
 #include "refs-internal.h"
 #include "ref-cache.h"
diff --git a/remote-curl.c b/remote-curl.c
index ece45993d..0053b0954 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "strbuf.h"
 #include "walker.h"
diff --git a/remote.c b/remote.c
index 3649d60cd..68d20f650 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/rerere.c b/rerere.c
index 3bd55caf3..344d6aa81 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
diff --git a/send-pack.c b/send-pack.c
index 78bb34ebe..ed3cee321 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/sequencer.c b/sequencer.c
index 924fb1d0c..86b0640d2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index e3f7699a9..e99a82cbe 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "string-list.h"
 
diff --git a/sha1_file.c b/sha1_file.c
index 59a4ed2ed..44561e0b9 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "lockfile.h"
 #include "delta.h"
diff --git a/sha1_name.c b/sha1_name.c
index e9ffe685d..2875771ff 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/submodule-config.c b/submodule-config.c
index 4f58491dd..d8f8d5ea3 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
diff --git a/submodule.c b/submodule.c
index bf5a93d16..95328de61 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "dir.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 8e3ed6a76..1a7b8bd3d 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 2f144d539..c6c57bba0 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/trailer.c b/trailer.c
index 11f0b9fb4..751b56c00 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
diff --git a/transport.c b/transport.c
index 9bfcf870f..b9995306f 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "transport.h"
 #include "run-command.h"
 #include "pkt-line.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index d38c37e38..dd535bc84 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 5330c02c1..7efff2fbf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
diff --git a/userdiff.c b/userdiff.c
index 8b732e40b..2c1502f71 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "userdiff.h"
 #include "attr.h"
 
diff --git a/versioncmp.c b/versioncmp.c
index 9f81dc106..069ee94a4 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/wrapper.c b/wrapper.c
index d83741770..487a9f753 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "config.h"
 
 static void do_nothing(size_t size)
 {
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 060038c2d..5ac07d734 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
                   ` (2 preceding siblings ...)
  2017-06-12 21:34 ` [PATCH 3/4] config: don't include config.h by default Brandon Williams
@ 2017-06-12 21:34 ` Brandon Williams
  2017-06-13  1:05   ` Jonathan Nieder
  2017-06-12 21:45 ` [PATCH 0/4] config.h Jeff King
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:34 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, jrnieder, Brandon Williams

Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
not set up) added a 'git_dir' field to the config_options struct.  Let's
use this option field explicitly all the time instead of occasionally
falling back to calling 'git_pathdup("config")' to get the path to the
local repository configuration.  This allows 'do_git_config_sequence()'
to not implicitly rely on global repository state.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/config.c | 2 ++
 config.c         | 6 ++----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 753c40a5c..90f49a6ee 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -539,6 +539,8 @@ 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 (have_git_dir())
+		config_options.git_dir = get_git_common_dir();
 
 	if (end_null) {
 		term = '\0';
diff --git a/config.c b/config.c
index 2390f98e3..4e2842689 100644
--- a/config.c
+++ b/config.c
@@ -219,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;
 
@@ -1548,8 +1546,6 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 	if (opts->git_dir)
 		repo_config = mkpathdup("%s/config", opts->git_dir);
-	else if (have_git_dir())
-		repo_config = git_pathdup("config");
 	else
 		repo_config = NULL;
 
@@ -1613,6 +1609,8 @@ static void git_config_raw(config_fn_t fn, void *data)
 	struct config_options opts = {0};
 
 	opts.respect_includes = 1;
+	if (have_git_dir())
+		opts.git_dir = get_git_common_dir();
 	if (git_config_with_options(fn, data, NULL, &opts) < 0)
 		/*
 		 * git_config_with_options() normally returns only
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* Re: [PATCH 0/4] config.h
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
                   ` (3 preceding siblings ...)
  2017-06-12 21:34 ` [PATCH 4/4] config: don't implicitly use gitdir Brandon Williams
@ 2017-06-12 21:45 ` Jeff King
  2017-06-12 21:53   ` Brandon Williams
  2017-06-13  1:07 ` Jonathan Nieder
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
  6 siblings, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-12 21:45 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, jrnieder

On Mon, Jun 12, 2017 at 02:34:02PM -0700, Brandon Williams wrote:

> After some discussion I realized that my 'repository object' series was getting
> to be rather long and increase in scope.  So I've decided to break off these
> couple patches into their own series so they can be reviewed more easily.  This
> should also let them be merged in faster as I suspect it'll take a while for my
> 'repository object' series to be reviewed thourouly and these couple patches
> could result in a lot of merge conflicts as it touches a lot of files.
> 
> Brandon Williams (4):
>   config: create config.h
>   config: remove git_config_iter
>   config: don't include config.h by default
>   config: don't implicitly use gitdir

These all seem reasonable to me. Patch 3 made me shrug a little, because
it seems like the majority of C files end up including it anyway. I
suspect you could break config.h down into two files: the few things
that everybody needs (git_config() and the few parsing functions needed
in callbacks) and the ones for commands that actually manipulate the
config.

That would reduce the surface area of the module that most callers look
at, but I don't think there's a huge benefit to doing so (mostly it just
makes re-compiling faster by decreasing the chance that a dependent
header has changed for each file).

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 0/4] config.h
  2017-06-12 21:45 ` [PATCH 0/4] config.h Jeff King
@ 2017-06-12 21:53   ` Brandon Williams
  2017-06-12 22:02     ` Jeff King
  0 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 21:53 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, jrnieder

On 06/12, Jeff King wrote:
> On Mon, Jun 12, 2017 at 02:34:02PM -0700, Brandon Williams wrote:
> 
> > After some discussion I realized that my 'repository object' series was getting
> > to be rather long and increase in scope.  So I've decided to break off these
> > couple patches into their own series so they can be reviewed more easily.  This
> > should also let them be merged in faster as I suspect it'll take a while for my
> > 'repository object' series to be reviewed thourouly and these couple patches
> > could result in a lot of merge conflicts as it touches a lot of files.
> > 
> > Brandon Williams (4):
> >   config: create config.h
> >   config: remove git_config_iter
> >   config: don't include config.h by default
> >   config: don't implicitly use gitdir
> 
> These all seem reasonable to me. Patch 3 made me shrug a little, because
> it seems like the majority of C files end up including it anyway. I
> suspect you could break config.h down into two files: the few things
> that everybody needs (git_config() and the few parsing functions needed
> in callbacks) and the ones for commands that actually manipulate the
> config.
> 
> That would reduce the surface area of the module that most callers look
> at, but I don't think there's a huge benefit to doing so (mostly it just
> makes re-compiling faster by decreasing the chance that a dependent
> header has changed for each file).

Yes, ultimately I think it would be a good thing to break config.c down
into at least 2 more files (the file parsing logic and the config_set
logic) but that can be done at a later point.  I started looking at
doing that now but that logic is a little more entangled than I thought
it was.

Thanks for taking a look Jeff!

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 0/4] config.h
  2017-06-12 21:53   ` Brandon Williams
@ 2017-06-12 22:02     ` Jeff King
  2017-06-12 22:06       ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-12 22:02 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, jrnieder

On Mon, Jun 12, 2017 at 02:53:52PM -0700, Brandon Williams wrote:

> > These all seem reasonable to me. Patch 3 made me shrug a little, because
> > it seems like the majority of C files end up including it anyway. I
> > suspect you could break config.h down into two files: the few things
> > that everybody needs (git_config() and the few parsing functions needed
> > in callbacks) and the ones for commands that actually manipulate the
> > config.
> > 
> > That would reduce the surface area of the module that most callers look
> > at, but I don't think there's a huge benefit to doing so (mostly it just
> > makes re-compiling faster by decreasing the chance that a dependent
> > header has changed for each file).
> 
> Yes, ultimately I think it would be a good thing to break config.c down
> into at least 2 more files (the file parsing logic and the config_set
> logic) but that can be done at a later point.  I started looking at
> doing that now but that logic is a little more entangled than I thought
> it was.

To be clear, I don't mind that sort of module refactoring and like the
results.  But it almost certainly isn't the biggest bang-for-buck in
terms of the time it takes versus the benefit it brings. So take my
comment as "we could also do..." but not "we should not take your patch
because it does not go far enough".

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 0/4] config.h
  2017-06-12 22:02     ` Jeff King
@ 2017-06-12 22:06       ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-12 22:06 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, jrnieder

On 06/12, Jeff King wrote:
> On Mon, Jun 12, 2017 at 02:53:52PM -0700, Brandon Williams wrote:
> 
> > > These all seem reasonable to me. Patch 3 made me shrug a little, because
> > > it seems like the majority of C files end up including it anyway. I
> > > suspect you could break config.h down into two files: the few things
> > > that everybody needs (git_config() and the few parsing functions needed
> > > in callbacks) and the ones for commands that actually manipulate the
> > > config.
> > > 
> > > That would reduce the surface area of the module that most callers look
> > > at, but I don't think there's a huge benefit to doing so (mostly it just
> > > makes re-compiling faster by decreasing the chance that a dependent
> > > header has changed for each file).
> > 
> > Yes, ultimately I think it would be a good thing to break config.c down
> > into at least 2 more files (the file parsing logic and the config_set
> > logic) but that can be done at a later point.  I started looking at
> > doing that now but that logic is a little more entangled than I thought
> > it was.
> 
> To be clear, I don't mind that sort of module refactoring and like the
> results.  But it almost certainly isn't the biggest bang-for-buck in
> terms of the time it takes versus the benefit it brings. So take my
> comment as "we could also do..." but not "we should not take your patch
> because it does not go far enough".

Yes, that's how I understood your comment.  I realize that there's a lot
of improvements that can be done across our code base and one rabbit
hole that is easy to fall into is "fix all the things right now!" hence
why I decided to defer doing that to a later date.  And I agree that
doing that extra work doesn't buy us 'all too much'.

Having said that I do think it was worthwhile to remove the config
declarations from cache.h.  I think in the long term it would be nice to
limit cache.h's scope as it is very unapproachable in its current form.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 2/4] config: remove git_config_iter
  2017-06-12 21:34 ` [PATCH 2/4] config: remove git_config_iter Brandon Williams
@ 2017-06-13  0:49   ` Jonathan Nieder
  2017-06-13  0:57     ` Jeff King
  0 siblings, 1 reply; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13  0:49 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, gitster, Tanay Abhra

(+tanayabh)
Hi,

Brandon Williams wrote:

> Since there is no implementation of the function 'git_config_iter' lets
> stop exporting it and remove the prototype from config.h.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  config.h | 1 -
>  1 file changed, 1 deletion(-)

Good eyes.  Looks like the function never existed.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

> diff --git a/config.h b/config.h
> index f7f8b66c5..c70599bd5 100644
> --- a/config.h
> +++ b/config.h
> @@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, co
>  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);

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 2/4] config: remove git_config_iter
  2017-06-13  0:49   ` Jonathan Nieder
@ 2017-06-13  0:57     ` Jeff King
  0 siblings, 0 replies; 57+ messages in thread
From: Jeff King @ 2017-06-13  0:57 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Brandon Williams, git, gitster, Tanay Abhra

On Mon, Jun 12, 2017 at 05:49:11PM -0700, Jonathan Nieder wrote:

> > Since there is no implementation of the function 'git_config_iter' lets
> > stop exporting it and remove the prototype from config.h.
> >
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> >  config.h | 1 -
> >  1 file changed, 1 deletion(-)
> 
> Good eyes.  Looks like the function never existed.

You can find mention of it on the list[1,2] in early versions of Tanay's
patches. I think it was originally intended to be a variant of
git_config() that used the cache. But in the end, we made git_config()
do that by default (and added git_config_raw as its underlying helper).

I just looked that up to satisfy my curiosity. You are right that its
implementation never actually got committed, and clearly removing the
declaration is the right thing.

-Peff

[1] http://public-inbox.org/git/1404280905-26763-2-git-send-email-tanayabh@gmail.com/

[2] http://public-inbox.org/git/xmqqd2dnitm7.fsf@gitster.dls.corp.google.com/

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-12 21:34 ` [PATCH 4/4] config: don't implicitly use gitdir Brandon Williams
@ 2017-06-13  1:05   ` Jonathan Nieder
  2017-06-13  1:23     ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13  1:05 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, gitster

Hi,

Brandon Williams wrote:

> Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
> not set up) added a 'git_dir' field to the config_options struct.  Let's
> use this option field explicitly all the time instead of occasionally
> falling back to calling 'git_pathdup("config")' to get the path to the
> local repository configuration.  This allows 'do_git_config_sequence()'
> to not implicitly rely on global repository state.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  builtin/config.c | 2 ++
>  config.c         | 6 ++----
>  2 files changed, 4 insertions(+), 4 deletions(-)

Unlike the previous 3, this one makes me pause for a moment: it means
that "gitdir:" includes and .git/config discovery would stop working
if the caller does not remember to set git_dir in their
config_options.

So we have to inspect callers.

Callers that set respect_includes = 1:

- read_early_config carefully sets git_dir *phew*
- git_config_raw doesn't and is used approximately everywhere.

do_git_config_sequence call chain:
- called by git_config_with_options, which is called by
  - read_early_config
  - git_config_raw
  - various callers in builtin/config.c, using &config_options

> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -539,6 +539,8 @@ 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 (have_git_dir())
> +		config_options.git_dir = get_git_common_dir();

nit: because of the context, this 'if' can be "if (!nongit)".

[...]
> --- a/config.c
> +++ b/config.c
> @@ -219,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;

I wonder if this should have a sanity-check:

	else if (have_git_dir())
		BUG("caller forgot to set opts->git_dir");

Alternatively, could this patch rename git_config_with_options?  That
way any other patch in flight that calls git_config_with_options would
conflict with this patch, giving us an opportunity to make sure it
also sets git_dir.  As another nice side benefit it would make it easy
for someone reading the patch to verify it didn't miss any callers.

> @@ -1548,8 +1546,6 @@ static int do_git_config_sequence(const struct config_options *opts,
>  
>  	if (opts->git_dir)
>  		repo_config = mkpathdup("%s/config", opts->git_dir);
> -	else if (have_git_dir())
> -		repo_config = git_pathdup("config");
>  	else
>  		repo_config = NULL;

Likewise: either this should get a sanity check

	else if (have_git_dir())
		BUG("caller forgot to set opts->git_dir");

or the public interface git_config_with_options should be renamed.

> @@ -1613,6 +1609,8 @@ static void git_config_raw(config_fn_t fn, void *data)
>  	struct config_options opts = {0};
>  
>  	opts.respect_includes = 1;
> +	if (have_git_dir())
> +		opts.git_dir = get_git_common_dir();

curious: Why get_git_common_dir() instead of get_git_dir()?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 0/4] config.h
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
                   ` (4 preceding siblings ...)
  2017-06-12 21:45 ` [PATCH 0/4] config.h Jeff King
@ 2017-06-13  1:07 ` Jonathan Nieder
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
  6 siblings, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13  1:07 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, gitster

Brandon Williams wrote:

> Brandon Williams (4):
>   config: create config.h
>   config: remove git_config_iter
>   config: don't include config.h by default
>   config: don't implicitly use gitdir

Patches 1-3 are

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

I'm very happy to see cache.h getting shorter and less intimidating.

I have some minor concerns with patch 4 that I described in a reply to
that patch.  I'd expect that after another round that one will be
ready.

Thanks for a pleasant read.

Sincerely,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  1:05   ` Jonathan Nieder
@ 2017-06-13  1:23     ` Brandon Williams
  2017-06-13  1:33       ` Jonathan Nieder
  2017-06-13  1:38       ` Jonathan Nieder
  0 siblings, 2 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13  1:23 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, peff, gitster

On 06/12, Jonathan Nieder wrote:
> Hi,
> 
> Brandon Williams wrote:
> 
> > Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
> > not set up) added a 'git_dir' field to the config_options struct.  Let's
> > use this option field explicitly all the time instead of occasionally
> > falling back to calling 'git_pathdup("config")' to get the path to the
> > local repository configuration.  This allows 'do_git_config_sequence()'
> > to not implicitly rely on global repository state.
> >
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> >  builtin/config.c | 2 ++
> >  config.c         | 6 ++----
> >  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> Unlike the previous 3, this one makes me pause for a moment: it means
> that "gitdir:" includes and .git/config discovery would stop working
> if the caller does not remember to set git_dir in their
> config_options.
> 
> So we have to inspect callers.
> 
> Callers that set respect_includes = 1:
> 
> - read_early_config carefully sets git_dir *phew*
> - git_config_raw doesn't and is used approximately everywhere.
> 
> do_git_config_sequence call chain:
> - called by git_config_with_options, which is called by
>   - read_early_config
>   - git_config_raw
>   - various callers in builtin/config.c, using &config_options
> 
> > --- a/builtin/config.c
> > +++ b/builtin/config.c
> > @@ -539,6 +539,8 @@ 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 (have_git_dir())
> > +		config_options.git_dir = get_git_common_dir();
> 
> nit: because of the context, this 'if' can be "if (!nongit)".

Will do.

> 
> [...]
> > --- a/config.c
> > +++ b/config.c
> > @@ -219,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;
> 
> I wonder if this should have a sanity-check:
> 
> 	else if (have_git_dir())
> 		BUG("caller forgot to set opts->git_dir");
> 
> Alternatively, could this patch rename git_config_with_options?  That
> way any other patch in flight that calls git_config_with_options would
> conflict with this patch, giving us an opportunity to make sure it
> also sets git_dir.  As another nice side benefit it would make it easy
> for someone reading the patch to verify it didn't miss any callers.

That kind of defeats the purpose of the patch.  The point is to not rely
on global repository state and with the BUG statement we still are
relying on global state.

And I don't know if I agree with renaming a function just to rename it.

> 
> > @@ -1548,8 +1546,6 @@ static int do_git_config_sequence(const struct config_options *opts,
> >  
> >  	if (opts->git_dir)
> >  		repo_config = mkpathdup("%s/config", opts->git_dir);
> > -	else if (have_git_dir())
> > -		repo_config = git_pathdup("config");
> >  	else
> >  		repo_config = NULL;
> 
> Likewise: either this should get a sanity check
> 
> 	else if (have_git_dir())
> 		BUG("caller forgot to set opts->git_dir");
> 
> or the public interface git_config_with_options should be renamed.
> 
> > @@ -1613,6 +1609,8 @@ static void git_config_raw(config_fn_t fn, void *data)
> >  	struct config_options opts = {0};
> >  
> >  	opts.respect_includes = 1;
> > +	if (have_git_dir())
> > +		opts.git_dir = get_git_common_dir();
> 
> curious: Why get_git_common_dir() instead of get_git_dir()?

Needs to be commondir since the config is stored in the common git
directory and not a per worktree git directory.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  1:23     ` Brandon Williams
@ 2017-06-13  1:33       ` Jonathan Nieder
  2017-06-13  1:38       ` Jonathan Nieder
  1 sibling, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13  1:33 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, gitster

Brandon Williams wrote:
> On 06/12, Jonathan Nieder wrote:
>> Brandon Williams wrote:

>>> Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
>>> not set up) added a 'git_dir' field to the config_options struct.  Let's
>>> use this option field explicitly all the time instead of occasionally
>>> falling back to calling 'git_pathdup("config")' to get the path to the
>>> local repository configuration.  This allows 'do_git_config_sequence()'
>>> to not implicitly rely on global repository state.
>>>
>>> Signed-off-by: Brandon Williams <bmwill@google.com>
[...]
>> Unlike the previous 3, this one makes me pause for a moment: it means
>> that "gitdir:" includes and .git/config discovery would stop working
>> if the caller does not remember to set git_dir in their
>> config_options.
>>
>> So we have to inspect callers.
[...]
>> nit: because of the context, this 'if' can be "if (!nongit)".
>
> Will do.

Thanks.

[...]
>>> +++ b/config.c
>>> @@ -219,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;
>>
>> I wonder if this should have a sanity-check:
>>
>> 	else if (have_git_dir())
>> 		BUG("caller forgot to set opts->git_dir");
>>
>> Alternatively, could this patch rename git_config_with_options?  That
>> way any other patch in flight that calls git_config_with_options would
>> conflict with this patch, giving us an opportunity to make sure it
>> also sets git_dir.  As another nice side benefit it would make it easy
>> for someone reading the patch to verify it didn't miss any callers.
>
> That kind of defeats the purpose of the patch.  The point is to not rely
> on global repository state and with the BUG statement we still are
> relying on global state.

By "that" are you referring to the BUG()?  I agree --- I'd prefer
renaming the function over adding a BUG() to catch mistaken old callers,
so I shouldn't have mentioned the idea.  I mentioned it to give another
example of how to make this kind of change safely.

> And I don't know if I agree with renaming a function just to rename it.

It is not renaming just to rename: this is approximately the only safe
way that the Git project has to make a significant breaking change to
the API of a function.  In a project where people push directly to the
repository in a fast-forward way, it may be possible to make such a
change by announcing it loudly and relying on patch authors keeping
track of what is happening in the repository.  But in a project like
Git that juggles multiple patches in flight, some more explicit
coordination, for example by renaming the identifier, is needed.

Sorry.

Do you have another method in mind?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  1:23     ` Brandon Williams
  2017-06-13  1:33       ` Jonathan Nieder
@ 2017-06-13  1:38       ` Jonathan Nieder
  2017-06-13  2:59         ` Jeff King
  2017-06-13  5:52         ` Brandon Williams
  1 sibling, 2 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13  1:38 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, gitster

Hi again,

Brandon Williams wrote:
> On 06/12, Jonathan Nieder wrote:

>> Alternatively, could this patch rename git_config_with_options?  That
>> way any other patch in flight that calls git_config_with_options would
>> conflict with this patch, giving us an opportunity to make sure it
>> also sets git_dir.  As another nice side benefit it would make it easy
>> for someone reading the patch to verify it didn't miss any callers.
[...]
> And I don't know if I agree with renaming a function just to rename it.

I forgot to say: another way to accomplish the same thing can be to
reorder the function's arguments.  The relevant thing is to make code
that calls the function without being aware of the new requirements
fail to compile.

[...]
>> Brandon Williams wrote:

>>>  	opts.respect_includes = 1;
>>> +	if (have_git_dir())
>>> +		opts.git_dir = get_git_common_dir();
>>
>> curious: Why get_git_common_dir() instead of get_git_dir()?
>
> Needs to be commondir since the config is stored in the common git
> directory and not a per worktree git directory.

*puzzled* Why wasn't this needed before, then?  The rest of the patch
should result in no functional change, but this part seems different.

Please add some explanation to the commit message.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  1:38       ` Jonathan Nieder
@ 2017-06-13  2:59         ` Jeff King
  2017-06-13  6:16           ` Brandon Williams
  2017-06-13 17:06           ` Jonathan Nieder
  2017-06-13  5:52         ` Brandon Williams
  1 sibling, 2 replies; 57+ messages in thread
From: Jeff King @ 2017-06-13  2:59 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Brandon Williams, git, gitster

On Mon, Jun 12, 2017 at 06:38:17PM -0700, Jonathan Nieder wrote:

> Brandon Williams wrote:
> > On 06/12, Jonathan Nieder wrote:
> 
> >> Alternatively, could this patch rename git_config_with_options?  That
> >> way any other patch in flight that calls git_config_with_options would
> >> conflict with this patch, giving us an opportunity to make sure it
> >> also sets git_dir.  As another nice side benefit it would make it easy
> >> for someone reading the patch to verify it didn't miss any callers.
> [...]
> > And I don't know if I agree with renaming a function just to rename it.
> 
> I forgot to say: another way to accomplish the same thing can be to
> reorder the function's arguments.  The relevant thing is to make code
> that calls the function without being aware of the new requirements
> fail to compile.

If the parameter is now required, then it might make sense for it to
become an actual function parameter instead of being stuffed into the
config_options struct. That would give you your breaking change, plus
make it more obvious to the reader that it is not optional.

The downside is that has to get shuttled around manually through the
callstack. Most of the damage is in builtin/config.c, where we call
git_config_with_options() a lot.

include_by_gitdir is also a bit annoying, as we pass around the
config_options struct through our void-pointer callbacks. But we can
solve that by sticking the git_dir into the include_data struct (whose
exact purpose is to carry the information we need to handle includes).

The patch below (on top of Brandon's series does that).

> >>> +	if (have_git_dir())
> >>> +		opts.git_dir = get_git_common_dir();
> >>
> >> curious: Why get_git_common_dir() instead of get_git_dir()?
> >
> > Needs to be commondir since the config is stored in the common git
> > directory and not a per worktree git directory.
> 
> *puzzled* Why wasn't this needed before, then?  The rest of the patch
> should result in no functional change, but this part seems different.

Now I'm puzzled, too. The original that got filled in lazily by the
config functions was always get_git_dir(). I can buy the argument that
this was a bug (I'm not familiar enough with worktree to say one way or
the other), but if it's a fix it should definitely go into another
patch.

---
 builtin/config.c | 17 ++++++++++----
 config.c         | 43 +++++++++++++++++++----------------
 config.h         |  4 ++--
 3 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 90f49a6ee..f5dd6f7ff 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -29,6 +29,7 @@ static int actions, types;
 static int end_null;
 static int respect_includes_opt = -1;
 static struct config_options config_options;
+const char *config_git_dir;
 static int show_origin;
 
 #define ACTION_GET (1<<0)
@@ -244,7 +245,9 @@ static int get_value(const char *key_, const char *regex_)
 	}
 
 	git_config_with_options(collect_config, &values,
-				&given_config_source, &config_options);
+				&given_config_source,
+				config_git_dir,
+				&config_options);
 
 	ret = !values.nr;
 
@@ -322,7 +325,8 @@ static void get_color(const char *var, const char *def_color)
 	get_color_found = 0;
 	parsed_color[0] = '\0';
 	git_config_with_options(git_get_color_config, NULL,
-				&given_config_source, &config_options);
+				&given_config_source,
+				config_git_dir, &config_options);
 
 	if (!get_color_found && def_color) {
 		if (color_parse(def_color, parsed_color) < 0)
@@ -354,7 +358,8 @@ static int get_colorbool(const char *var, int print)
 	get_diff_color_found = -1;
 	get_color_ui_found = -1;
 	git_config_with_options(git_get_colorbool_config, NULL,
-				&given_config_source, &config_options);
+				&given_config_source,
+				config_git_dir, &config_options);
 
 	if (get_colorbool_found < 0) {
 		if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -443,7 +448,8 @@ static int get_urlmatch(const char *var, const char *url)
 	}
 
 	git_config_with_options(urlmatch_config_entry, &config,
-				&given_config_source, &config_options);
+				&given_config_source, config_git_dir,
+				&config_options);
 
 	ret = !values.nr;
 
@@ -540,7 +546,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	else
 		config_options.respect_includes = respect_includes_opt;
 	if (have_git_dir())
-		config_options.git_dir = get_git_common_dir();
+		config_git_dir = get_git_common_dir();
 
 	if (end_null) {
 		term = '\0';
@@ -587,6 +593,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		check_argc(argc, 0, 0);
 		if (git_config_with_options(show_all_config, NULL,
 					    &given_config_source,
+					    config_git_dir,
 					    &config_options) < 0) {
 			if (given_config_source.file)
 				die_errno("unable to read config file '%s'",
diff --git a/config.c b/config.c
index 4e2842689..e1566f7b4 100644
--- a/config.c
+++ b/config.c
@@ -208,21 +208,18 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
 	return prefix;
 }
 
-static int include_by_gitdir(const struct config_options *opts,
+static int include_by_gitdir(const struct config_include_data *inc,
 			     const char *cond, size_t cond_len, int icase)
 {
 	struct strbuf text = STRBUF_INIT;
 	struct strbuf pattern = STRBUF_INIT;
 	int ret = 0, prefix;
-	const char *git_dir;
 	int already_tried_absolute = 0;
 
-	if (opts->git_dir)
-		git_dir = opts->git_dir;
-	else
+	if (!inc->git_dir)
 		goto done;
 
-	strbuf_realpath(&text, git_dir, 1);
+	strbuf_realpath(&text, inc->git_dir, 1);
 	strbuf_add(&pattern, cond, cond_len);
 	prefix = prepare_include_condition_pattern(&pattern);
 
@@ -256,7 +253,7 @@ static int include_by_gitdir(const struct config_options *opts,
 		 * which'll do the right thing
 		 */
 		strbuf_reset(&text);
-		strbuf_add_absolute_path(&text, git_dir);
+		strbuf_add_absolute_path(&text, inc->git_dir);
 		already_tried_absolute = 1;
 		goto again;
 	}
@@ -266,14 +263,14 @@ static int include_by_gitdir(const struct config_options *opts,
 	return ret;
 }
 
-static int include_condition_is_true(const struct config_options *opts,
+static int include_condition_is_true(const struct config_include_data *inc,
 				     const char *cond, size_t cond_len)
 {
 
 	if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
-		return include_by_gitdir(opts, cond, cond_len, 0);
+		return include_by_gitdir(inc, cond, cond_len, 0);
 	else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
-		return include_by_gitdir(opts, cond, cond_len, 1);
+		return include_by_gitdir(inc, cond, cond_len, 1);
 
 	/* unknown conditionals are always false */
 	return 0;
@@ -298,7 +295,7 @@ int git_config_include(const char *var, const char *value, void *data)
 		ret = handle_path_include(value, inc);
 
 	if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
-	    (cond && include_condition_is_true(inc->opts, cond, cond_len)) &&
+	    (cond && include_condition_is_true(inc, cond, cond_len)) &&
 	    !strcmp(key, "path"))
 		ret = handle_path_include(value, inc);
 
@@ -1537,6 +1534,7 @@ int git_config_system(void)
 }
 
 static int do_git_config_sequence(const struct config_options *opts,
+				  const char *git_dir,
 				  config_fn_t fn, void *data)
 {
 	int ret = 0;
@@ -1544,8 +1542,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);
+	if (git_dir)
+		repo_config = mkpathdup("%s/config", git_dir);
 	else
 		repo_config = NULL;
 
@@ -1578,6 +1576,7 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 int git_config_with_options(config_fn_t fn, void *data,
 			    struct git_config_source *config_source,
+			    const char *git_dir,
 			    const struct config_options *opts)
 {
 	struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -1585,7 +1584,7 @@ int git_config_with_options(config_fn_t fn, void *data,
 	if (opts->respect_includes) {
 		inc.fn = fn;
 		inc.data = data;
-		inc.opts = opts;
+		inc.git_dir = git_dir;
 		fn = git_config_include;
 		data = &inc;
 	}
@@ -1601,17 +1600,18 @@ int git_config_with_options(config_fn_t fn, void *data,
 	else if (config_source && config_source->blob)
 		return git_config_from_blob_ref(fn, config_source->blob, data);
 
-	return do_git_config_sequence(opts, fn, data);
+	return do_git_config_sequence(opts, git_dir, fn, data);
 }
 
 static void git_config_raw(config_fn_t fn, void *data)
 {
 	struct config_options opts = {0};
+	const char *git_dir;
 
 	opts.respect_includes = 1;
 	if (have_git_dir())
-		opts.git_dir = get_git_common_dir();
-	if (git_config_with_options(fn, data, NULL, &opts) < 0)
+		git_dir = get_git_common_dir();
+	if (git_config_with_options(fn, data, NULL, git_dir, &opts) < 0)
 		/*
 		 * git_config_with_options() normally returns only
 		 * zero, as most errors are fatal, and
@@ -1653,11 +1653,12 @@ void read_early_config(config_fn_t cb, void *data)
 {
 	struct config_options opts = {0};
 	struct strbuf buf = STRBUF_INIT;
+	const char *git_dir;
 
 	opts.respect_includes = 1;
 
 	if (have_git_dir())
-		opts.git_dir = get_git_dir();
+		git_dir = get_git_dir();
 	/*
 	 * When setup_git_directory() was not yet asked to discover the
 	 * GIT_DIR, we ask discover_git_directory() to figure out whether there
@@ -1667,9 +1668,11 @@ void read_early_config(config_fn_t cb, void *data)
 	 * call).
 	 */
 	else if (discover_git_directory(&buf))
-		opts.git_dir = buf.buf;
+		git_dir = buf.buf;
+	else
+		git_dir = NULL;
 
-	git_config_with_options(cb, data, NULL, &opts);
+	git_config_with_options(cb, data, NULL, git_dir, &opts);
 
 	strbuf_release(&buf);
 }
diff --git a/config.h b/config.h
index c70599bd5..47a8e8845 100644
--- a/config.h
+++ b/config.h
@@ -30,7 +30,6 @@ enum config_origin_type {
 
 struct config_options {
 	unsigned int respect_includes : 1;
-	const char *git_dir;
 };
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
@@ -46,6 +45,7 @@ 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 char *git_dir,
 				   const struct config_options *opts);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_parse_maybe_bool(const char *);
@@ -97,7 +97,7 @@ struct config_include_data {
 	int depth;
 	config_fn_t fn;
 	void *data;
-	const struct config_options *opts;
+	const char *git_dir;
 };
 #define CONFIG_INCLUDE_INIT { 0 }
 extern int git_config_include(const char *name, const char *value, void *data);

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  1:38       ` Jonathan Nieder
  2017-06-13  2:59         ` Jeff King
@ 2017-06-13  5:52         ` Brandon Williams
  2017-06-13  6:29           ` Jeff King
  1 sibling, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13  5:52 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, peff, gitster

On 06/12, Jonathan Nieder wrote:
> Hi again,
> 
> Brandon Williams wrote:
> > On 06/12, Jonathan Nieder wrote:
> 
> >> Alternatively, could this patch rename git_config_with_options?  That
> >> way any other patch in flight that calls git_config_with_options would
> >> conflict with this patch, giving us an opportunity to make sure it
> >> also sets git_dir.  As another nice side benefit it would make it easy
> >> for someone reading the patch to verify it didn't miss any callers.
> [...]
> > And I don't know if I agree with renaming a function just to rename it.
> 
> I forgot to say: another way to accomplish the same thing can be to
> reorder the function's arguments.  The relevant thing is to make code
> that calls the function without being aware of the new requirements
> fail to compile.
> 
> [...]
> >> Brandon Williams wrote:
> 
> >>>  	opts.respect_includes = 1;
> >>> +	if (have_git_dir())
> >>> +		opts.git_dir = get_git_common_dir();
> >>
> >> curious: Why get_git_common_dir() instead of get_git_dir()?
> >
> > Needs to be commondir since the config is stored in the common git
> > directory and not a per worktree git directory.
> 
> *puzzled* Why wasn't this needed before, then?  The rest of the patch
> should result in no functional change, but this part seems different.

there is no functional change, this is what always happened.
git_path("config") will replace gitdir with commondir under the hood.

> 
> Please add some explanation to the commit message.
> 
> Thanks,
> Jonathan

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  2:59         ` Jeff King
@ 2017-06-13  6:16           ` Brandon Williams
  2017-06-13  6:45             ` Jeff King
  2017-06-13  7:08             ` Jeff King
  2017-06-13 17:06           ` Jonathan Nieder
  1 sibling, 2 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13  6:16 UTC (permalink / raw)
  To: Jeff King; +Cc: Jonathan Nieder, git, gitster

On 06/12, Jeff King wrote:
> On Mon, Jun 12, 2017 at 06:38:17PM -0700, Jonathan Nieder wrote:
> 
> > Brandon Williams wrote:
> > > On 06/12, Jonathan Nieder wrote:
> > 
> > >> Alternatively, could this patch rename git_config_with_options?  That
> > >> way any other patch in flight that calls git_config_with_options would
> > >> conflict with this patch, giving us an opportunity to make sure it
> > >> also sets git_dir.  As another nice side benefit it would make it easy
> > >> for someone reading the patch to verify it didn't miss any callers.
> > [...]
> > > And I don't know if I agree with renaming a function just to rename it.
> > 
> > I forgot to say: another way to accomplish the same thing can be to
> > reorder the function's arguments.  The relevant thing is to make code
> > that calls the function without being aware of the new requirements
> > fail to compile.
> 
> If the parameter is now required, then it might make sense for it to
> become an actual function parameter instead of being stuffed into the
> config_options struct. That would give you your breaking change, plus
> make it more obvious to the reader that it is not optional.
> 
> The downside is that has to get shuttled around manually through the
> callstack. Most of the damage is in builtin/config.c, where we call
> git_config_with_options() a lot.
> 
> include_by_gitdir is also a bit annoying, as we pass around the
> config_options struct through our void-pointer callbacks. But we can
> solve that by sticking the git_dir into the include_data struct (whose
> exact purpose is to carry the information we need to handle includes).
> 
> The patch below (on top of Brandon's series does that).

I really don't understand why this has to be so difficult and why a
'breaking change' is even needed.  Duy just added the 'git_dir' field to
the config_options struct in April of this year (2185fde56 config:
handle conditional include when $GIT_DIR is not set up) and now we want
to strip it out again?  That's not even two months. Seems very counter
productive and makes the api more unwieldy.

> 
> > >>> +	if (have_git_dir())
> > >>> +		opts.git_dir = get_git_common_dir();
> > >>
> > >> curious: Why get_git_common_dir() instead of get_git_dir()?
> > >
> > > Needs to be commondir since the config is stored in the common git
> > > directory and not a per worktree git directory.
> > 
> > *puzzled* Why wasn't this needed before, then?  The rest of the patch
> > should result in no functional change, but this part seems different.
> 
> Now I'm puzzled, too. The original that got filled in lazily by the
> config functions was always get_git_dir(). I can buy the argument that
> this was a bug (I'm not familiar enough with worktree to say one way or
> the other), but if it's a fix it should definitely go into another
> patch.

Well actually... in do_git_config_sequence 'git_path("config")' is
called which will convert gitdir to commondir under the hood.  you can't
use vanilla gitdir because the config isn't stored in a worktree's
gitdir but rather in the commondir as the config is shared by all
worktrees.

So maybe we actually need to add a field to the 'config_options' struct
of 'commondir' such that the commondir can be used to load the actual
config file and 'gitdir' can be used to handle the 'IncludeIf' stuff.

> 
> ---
>  builtin/config.c | 17 ++++++++++----
>  config.c         | 43 +++++++++++++++++++----------------
>  config.h         |  4 ++--
>  3 files changed, 37 insertions(+), 27 deletions(-)
> 
> diff --git a/builtin/config.c b/builtin/config.c
> index 90f49a6ee..f5dd6f7ff 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -29,6 +29,7 @@ static int actions, types;
>  static int end_null;
>  static int respect_includes_opt = -1;
>  static struct config_options config_options;
> +const char *config_git_dir;
>  static int show_origin;
>  
>  #define ACTION_GET (1<<0)
> @@ -244,7 +245,9 @@ static int get_value(const char *key_, const char *regex_)
>  	}
>  
>  	git_config_with_options(collect_config, &values,
> -				&given_config_source, &config_options);
> +				&given_config_source,
> +				config_git_dir,
> +				&config_options);
>  
>  	ret = !values.nr;
>  
> @@ -322,7 +325,8 @@ static void get_color(const char *var, const char *def_color)
>  	get_color_found = 0;
>  	parsed_color[0] = '\0';
>  	git_config_with_options(git_get_color_config, NULL,
> -				&given_config_source, &config_options);
> +				&given_config_source,
> +				config_git_dir, &config_options);
>  
>  	if (!get_color_found && def_color) {
>  		if (color_parse(def_color, parsed_color) < 0)
> @@ -354,7 +358,8 @@ static int get_colorbool(const char *var, int print)
>  	get_diff_color_found = -1;
>  	get_color_ui_found = -1;
>  	git_config_with_options(git_get_colorbool_config, NULL,
> -				&given_config_source, &config_options);
> +				&given_config_source,
> +				config_git_dir, &config_options);
>  
>  	if (get_colorbool_found < 0) {
>  		if (!strcmp(get_colorbool_slot, "color.diff"))
> @@ -443,7 +448,8 @@ static int get_urlmatch(const char *var, const char *url)
>  	}
>  
>  	git_config_with_options(urlmatch_config_entry, &config,
> -				&given_config_source, &config_options);
> +				&given_config_source, config_git_dir,
> +				&config_options);
>  
>  	ret = !values.nr;
>  
> @@ -540,7 +546,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
>  	else
>  		config_options.respect_includes = respect_includes_opt;
>  	if (have_git_dir())
> -		config_options.git_dir = get_git_common_dir();
> +		config_git_dir = get_git_common_dir();
>  
>  	if (end_null) {
>  		term = '\0';
> @@ -587,6 +593,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
>  		check_argc(argc, 0, 0);
>  		if (git_config_with_options(show_all_config, NULL,
>  					    &given_config_source,
> +					    config_git_dir,
>  					    &config_options) < 0) {
>  			if (given_config_source.file)
>  				die_errno("unable to read config file '%s'",
> diff --git a/config.c b/config.c
> index 4e2842689..e1566f7b4 100644
> --- a/config.c
> +++ b/config.c
> @@ -208,21 +208,18 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
>  	return prefix;
>  }
>  
> -static int include_by_gitdir(const struct config_options *opts,
> +static int include_by_gitdir(const struct config_include_data *inc,
>  			     const char *cond, size_t cond_len, int icase)
>  {
>  	struct strbuf text = STRBUF_INIT;
>  	struct strbuf pattern = STRBUF_INIT;
>  	int ret = 0, prefix;
> -	const char *git_dir;
>  	int already_tried_absolute = 0;
>  
> -	if (opts->git_dir)
> -		git_dir = opts->git_dir;
> -	else
> +	if (!inc->git_dir)
>  		goto done;
>  
> -	strbuf_realpath(&text, git_dir, 1);
> +	strbuf_realpath(&text, inc->git_dir, 1);
>  	strbuf_add(&pattern, cond, cond_len);
>  	prefix = prepare_include_condition_pattern(&pattern);
>  
> @@ -256,7 +253,7 @@ static int include_by_gitdir(const struct config_options *opts,
>  		 * which'll do the right thing
>  		 */
>  		strbuf_reset(&text);
> -		strbuf_add_absolute_path(&text, git_dir);
> +		strbuf_add_absolute_path(&text, inc->git_dir);
>  		already_tried_absolute = 1;
>  		goto again;
>  	}
> @@ -266,14 +263,14 @@ static int include_by_gitdir(const struct config_options *opts,
>  	return ret;
>  }
>  
> -static int include_condition_is_true(const struct config_options *opts,
> +static int include_condition_is_true(const struct config_include_data *inc,
>  				     const char *cond, size_t cond_len)
>  {
>  
>  	if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
> -		return include_by_gitdir(opts, cond, cond_len, 0);
> +		return include_by_gitdir(inc, cond, cond_len, 0);
>  	else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
> -		return include_by_gitdir(opts, cond, cond_len, 1);
> +		return include_by_gitdir(inc, cond, cond_len, 1);
>  
>  	/* unknown conditionals are always false */
>  	return 0;
> @@ -298,7 +295,7 @@ int git_config_include(const char *var, const char *value, void *data)
>  		ret = handle_path_include(value, inc);
>  
>  	if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
> -	    (cond && include_condition_is_true(inc->opts, cond, cond_len)) &&
> +	    (cond && include_condition_is_true(inc, cond, cond_len)) &&
>  	    !strcmp(key, "path"))
>  		ret = handle_path_include(value, inc);
>  
> @@ -1537,6 +1534,7 @@ int git_config_system(void)
>  }
>  
>  static int do_git_config_sequence(const struct config_options *opts,
> +				  const char *git_dir,
>  				  config_fn_t fn, void *data)
>  {
>  	int ret = 0;
> @@ -1544,8 +1542,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);
> +	if (git_dir)
> +		repo_config = mkpathdup("%s/config", git_dir);
>  	else
>  		repo_config = NULL;
>  
> @@ -1578,6 +1576,7 @@ static int do_git_config_sequence(const struct config_options *opts,
>  
>  int git_config_with_options(config_fn_t fn, void *data,
>  			    struct git_config_source *config_source,
> +			    const char *git_dir,
>  			    const struct config_options *opts)
>  {
>  	struct config_include_data inc = CONFIG_INCLUDE_INIT;
> @@ -1585,7 +1584,7 @@ int git_config_with_options(config_fn_t fn, void *data,
>  	if (opts->respect_includes) {
>  		inc.fn = fn;
>  		inc.data = data;
> -		inc.opts = opts;
> +		inc.git_dir = git_dir;
>  		fn = git_config_include;
>  		data = &inc;
>  	}
> @@ -1601,17 +1600,18 @@ int git_config_with_options(config_fn_t fn, void *data,
>  	else if (config_source && config_source->blob)
>  		return git_config_from_blob_ref(fn, config_source->blob, data);
>  
> -	return do_git_config_sequence(opts, fn, data);
> +	return do_git_config_sequence(opts, git_dir, fn, data);
>  }
>  
>  static void git_config_raw(config_fn_t fn, void *data)
>  {
>  	struct config_options opts = {0};
> +	const char *git_dir;
>  
>  	opts.respect_includes = 1;
>  	if (have_git_dir())
> -		opts.git_dir = get_git_common_dir();
> -	if (git_config_with_options(fn, data, NULL, &opts) < 0)
> +		git_dir = get_git_common_dir();
> +	if (git_config_with_options(fn, data, NULL, git_dir, &opts) < 0)
>  		/*
>  		 * git_config_with_options() normally returns only
>  		 * zero, as most errors are fatal, and
> @@ -1653,11 +1653,12 @@ void read_early_config(config_fn_t cb, void *data)
>  {
>  	struct config_options opts = {0};
>  	struct strbuf buf = STRBUF_INIT;
> +	const char *git_dir;
>  
>  	opts.respect_includes = 1;
>  
>  	if (have_git_dir())
> -		opts.git_dir = get_git_dir();
> +		git_dir = get_git_dir();
>  	/*
>  	 * When setup_git_directory() was not yet asked to discover the
>  	 * GIT_DIR, we ask discover_git_directory() to figure out whether there
> @@ -1667,9 +1668,11 @@ void read_early_config(config_fn_t cb, void *data)
>  	 * call).
>  	 */
>  	else if (discover_git_directory(&buf))
> -		opts.git_dir = buf.buf;
> +		git_dir = buf.buf;
> +	else
> +		git_dir = NULL;
>  
> -	git_config_with_options(cb, data, NULL, &opts);
> +	git_config_with_options(cb, data, NULL, git_dir, &opts);
>  
>  	strbuf_release(&buf);
>  }
> diff --git a/config.h b/config.h
> index c70599bd5..47a8e8845 100644
> --- a/config.h
> +++ b/config.h
> @@ -30,7 +30,6 @@ enum config_origin_type {
>  
>  struct config_options {
>  	unsigned int respect_includes : 1;
> -	const char *git_dir;
>  };
>  
>  typedef int (*config_fn_t)(const char *, const char *, void *);
> @@ -46,6 +45,7 @@ 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 char *git_dir,
>  				   const struct config_options *opts);
>  extern int git_parse_ulong(const char *, unsigned long *);
>  extern int git_parse_maybe_bool(const char *);
> @@ -97,7 +97,7 @@ struct config_include_data {
>  	int depth;
>  	config_fn_t fn;
>  	void *data;
> -	const struct config_options *opts;
> +	const char *git_dir;
>  };
>  #define CONFIG_INCLUDE_INIT { 0 }
>  extern int git_config_include(const char *name, const char *value, void *data);

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  5:52         ` Brandon Williams
@ 2017-06-13  6:29           ` Jeff King
  2017-06-13 14:47             ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-13  6:29 UTC (permalink / raw)
  To: Brandon Williams; +Cc: Jonathan Nieder, git, gitster

On Mon, Jun 12, 2017 at 10:52:43PM -0700, Brandon Williams wrote:

> > >> curious: Why get_git_common_dir() instead of get_git_dir()?
> > >
> > > Needs to be commondir since the config is stored in the common git
> > > directory and not a per worktree git directory.
> > 
> > *puzzled* Why wasn't this needed before, then?  The rest of the patch
> > should result in no functional change, but this part seems different.
> 
> there is no functional change, this is what always happened.
> git_path("config") will replace gitdir with commondir under the hood.

Of the two callsites you removed, one is git_pathdup(), and the other
is get_git_dir(). So they weren't matched, though I suspect the one in
include_by_gitdir probably ought to have been commondir?

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  6:16           ` Brandon Williams
@ 2017-06-13  6:45             ` Jeff King
  2017-06-13  7:08             ` Jeff King
  1 sibling, 0 replies; 57+ messages in thread
From: Jeff King @ 2017-06-13  6:45 UTC (permalink / raw)
  To: Brandon Williams; +Cc: Jonathan Nieder, git, gitster

On Mon, Jun 12, 2017 at 11:16:27PM -0700, Brandon Williams wrote:

> > If the parameter is now required, then it might make sense for it to
> > become an actual function parameter instead of being stuffed into the
> > config_options struct. That would give you your breaking change, plus
> > make it more obvious to the reader that it is not optional.
> > 
> > The downside is that has to get shuttled around manually through the
> > callstack. Most of the damage is in builtin/config.c, where we call
> > git_config_with_options() a lot.
> > 
> > include_by_gitdir is also a bit annoying, as we pass around the
> > config_options struct through our void-pointer callbacks. But we can
> > solve that by sticking the git_dir into the include_data struct (whose
> > exact purpose is to carry the information we need to handle includes).
> > 
> > The patch below (on top of Brandon's series does that).
> 
> I really don't understand why this has to be so difficult and why a
> 'breaking change' is even needed.  Duy just added the 'git_dir' field to
> the config_options struct in April of this year (2185fde56 config:
> handle conditional include when $GIT_DIR is not set up) and now we want
> to strip it out again?  That's not even two months. Seems very counter
> productive and makes the api more unwieldy.

I could go either way on it. But note that you're not just changing the
existing opt->git_dir behavior.

If I call git_config_with_options() without having set opt->git_dir, the
call will now quietly ignore repo config. But even before opt->git_dir
existed, calling that function would always have read from repo config
(when we're in one, of course). So if there's a patch in flight that
adds a call to git_config_with_options(), it's now very subtly broken.

The reason I say "I could go either way" is that we can make a guess as
to whether there are any topics in flight that add such a call.

There aren't any in pu right now. That's not the whole world, of course;
people may have topics they haven't yet published. Or they may have long
running forks. Git for Windows is one, and I maintain one that GitHub
uses internally. But GfW is public and doesn't have any new calls (and
nor does my fork).  In general, it's kind of an unlikely call for a fork
or a new branch to add.

So at some point I think we say "good enough, it's not worth the hassle"
and this may be such a case.

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  6:16           ` Brandon Williams
  2017-06-13  6:45             ` Jeff King
@ 2017-06-13  7:08             ` Jeff King
  2017-06-13 14:43               ` Brandon Williams
  1 sibling, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-13  7:08 UTC (permalink / raw)
  To: Brandon Williams; +Cc: Jonathan Nieder, git, gitster

On Mon, Jun 12, 2017 at 11:16:27PM -0700, Brandon Williams wrote:

> > > *puzzled* Why wasn't this needed before, then?  The rest of the patch
> > > should result in no functional change, but this part seems different.
> > 
> > Now I'm puzzled, too. The original that got filled in lazily by the
> > config functions was always get_git_dir(). I can buy the argument that
> > this was a bug (I'm not familiar enough with worktree to say one way or
> > the other), but if it's a fix it should definitely go into another
> > patch.
> 
> Well actually... in do_git_config_sequence 'git_path("config")' is
> called which will convert gitdir to commondir under the hood.  you can't
> use vanilla gitdir because the config isn't stored in a worktree's
> gitdir but rather in the commondir as the config is shared by all
> worktrees.

Sorry, I missed the fact that there were two sites changed on the first
read.

> So maybe we actually need to add a field to the 'config_options' struct
> of 'commondir' such that the commondir can be used to load the actual
> config file and 'gitdir' can be used to handle the 'IncludeIf' stuff.

On reflection, I suspect that probably is the case. If you have a
workdir in ~/foo, you probably want to match IncludeIf against that
instead of wherever the common dir happens to be.

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  7:08             ` Jeff King
@ 2017-06-13 14:43               ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 14:43 UTC (permalink / raw)
  To: Jeff King; +Cc: Jonathan Nieder, git, gitster

On 06/13, Jeff King wrote:
> On Mon, Jun 12, 2017 at 11:16:27PM -0700, Brandon Williams wrote:
> 
> > > > *puzzled* Why wasn't this needed before, then?  The rest of the patch
> > > > should result in no functional change, but this part seems different.
> > > 
> > > Now I'm puzzled, too. The original that got filled in lazily by the
> > > config functions was always get_git_dir(). I can buy the argument that
> > > this was a bug (I'm not familiar enough with worktree to say one way or
> > > the other), but if it's a fix it should definitely go into another
> > > patch.
> > 
> > Well actually... in do_git_config_sequence 'git_path("config")' is
> > called which will convert gitdir to commondir under the hood.  you can't
> > use vanilla gitdir because the config isn't stored in a worktree's
> > gitdir but rather in the commondir as the config is shared by all
> > worktrees.
> 
> Sorry, I missed the fact that there were two sites changed on the first
> read.

Well I missed that fact when I first wrote these patches too :)

> 
> > So maybe we actually need to add a field to the 'config_options' struct
> > of 'commondir' such that the commondir can be used to load the actual
> > config file and 'gitdir' can be used to handle the 'IncludeIf' stuff.
> 
> On reflection, I suspect that probably is the case. If you have a
> workdir in ~/foo, you probably want to match IncludeIf against that
> instead of wherever the common dir happens to be.

K I'll look into adding that then.  I will say keeping track of
'commondir' vs 'gitdir' does get slightly confusing.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  6:29           ` Jeff King
@ 2017-06-13 14:47             ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 14:47 UTC (permalink / raw)
  To: Jeff King; +Cc: Jonathan Nieder, git, gitster

On 06/13, Jeff King wrote:
> On Mon, Jun 12, 2017 at 10:52:43PM -0700, Brandon Williams wrote:
> 
> > > >> curious: Why get_git_common_dir() instead of get_git_dir()?
> > > >
> > > > Needs to be commondir since the config is stored in the common git
> > > > directory and not a per worktree git directory.
> > > 
> > > *puzzled* Why wasn't this needed before, then?  The rest of the patch
> > > should result in no functional change, but this part seems different.
> > 
> > there is no functional change, this is what always happened.
> > git_path("config") will replace gitdir with commondir under the hood.
> 
> Of the two callsites you removed, one is git_pathdup(), and the other
> is get_git_dir(). So they weren't matched, though I suspect the one in
> include_by_gitdir probably ought to have been commondir?

Good point, I hope my reply on the other part of the thread answers
this.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH 4/4] config: don't implicitly use gitdir
  2017-06-13  2:59         ` Jeff King
  2017-06-13  6:16           ` Brandon Williams
@ 2017-06-13 17:06           ` Jonathan Nieder
  1 sibling, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 17:06 UTC (permalink / raw)
  To: Jeff King; +Cc: Brandon Williams, git, gitster

Jeff King wrote:
> On Mon, Jun 12, 2017 at 06:38:17PM -0700, Jonathan Nieder wrote:
>> Brandon Williams wrote:
>>> On 06/12, Jonathan Nieder wrote:

>>>> Alternatively, could this patch rename git_config_with_options?  That
>>>> way any other patch in flight that calls git_config_with_options would
>>>> conflict with this patch, giving us an opportunity to make sure it
>>>> also sets git_dir.  As another nice side benefit it would make it easy
>>>> for someone reading the patch to verify it didn't miss any callers.
>> [...]
>>> And I don't know if I agree with renaming a function just to rename it.
>>
>> I forgot to say: another way to accomplish the same thing can be to
>> reorder the function's arguments.  The relevant thing is to make code
>> that calls the function without being aware of the new requirements
>> fail to compile.
>
> If the parameter is now required, then it might make sense for it to
> become an actual function parameter instead of being stuffed into the
> config_options struct. That would give you your breaking change, plus
> make it more obvious to the reader that it is not optional.

I like it.  I also like that in your proposed patch the no longer
necessary local git_dir goes away.

What's the next step?  The discussion of get_git_common_dir() reveals
that switching from git_path() to mkpathdup() loses the
adjust_git_path() step and everything becomes complicated.  So perhaps
adding opts.git_common_dir and using that instead of git_path should
happen as a preliminary patch, making this patch afterward a more
straightforward refactoring.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* [PATCH v2 0/6] config.h
  2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
                   ` (5 preceding siblings ...)
  2017-06-13  1:07 ` Jonathan Nieder
@ 2017-06-13 21:03 ` Brandon Williams
  2017-06-13 21:03   ` [PATCH v2 1/6] config: create config.h Brandon Williams
                     ` (6 more replies)
  6 siblings, 7 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Changes in v2:
 * Fix a small nit in builtin/config.c that Jonathan pointed out.
 * Added two patches which ensure that the repository wide config is properly
   read by providing 'commondir' as a field in the 'config_options' struct.

Brandon Williams (6):
  config: create config.h
  config: remove git_config_iter
  config: don't include config.h by default
  config: don't implicitly use gitdir
  setup: teach discover_git_directory to respect the commondir
  config: respect commondir

--- interdiff with 'origin/bw/config-h'

diff --git a/builtin/config.c b/builtin/config.c
index 90f49a6ee..8b6e227c5 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -539,8 +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 (have_git_dir())
-		config_options.git_dir = get_git_common_dir();
+	if (!nongit) {
+		config_options.commondir = get_git_common_dir();
+		config_options.git_dir = get_git_dir();
+	}
 
 	if (end_null) {
 		term = '\0';
diff --git a/cache.h b/cache.h
index fd45b8c55..a4176436d 100644
--- a/cache.h
+++ b/cache.h
@@ -530,7 +530,8 @@ extern void setup_work_tree(void);
  * appended to gitdir. The return value is either NULL if no repository was
  * found, or pointing to the path inside gitdir's buffer.
  */
-extern const char *discover_git_directory(struct strbuf *gitdir);
+extern const char *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);
diff --git a/config.c b/config.c
index 4e2842689..81151fb54 100644
--- a/config.c
+++ b/config.c
@@ -1544,8 +1544,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);
+	if (opts->commondir)
+		repo_config = mkpathdup("%s/config", opts->commondir);
 	else
 		repo_config = NULL;
 
@@ -1609,8 +1609,11 @@ static void git_config_raw(config_fn_t fn, void *data)
 	struct config_options opts = {0};
 
 	opts.respect_includes = 1;
-	if (have_git_dir())
-		opts.git_dir = get_git_common_dir();
+	if (have_git_dir()) {
+		opts.commondir = get_git_common_dir();
+		opts.git_dir = get_git_dir();
+	}
+
 	if (git_config_with_options(fn, data, NULL, &opts) < 0)
 		/*
 		 * git_config_with_options() normally returns only
@@ -1652,11 +1655,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
@@ -1666,12 +1671,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);
 
-	strbuf_release(&buf);
+	strbuf_release(&commondir);
+	strbuf_release(&gitdir);
 }
 
 static void git_config_check_init(void);
diff --git a/config.h b/config.h
index c70599bd5..63b92784c 100644
--- a/config.h
+++ b/config.h
@@ -30,6 +30,7 @@ enum config_origin_type {
 
 struct config_options {
 	unsigned int respect_includes : 1;
+	const char *commondir;
 	const char *git_dir;
 };
 
diff --git a/setup.c b/setup.c
index e99a82cbe..7bbb8736f 100644
--- a/setup.c
+++ b/setup.c
@@ -946,10 +946,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
 	}
 }
 
-const char *discover_git_directory(struct strbuf *gitdir)
+const char *discover_git_directory(struct strbuf *commondir,
+				   struct strbuf *gitdir)
 {
 	struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
 	size_t gitdir_offset = gitdir->len, cwd_len;
+	size_t commondir_offset = commondir->len;
 	struct repository_format candidate;
 
 	if (strbuf_getcwd(&dir))
@@ -974,8 +976,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
 	}
 
+	get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
 	strbuf_reset(&dir);
-	strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+	strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
 	read_repository_format(&candidate, dir.buf);
 	strbuf_release(&dir);
 
@@ -983,6 +987,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		warning("ignoring git dir '%s': %s",
 			gitdir->buf + gitdir_offset, err.buf);
 		strbuf_release(&err);
+		strbuf_setlen(commondir, commondir_offset);
 		return NULL;
 	}

-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 1/6] config: create config.h
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-13 21:13     ` Jonathan Nieder
  2017-06-13 21:03   ` [PATCH v2 2/6] config: remove git_config_iter Brandon Williams
                     ` (5 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Move all config related declarations from cache.h to a new config.h
header file.  This makes cache.h smaller and allows for the opportunity
in a following patch to only include config.h when needed.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h  | 190 +------------------------------------------------------------
 config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+), 189 deletions(-)
 create mode 100644 config.h

diff --git a/cache.h b/cache.h
index 4d92aae0e..ed56f8818 100644
--- a/cache.h
+++ b/cache.h
@@ -11,6 +11,7 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
+#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
@@ -1872,188 +1873,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.
@@ -2061,16 +1883,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);
 
diff --git a/config.h b/config.h
new file mode 100644
index 000000000..f7f8b66c5
--- /dev/null
+++ b/config.h
@@ -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 *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 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);
+
+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 */
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 2/6] config: remove git_config_iter
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
  2017-06-13 21:03   ` [PATCH v2 1/6] config: create config.h Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-13 21:14     ` Jonathan Nieder
  2017-06-13 21:03   ` [PATCH v2 3/6] config: don't include config.h by default Brandon Williams
                     ` (4 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Since there is no implementation of the function 'git_config_iter' lets
stop exporting it and remove the prototype from config.h.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 config.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.h b/config.h
index f7f8b66c5..c70599bd5 100644
--- a/config.h
+++ b/config.h
@@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, co
 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);
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 3/6] config: don't include config.h by default
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
  2017-06-13 21:03   ` [PATCH v2 1/6] config: create config.h Brandon Williams
  2017-06-13 21:03   ` [PATCH v2 2/6] config: remove git_config_iter Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-13 21:58     ` Jonathan Nieder
  2017-06-13 21:03   ` [PATCH v2 4/6] config: don't implicitly use gitdir Brandon Williams
                     ` (3 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Stop including config.h by default in cache.h.  Instead only include
config.h in those files which require use of the config system.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 advice.c                         | 1 +
 alias.c                          | 1 +
 apply.c                          | 1 +
 archive-tar.c                    | 1 +
 archive-zip.c                    | 1 +
 archive.c                        | 1 +
 attr.c                           | 1 +
 bisect.c                         | 1 +
 branch.c                         | 1 +
 builtin/add.c                    | 1 +
 builtin/am.c                     | 1 +
 builtin/blame.c                  | 2 ++
 builtin/branch.c                 | 1 +
 builtin/cat-file.c               | 1 +
 builtin/check-attr.c             | 1 +
 builtin/check-ignore.c           | 1 +
 builtin/check-mailmap.c          | 1 +
 builtin/checkout-index.c         | 1 +
 builtin/checkout.c               | 1 +
 builtin/clean.c                  | 1 +
 builtin/clone.c                  | 1 +
 builtin/column.c                 | 1 +
 builtin/commit-tree.c            | 1 +
 builtin/commit.c                 | 1 +
 builtin/config.c                 | 1 +
 builtin/count-objects.c          | 1 +
 builtin/describe.c               | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/diff-tree.c              | 1 +
 builtin/diff.c                   | 1 +
 builtin/difftool.c               | 1 +
 builtin/fast-export.c            | 1 +
 builtin/fetch.c                  | 1 +
 builtin/fmt-merge-msg.c          | 1 +
 builtin/for-each-ref.c           | 1 +
 builtin/fsck.c                   | 1 +
 builtin/gc.c                     | 1 +
 builtin/grep.c                   | 1 +
 builtin/hash-object.c            | 1 +
 builtin/help.c                   | 1 +
 builtin/index-pack.c             | 1 +
 builtin/init-db.c                | 1 +
 builtin/log.c                    | 1 +
 builtin/ls-files.c               | 1 +
 builtin/ls-tree.c                | 1 +
 builtin/merge-base.c             | 1 +
 builtin/merge-file.c             | 1 +
 builtin/merge.c                  | 1 +
 builtin/mv.c                     | 1 +
 builtin/name-rev.c               | 1 +
 builtin/notes.c                  | 1 +
 builtin/pack-objects.c           | 1 +
 builtin/patch-id.c               | 1 +
 builtin/pull.c                   | 1 +
 builtin/push.c                   | 1 +
 builtin/read-tree.c              | 1 +
 builtin/rebase--helper.c         | 1 +
 builtin/receive-pack.c           | 1 +
 builtin/reflog.c                 | 1 +
 builtin/remote.c                 | 1 +
 builtin/repack.c                 | 1 +
 builtin/replace.c                | 1 +
 builtin/rerere.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-list.c               | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/rm.c                     | 1 +
 builtin/send-pack.c              | 1 +
 builtin/shortlog.c               | 1 +
 builtin/show-branch.c            | 1 +
 builtin/stripspace.c             | 1 +
 builtin/submodule--helper.c      | 1 +
 builtin/symbolic-ref.c           | 1 +
 builtin/tag.c                    | 1 +
 builtin/unpack-file.c            | 1 +
 builtin/unpack-objects.c         | 1 +
 builtin/update-index.c           | 1 +
 builtin/update-ref.c             | 1 +
 builtin/update-server-info.c     | 1 +
 builtin/var.c                    | 1 +
 builtin/verify-commit.c          | 1 +
 builtin/verify-pack.c            | 1 +
 builtin/verify-tag.c             | 1 +
 builtin/worktree.c               | 1 +
 builtin/write-tree.c             | 1 +
 cache.h                          | 1 -
 color.c                          | 1 +
 column.c                         | 1 +
 config.c                         | 1 +
 connect.c                        | 1 +
 convert.c                        | 1 +
 credential-cache--daemon.c       | 1 +
 credential.c                     | 1 +
 daemon.c                         | 1 +
 diff.c                           | 1 +
 dir.c                            | 1 +
 environment.c                    | 1 +
 fast-import.c                    | 1 +
 fetch-pack.c                     | 1 +
 git.c                            | 1 +
 gpg-interface.c                  | 1 +
 graph.c                          | 1 +
 grep.c                           | 1 +
 help.c                           | 1 +
 http-backend.c                   | 1 +
 http-fetch.c                     | 1 +
 http.c                           | 1 +
 ident.c                          | 1 +
 imap-send.c                      | 1 +
 ll-merge.c                       | 1 +
 log-tree.c                       | 1 +
 mailinfo.c                       | 1 +
 merge-recursive.c                | 1 +
 notes-utils.c                    | 1 +
 notes.c                          | 1 +
 pager.c                          | 1 +
 parse-options.c                  | 1 +
 pathspec.c                       | 1 +
 pretty.c                         | 1 +
 prompt.c                         | 1 +
 read-cache.c                     | 1 +
 refs.c                           | 1 +
 refs/files-backend.c             | 1 +
 remote-curl.c                    | 1 +
 remote.c                         | 1 +
 rerere.c                         | 1 +
 send-pack.c                      | 1 +
 sequencer.c                      | 1 +
 setup.c                          | 1 +
 sha1_file.c                      | 1 +
 sha1_name.c                      | 1 +
 submodule-config.c               | 1 +
 submodule.c                      | 1 +
 t/helper/test-config.c           | 1 +
 t/helper/test-submodule-config.c | 1 +
 trailer.c                        | 1 +
 transport.c                      | 1 +
 unpack-trees.c                   | 1 +
 upload-pack.c                    | 1 +
 userdiff.c                       | 1 +
 versioncmp.c                     | 1 +
 wrapper.c                        | 1 +
 xdiff-interface.c                | 1 +
 145 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/advice.c b/advice.c
index b84ae4960..3fa04fca0 100644
--- a/advice.c
+++ b/advice.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
diff --git a/alias.c b/alias.c
index 3b90397a9..052f34136 100644
--- a/alias.c
+++ b/alias.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 char *alias_lookup(const char *alias)
 {
diff --git a/apply.c b/apply.c
index c49cef063..87db9618d 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 073e60ebd..c6ed96ee7 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -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"
diff --git a/archive-zip.c b/archive-zip.c
index 27563e9e2..e8913e5a2 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2006 Rene Scharfe
  */
 #include "cache.h"
+#include "config.h"
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
diff --git a/archive.c b/archive.c
index b15a922da..60b3035a7 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 7e2134471..9f8b02936 100644
--- a/attr.c
+++ b/attr.c
@@ -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"
diff --git a/bisect.c b/bisect.c
index c952df692..d8587d11c 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/branch.c b/branch.c
index 985316eb7..a8a548ccf 100644
--- a/branch.c
+++ b/branch.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "config.h"
 #include "branch.h"
 #include "refs.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index d9a2491e4..f2415e99f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5ee146bfb..242d70361 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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"
diff --git a/builtin/blame.c b/builtin/blame.c
index d7a2df3b4..381927920 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,6 +6,8 @@
  */
 
 #include "cache.h"
+#include "config.h"
+#include "refs.h"
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 83fcda43d..c958e9325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4bffd7a2d..7efbc4019 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 4d01ca0c8..91444dc04 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index c7b8c0889..3e280b9c7 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cf0f54f6b..cdce144f3 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 07631d0c9..39c8be05d 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -5,6 +5,7 @@
  *
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a6b2af39d..45fab5a4d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 142bf668c..ed954134d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 743f16ae2..4922a5496 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
diff --git a/builtin/column.c b/builtin/column.c
index 33314b4d7..0c3223d64 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index f39c2b273..a4a923d7c 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index da1ba4c86..805da4915 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
diff --git a/builtin/config.c b/builtin/config.c
index 7f6c25d4d..753c40a5c 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "parse-options.h"
 #include "urlmatch.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index acb05940f..1d82e61f2 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 893c8789f..70eb14460 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index a572da9d5..965f2fb76 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index f084826a2..ad9971f64 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e40111204..36c220f93 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "log-tree.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 0c8f86e40..0d59e99ef 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index b9a892f26..9199227f6 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -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"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 24e29ad7e..0dfd980dd 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "object.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 47708451b..65317bd6c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2,6 +2,7 @@
  * "git fetch"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 70137b0b7..10cbb4341 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index eca365bf8..52be99cba 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index cb2ba6cd1..90593491e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index f484eda43..bd91f136f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7df9c253e..7f720ca6c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -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"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index bbeaf20bc..d04baf999 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -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"
diff --git a/builtin/help.c b/builtin/help.c
index 49f7a07f8..334a8494a 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -2,6 +2,7 @@
  * Builtin help command
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 04b9dcaf0..edc1a91d8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "delta.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 8a6acb0ec..47823f9aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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"
diff --git a/builtin/log.c b/builtin/log.c
index e89ec941c..01d7213c1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
  *		 2006 Junio Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc31..c4357dc30 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -6,6 +6,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ee7b293b1..ef965408e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 0c36a70ad..6dbd167d3 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 47dde7c39..b08803e61 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -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"
diff --git a/builtin/merge.c b/builtin/merge.c
index a4a098f40..2512370c1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "builtin.h"
 #include "lockfile.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 61d20037a..dcf6736b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Johannes Schindelin
  */
 #include "builtin.h"
+#include "config.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7fc7e66e8..e21715f1d 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 7196bff0e..8d14f434a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "notes.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f672225de..d5e96ed2d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 81552e02e..970d0d30b 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -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)
 {
diff --git a/builtin/pull.c b/builtin/pull.c
index da8b60fc8..0c77381da 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -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"
diff --git a/builtin/push.c b/builtin/push.c
index a597759d8..76aa713d2 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -2,6 +2,7 @@
  * "git push"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "run-command.h"
 #include "builtin.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 78d319365..6eb2a0e57 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "tree.h"
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index ca1ebb2fa..c82b4dce6 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "sequencer.h"
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b1706a573..71c0c768d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 920c16dac..44cdc2dbd 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe26..6273c0c23 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 38ba4ef82..f17a68a17 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index c921bc976..80a15cf35 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -9,6 +9,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1bf72423b..ffb66e290 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 430602d10..d0b604103 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 718c6059c..f8e2b7bf5 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index efdc14473..c78b7b33d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 345d9586a..16028b9ea 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 7c323d012..824d1de9e 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -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"
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index b8e2e74fe..633e0c3cd 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7cff1839f..43c4799ea 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "string-list.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 4a6cc6f49..e4cf1b5bb 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "builtin.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e62a008c..bdf032886 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8cc648d85..4dcbfb952 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 70addef15..df75cb9d4 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "cache.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 1f74a56db..01154ea8d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "tag.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6fc6bcdf7..73f133419 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 
 static char *create_temp_file(unsigned char *sha1)
 {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 8bc999776..193f8b9d5 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ebfc09faa..0a4c23648 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -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"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0b2ecf41a..40ccfc193 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6c8cc3edc..873070e51 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53a2..6c6f46b4a 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,6 +4,7 @@
  * Copyright (C) Eric Biederman, 2005
  */
 #include "builtin.h"
+#include "config.h"
 
 static const char var_usage[] = "git var (-l | <variable>)";
 
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05b734e6d..ba38ac9b1 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -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"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c94e15693..c2a1a5c50 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "parse-options.h"
 
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5199553d9..f9a5f7535 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -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"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 793306ea5..0c5476ee9 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "dir.h"
 #include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 084c0df78..bd0a78aa3 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
diff --git a/cache.h b/cache.h
index ed56f8818..fd45b8c55 100644
--- a/cache.h
+++ b/cache.h
@@ -11,7 +11,6 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
-#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
diff --git a/color.c b/color.c
index dee61557e..31b6207a0 100644
--- a/color.c
+++ b/color.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/column.c b/column.c
index d55ead18e..ff7bdab1a 100644
--- a/column.c
+++ b/column.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "column.h"
 #include "string-list.h"
 #include "parse-options.h"
diff --git a/config.c b/config.c
index 146cb3452..2390f98e3 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
diff --git a/connect.c b/connect.c
index c72b1d115..e78d3f43d 100644
--- a/connect.c
+++ b/connect.c
@@ -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"
diff --git a/convert.c b/convert.c
index f1e168bc3..5f4a4b1f5 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index f3814cc47..0d5c62509 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "credential.h"
 #include "unix-socket.h"
diff --git a/credential.c b/credential.c
index aa996669f..67a523353 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/daemon.c b/daemon.c
index ac7181a48..30747075f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index 5275c4b78..3458ec640 100644
--- a/diff.c
+++ b/diff.c
@@ -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"
diff --git a/dir.c b/dir.c
index 9efcf1eab..d4e4258ea 100644
--- a/dir.c
+++ b/dir.c
@@ -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"
diff --git a/environment.c b/environment.c
index aa478e71d..d40b21fb7 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
 #include "commit.h"
diff --git a/fast-import.c b/fast-import.c
index e69d21968..2881d4898 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -154,6 +154,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "blob.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index cd86865be..fbbc99c88 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/git.c b/git.c
index 8ff44f081..594436e43 100644
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "help.h"
 #include "run-command.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index e44cc27da..8ab32df45 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "gpg-interface.h"
diff --git a/graph.c b/graph.c
index 8b9049dd2..e7e20650d 100644
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "graph.h"
diff --git a/grep.c b/grep.c
index d03d424e5..62c7cf970 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "grep.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/help.c b/help.c
index db7f3d79a..5d44f811a 100644
--- a/help.c
+++ b/help.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/http-backend.c b/http-backend.c
index ba5ff1aa2..519025d2c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "object.h"
diff --git a/http-fetch.c b/http-fetch.c
index 3b556d661..8af380050 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "http.h"
 #include "walker.h"
diff --git a/http.c b/http.c
index d2e11ec6f..013bb0cc6 100644
--- a/http.c
+++ b/http.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "http.h"
+#include "config.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/ident.c b/ident.c
index bea871c8e..d41fc9119 100644
--- a/ident.c
+++ b/ident.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2005 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
diff --git a/imap-send.c b/imap-send.c
index 857591660..59e9b12d2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,6 +23,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/ll-merge.c b/ll-merge.c
index ac0d4a5d7..24ff94e1d 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
diff --git a/log-tree.c b/log-tree.c
index a4ec11c2b..7e1dfd749 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/mailinfo.c b/mailinfo.c
index f92cb9f72..f59162453 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index ae5238d82..c2494f34f 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -4,6 +4,7 @@
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
 #include "cache.h"
+#include "config.h"
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/notes-utils.c b/notes-utils.c
index 031503d7b..3f6cbdc47 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index 542563b28..dbcfef4d7 100644
--- a/notes.c
+++ b/notes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "notes.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/pager.c b/pager.c
index c113d898a..4dd9e1b26 100644
--- a/pager.c
+++ b/pager.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
 
diff --git a/parse-options.c b/parse-options.c
index e5ad34a2c..0dd9fc6a0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "utf8.h"
diff --git a/pathspec.c b/pathspec.c
index 828405021..ecc5331c2 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "attr.h"
diff --git a/pretty.c b/pretty.c
index 09701bd2f..9c9f81b5b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/prompt.c b/prompt.c
index 75406390c..6d5885d00 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
diff --git a/read-cache.c b/read-cache.c
index bc156a133..c8c766dab 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/refs.c b/refs.c
index f0685c925..84112c88e 100644
--- a/refs.c
+++ b/refs.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "lockfile.h"
 #include "iterator.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d8b3f7314..621a4086c 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,5 @@
 #include "../cache.h"
+#include "../config.h"
 #include "../refs.h"
 #include "refs-internal.h"
 #include "ref-cache.h"
diff --git a/remote-curl.c b/remote-curl.c
index ece45993d..0053b0954 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "strbuf.h"
 #include "walker.h"
diff --git a/remote.c b/remote.c
index 3649d60cd..68d20f650 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/rerere.c b/rerere.c
index 3bd55caf3..344d6aa81 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
diff --git a/send-pack.c b/send-pack.c
index 78bb34ebe..ed3cee321 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/sequencer.c b/sequencer.c
index 924fb1d0c..86b0640d2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index e3f7699a9..e99a82cbe 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "string-list.h"
 
diff --git a/sha1_file.c b/sha1_file.c
index 59a4ed2ed..44561e0b9 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "lockfile.h"
 #include "delta.h"
diff --git a/sha1_name.c b/sha1_name.c
index e9ffe685d..2875771ff 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/submodule-config.c b/submodule-config.c
index 4f58491dd..d8f8d5ea3 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
diff --git a/submodule.c b/submodule.c
index bf5a93d16..95328de61 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "dir.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 8e3ed6a76..1a7b8bd3d 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 2f144d539..c6c57bba0 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/trailer.c b/trailer.c
index 11f0b9fb4..751b56c00 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
diff --git a/transport.c b/transport.c
index 9bfcf870f..b9995306f 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "transport.h"
 #include "run-command.h"
 #include "pkt-line.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index d38c37e38..dd535bc84 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 5330c02c1..7efff2fbf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
diff --git a/userdiff.c b/userdiff.c
index 8b732e40b..2c1502f71 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "userdiff.h"
 #include "attr.h"
 
diff --git a/versioncmp.c b/versioncmp.c
index 9f81dc106..069ee94a4 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/wrapper.c b/wrapper.c
index d83741770..487a9f753 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "config.h"
 
 static void do_nothing(size_t size)
 {
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 060038c2d..5ac07d734 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
                     ` (2 preceding siblings ...)
  2017-06-13 21:03   ` [PATCH v2 3/6] config: don't include config.h by default Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-13 21:08     ` Jonathan Nieder
  2017-06-13 21:03   ` [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
not set up) added a 'git_dir' field to the config_options struct.  Let's
use this option field explicitly all the time instead of occasionally
falling back to calling 'git_pathdup("config")' to get the path to the
local repository configuration.  This allows 'do_git_config_sequence()'
to not implicitly rely on global repository state.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/config.c | 2 ++
 config.c         | 6 ++----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 753c40a5c..f06a8dff2 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -539,6 +539,8 @@ 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.git_dir = get_git_common_dir();
 
 	if (end_null) {
 		term = '\0';
diff --git a/config.c b/config.c
index 2390f98e3..4e2842689 100644
--- a/config.c
+++ b/config.c
@@ -219,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;
 
@@ -1548,8 +1546,6 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 	if (opts->git_dir)
 		repo_config = mkpathdup("%s/config", opts->git_dir);
-	else if (have_git_dir())
-		repo_config = git_pathdup("config");
 	else
 		repo_config = NULL;
 
@@ -1613,6 +1609,8 @@ static void git_config_raw(config_fn_t fn, void *data)
 	struct config_options opts = {0};
 
 	opts.respect_includes = 1;
+	if (have_git_dir())
+		opts.git_dir = get_git_common_dir();
 	if (git_config_with_options(fn, data, NULL, &opts) < 0)
 		/*
 		 * git_config_with_options() normally returns only
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
                     ` (3 preceding siblings ...)
  2017-06-13 21:03   ` [PATCH v2 4/6] config: don't implicitly use gitdir Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-14  6:15     ` Jeff King
  2017-06-13 21:03   ` [PATCH v2 6/6] config: respect commondir Brandon Williams
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
  6 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Currently 'discover_git_directory' only looks at the gitdir to determine
if a git directory was discovered.  This causes a problem in the event
that the gitdir which was discovered was in fact a per-worktree git
directory and not the common git directory.  This is because the
repository config, which is checked to verify the repository's format,
is stored in the commondir and not in the per-worktree gitdir.  Correct
this behavior by checking the config stored in the commondir.

It will also be of use for callers to have access to the commondir, so
lets also return that upon successfully discovering a git directory.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h  |  3 ++-
 config.c | 10 ++++++----
 setup.c  |  9 +++++++--
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/cache.h b/cache.h
index fd45b8c55..a4176436d 100644
--- a/cache.h
+++ b/cache.h
@@ -530,7 +530,8 @@ extern void setup_work_tree(void);
  * appended to gitdir. The return value is either NULL if no repository was
  * found, or pointing to the path inside gitdir's buffer.
  */
-extern const char *discover_git_directory(struct strbuf *gitdir);
+extern const char *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);
diff --git a/config.c b/config.c
index 4e2842689..9aa9b9715 100644
--- a/config.c
+++ b/config.c
@@ -1652,7 +1652,8 @@ 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;
 
@@ -1666,12 +1667,13 @@ 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.git_dir = gitdir.buf;
 
 	git_config_with_options(cb, data, NULL, &opts);
 
-	strbuf_release(&buf);
+	strbuf_release(&commondir);
+	strbuf_release(&gitdir);
 }
 
 static void git_config_check_init(void);
diff --git a/setup.c b/setup.c
index e99a82cbe..7bbb8736f 100644
--- a/setup.c
+++ b/setup.c
@@ -946,10 +946,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
 	}
 }
 
-const char *discover_git_directory(struct strbuf *gitdir)
+const char *discover_git_directory(struct strbuf *commondir,
+				   struct strbuf *gitdir)
 {
 	struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
 	size_t gitdir_offset = gitdir->len, cwd_len;
+	size_t commondir_offset = commondir->len;
 	struct repository_format candidate;
 
 	if (strbuf_getcwd(&dir))
@@ -974,8 +976,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
 	}
 
+	get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
 	strbuf_reset(&dir);
-	strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+	strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
 	read_repository_format(&candidate, dir.buf);
 	strbuf_release(&dir);
 
@@ -983,6 +987,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		warning("ignoring git dir '%s': %s",
 			gitdir->buf + gitdir_offset, err.buf);
 		strbuf_release(&err);
+		strbuf_setlen(commondir, commondir_offset);
 		return NULL;
 	}
 
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 6/6] config: respect commondir
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
                     ` (4 preceding siblings ...)
  2017-06-13 21:03   ` [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
@ 2017-06-13 21:03   ` Brandon Williams
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:03 UTC (permalink / raw)
  To: git; +Cc: gitster, Johannes.Schindelin, peff, jrnieder, Brandon Williams

Worktrees present an interesting problem when it comes to the config.
Historically we could assume that the per-repository config lives at
'gitdir/config', but since worktrees were introduced this isn't the case
anymore.  There is currently no way to specify per-worktree
configuration, and as such the repository config is shared with all
worktrees and is located at 'commondir/config'.

Many users of the config machinery correctly set
'config_options.git_dir' with the repository's commondir, allowing the
config to be properly loaded when operating in a worktree.  But other's,
like 'read_early_config()', set 'config_options.git_dir' with the
repository's gitdir which can be incorrect when using worktrees.

To fix this issue, and to make things less ambiguous, lets add a
'commondir' field to the 'config_options' struct and have all callers
properly set both the 'git_dir' and 'commondir' fields so that the
config machinery is able to properly find the repository's config.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/config.c |  6 ++++--
 config.c         | 18 ++++++++++++------
 config.h         |  1 +
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index f06a8dff2..8b6e227c5 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -539,8 +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.git_dir = get_git_common_dir();
+	if (!nongit) {
+		config_options.commondir = get_git_common_dir();
+		config_options.git_dir = get_git_dir();
+	}
 
 	if (end_null) {
 		term = '\0';
diff --git a/config.c b/config.c
index 9aa9b9715..81151fb54 100644
--- a/config.c
+++ b/config.c
@@ -1544,8 +1544,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);
+	if (opts->commondir)
+		repo_config = mkpathdup("%s/config", opts->commondir);
 	else
 		repo_config = NULL;
 
@@ -1609,8 +1609,11 @@ static void git_config_raw(config_fn_t fn, void *data)
 	struct config_options opts = {0};
 
 	opts.respect_includes = 1;
-	if (have_git_dir())
-		opts.git_dir = get_git_common_dir();
+	if (have_git_dir()) {
+		opts.commondir = get_git_common_dir();
+		opts.git_dir = get_git_dir();
+	}
+
 	if (git_config_with_options(fn, data, NULL, &opts) < 0)
 		/*
 		 * git_config_with_options() normally returns only
@@ -1657,7 +1660,8 @@ void read_early_config(config_fn_t cb, void *data)
 
 	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,8 +1671,10 @@ 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(&commondir, &gitdir))
+	} else if (discover_git_directory(&commondir, &gitdir)) {
+		opts.commondir = commondir.buf;
 		opts.git_dir = gitdir.buf;
+	}
 
 	git_config_with_options(cb, data, NULL, &opts);
 
diff --git a/config.h b/config.h
index c70599bd5..63b92784c 100644
--- a/config.h
+++ b/config.h
@@ -30,6 +30,7 @@ enum config_origin_type {
 
 struct config_options {
 	unsigned int respect_includes : 1;
+	const char *commondir;
 	const char *git_dir;
 };
 
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:03   ` [PATCH v2 4/6] config: don't implicitly use gitdir Brandon Williams
@ 2017-06-13 21:08     ` Jonathan Nieder
  2017-06-13 21:38       ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 21:08 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, peff

Brandon Williams wrote:

> Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
> not set up) added a 'git_dir' field to the config_options struct.  Let's
> use this option field explicitly all the time instead of occasionally
> falling back to calling 'git_pathdup("config")' to get the path to the
> local repository configuration.  This allows 'do_git_config_sequence()'
> to not implicitly rely on global repository state.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  builtin/config.c | 2 ++
>  config.c         | 6 ++----
>  2 files changed, 4 insertions(+), 4 deletions(-)

The same comments as before still apply:

- this changes API to make opts->git_dir mandatory, which is error prone
  and easily avoidable, e.g. by making git_dir an argument to
  git_config_with_options

- the commit message doesn't say anything about to git dir vs common dir
  change.  It needs to, or even better, the switch to use common dir
  instead of git dir can happen as a separate patch.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 1/6] config: create config.h
  2017-06-13 21:03   ` [PATCH v2 1/6] config: create config.h Brandon Williams
@ 2017-06-13 21:13     ` Jonathan Nieder
  0 siblings, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 21:13 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, peff

Hi,

Brandon Williams wrote:

> Move all config related declarations from cache.h to a new config.h
> header file.  This makes cache.h smaller and allows for the opportunity
> in a following patch to only include config.h when needed.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  cache.h  | 190 +------------------------------------------------------------
>  config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 195 insertions(+), 189 deletions(-)
>  create mode 100644 config.h

'git diff HEAD^:cache.h config.h' confirms that this is
straightforward code movement and didn't introduce any unintentional
changes along the way.  Thanks for writing it.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 2/6] config: remove git_config_iter
  2017-06-13 21:03   ` [PATCH v2 2/6] config: remove git_config_iter Brandon Williams
@ 2017-06-13 21:14     ` Jonathan Nieder
  0 siblings, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 21:14 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, peff

Brandon Williams wrote:

> Since there is no implementation of the function 'git_config_iter' lets
> stop exporting it and remove the prototype from config.h.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  config.h | 1 -
>  1 file changed, 1 deletion(-)

Language nit:

	s/' lets/', let's/

That is, there is a comma and an apostrophe missing.

With or without that tweak,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:08     ` Jonathan Nieder
@ 2017-06-13 21:38       ` Brandon Williams
  2017-06-13 21:51         ` Jonathan Nieder
  2017-06-14  6:25         ` Jeff King
  0 siblings, 2 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-13 21:38 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, gitster, Johannes.Schindelin, peff

On 06/13, Jonathan Nieder wrote:
> Brandon Williams wrote:
> 
> > Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
> > not set up) added a 'git_dir' field to the config_options struct.  Let's
> > use this option field explicitly all the time instead of occasionally
> > falling back to calling 'git_pathdup("config")' to get the path to the
> > local repository configuration.  This allows 'do_git_config_sequence()'
> > to not implicitly rely on global repository state.
> >
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> >  builtin/config.c | 2 ++
> >  config.c         | 6 ++----
> >  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> The same comments as before still apply:
> 
> - this changes API to make opts->git_dir mandatory, which is error prone
>   and easily avoidable, e.g. by making git_dir an argument to
>   git_config_with_options

I still don't agree with this.  I have looked at all callers and ensured
that 'git_dir' will be set when appropriate in the 'config_options'
struct.  I find the notion ridiculous that I would need to change a
function's name or arguments every time the internals of the function
are adjusted or when an options struct obtains a new field.  Plus, there
is already an aptly named parameter of type 'config_options' with which
to hold options for the config machinery.  This struct is also added to
in a later patch to include commondir so that the gitdir vs commondir
issue can be resolved.

> - the commit message doesn't say anything about to git dir vs common dir
>   change.  It needs to, or even better, the switch to use common dir
>   instead of git dir can happen as a separate patch.

There really isn't any switching in this patch.  One of the following
patches in this series addresses this problem in more detail though.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:38       ` Brandon Williams
@ 2017-06-13 21:51         ` Jonathan Nieder
  2017-06-13 21:55           ` Junio C Hamano
  2017-06-14  6:25         ` Jeff King
  1 sibling, 1 reply; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 21:51 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, peff

Brandon Williams wrote:
> On 06/13, Jonathan Nieder wrote:
>> Brandon Williams wrote:

>>> Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
>>> not set up) added a 'git_dir' field to the config_options struct.  Let's
>>> use this option field explicitly all the time instead of occasionally
>>> falling back to calling 'git_pathdup("config")' to get the path to the
>>> local repository configuration.  This allows 'do_git_config_sequence()'
>>> to not implicitly rely on global repository state.
>>>
>>> Signed-off-by: Brandon Williams <bmwill@google.com>
>>> ---
>>>  builtin/config.c | 2 ++
>>>  config.c         | 6 ++----
>>>  2 files changed, 4 insertions(+), 4 deletions(-)
>>
>> The same comments as before still apply:
>>
>> - this changes API to make opts->git_dir mandatory, which is error prone
>>   and easily avoidable, e.g. by making git_dir an argument to
>>   git_config_with_options
>
> I still don't agree with this.  I have looked at all callers and ensured
> that 'git_dir' will be set when appropriate in the 'config_options'
> struct.  I find the notion ridiculous that I would need to change a
> function's name or arguments every time the internals of the function
> are adjusted or when an options struct obtains a new field.  Plus, there
> is already an aptly named parameter of type 'config_options' with which
> to hold options for the config machinery.  This struct is also added to
> in a later patch to include commondir so that the gitdir vs commondir
> issue can be resolved.

What is the next step, then?  You can find the notion ridiculous but
it's how this project has worked in my experience (and how other
projects with similar patch-based workflows work).

I also don't really understand why it is so bad to have to care about
API compatibility when it is so simple to do --- change the function
signature or change the function name.  That's all it takes.

>> - the commit message doesn't say anything about to git dir vs common dir
>>   change.  It needs to, or even better, the switch to use common dir
>>   instead of git dir can happen as a separate patch.
>
> There really isn't any switching in this patch.  One of the following
> patches in this series addresses this problem in more detail though.

There is, because of the gitdir: behavior change.

Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:51         ` Jonathan Nieder
@ 2017-06-13 21:55           ` Junio C Hamano
  2017-06-13 22:05             ` Jonathan Nieder
  0 siblings, 1 reply; 57+ messages in thread
From: Junio C Hamano @ 2017-06-13 21:55 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Brandon Williams, Git Mailing List, Johannes Schindelin,
	Jeff King

On Tue, Jun 13, 2017 at 2:51 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>
> What is the next step, then?  You can find the notion ridiculous but
> it's how this project has worked in my experience (and how other
> projects with similar patch-based workflows work).

Does "patch-based" have much to do with this? I agree that distributed
nature of the development would bring this issue, but I tend to think that
using merge/pull based workflow would not alleviate it--am I mistaken?

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 3/6] config: don't include config.h by default
  2017-06-13 21:03   ` [PATCH v2 3/6] config: don't include config.h by default Brandon Williams
@ 2017-06-13 21:58     ` Jonathan Nieder
  0 siblings, 0 replies; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 21:58 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, peff

Brandon Williams wrote:
> Stop including config.h by default in cache.h.  Instead only include
> config.h in those files which require use of the config system.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
[...]
>  145 files changed, 145 insertions(+), 1 deletion(-)

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:55           ` Junio C Hamano
@ 2017-06-13 22:05             ` Jonathan Nieder
  2017-06-14  4:40               ` Jacob Keller
  0 siblings, 1 reply; 57+ messages in thread
From: Jonathan Nieder @ 2017-06-13 22:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Brandon Williams, Git Mailing List, Johannes Schindelin,
	Jeff King

Junio C Hamano wrote:
> On Tue, Jun 13, 2017 at 2:51 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:

>> What is the next step, then?  You can find the notion ridiculous but
>> it's how this project has worked in my experience (and how other
>> projects with similar patch-based workflows work).
>
> Does "patch-based" have much to do with this? I agree that distributed
> nature of the development would bring this issue, but I tend to think that
> using merge/pull based workflow would not alleviate it--am I mistaken?

Thanks, you're right.  Distributed is the relevant feature.

The same issue can even come up when using a centralized version
control system like Subversion or Perforce --- without attention to
API compatibility, someone's change that was thoroughly reviewed and
well tested locally in a developer's working directory can introduce
subtle breakage once they run "svn commit", causing it to merge with
the latest upstream changes.  The problem becomes more likely the more
distributed a project is since each developer becomes less aware of
the other changes that their modifications need to be compatible with.

Jonathan

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 22:05             ` Jonathan Nieder
@ 2017-06-14  4:40               ` Jacob Keller
  0 siblings, 0 replies; 57+ messages in thread
From: Jacob Keller @ 2017-06-14  4:40 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Junio C Hamano, Brandon Williams, Git Mailing List,
	Johannes Schindelin, Jeff King

On Tue, Jun 13, 2017 at 3:05 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Junio C Hamano wrote:
>> On Tue, Jun 13, 2017 at 2:51 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>
>>> What is the next step, then?  You can find the notion ridiculous but
>>> it's how this project has worked in my experience (and how other
>>> projects with similar patch-based workflows work).
>>
>> Does "patch-based" have much to do with this? I agree that distributed
>> nature of the development would bring this issue, but I tend to think that
>> using merge/pull based workflow would not alleviate it--am I mistaken?
>
> Thanks, you're right.  Distributed is the relevant feature.
>
> The same issue can even come up when using a centralized version
> control system like Subversion or Perforce --- without attention to
> API compatibility, someone's change that was thoroughly reviewed and
> well tested locally in a developer's working directory can introduce
> subtle breakage once they run "svn commit", causing it to merge with
> the latest upstream changes.  The problem becomes more likely the more
> distributed a project is since each developer becomes less aware of
> the other changes that their modifications need to be compatible with.
>
> Jonathan

Which would be why early integration (pu) and a good test suite are
for. However, it's much easier to catch if you change the name when
the function no longer behaves the same. In this case I guess you
could argue that the part that changed wasn't part of the API...
However, I think I'd lean towards "we had code depending on it, so yes
it was".

It's ok to add new functionality only obtained by new flags or
similar,  but not ok to break potentially existing callers.

Thanks,
Jake

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir
  2017-06-13 21:03   ` [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
@ 2017-06-14  6:15     ` Jeff King
  2017-06-14 17:19       ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-14  6:15 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, gitster, Johannes.Schindelin, jrnieder

On Tue, Jun 13, 2017 at 02:03:20PM -0700, Brandon Williams wrote:

> Currently 'discover_git_directory' only looks at the gitdir to determine
> if a git directory was discovered.  This causes a problem in the event
> that the gitdir which was discovered was in fact a per-worktree git
> directory and not the common git directory.  This is because the
> repository config, which is checked to verify the repository's format,
> is stored in the commondir and not in the per-worktree gitdir.  Correct
> this behavior by checking the config stored in the commondir.
> 
> It will also be of use for callers to have access to the commondir, so
> lets also return that upon successfully discovering a git directory.

This makes sense, and I agree is the correct path forward for handling
the config code's needs.

> diff --git a/cache.h b/cache.h
> index fd45b8c55..a4176436d 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -530,7 +530,8 @@ extern void setup_work_tree(void);
>   * appended to gitdir. The return value is either NULL if no repository was
>   * found, or pointing to the path inside gitdir's buffer.
>   */
> -extern const char *discover_git_directory(struct strbuf *gitdir);
> +extern const char *discover_git_directory(struct strbuf *commondir,
> +					  struct strbuf *gitdir);

Does the docstring above the function need updating? What happens when
you are not in a worktree? Are both strbufs filled out with the same
value?

That's what I'd assume (and what it looks like looking at the code), but
it's probably worth being explicit.

We also return a pointer. I think this still points into the gitdir
strbuf. Which I guess is reasonable, though probably should be
documented.

Given that the callers only ever look at whether it's non-NULL, it
probably would be better to just return a true/false value. This might
be a good time to do that, because the function signature is changing
already (so if we switch to the usual "0 is success", a newly added call
won't silently do the wrong thing).

> @@ -983,6 +987,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
>  		warning("ignoring git dir '%s': %s",
>  			gitdir->buf + gitdir_offset, err.buf);
>  		strbuf_release(&err);
> +		strbuf_setlen(commondir, commondir_offset);
>  		return NULL;
>  	}

I'd have expected these resetting setlens to be paired between gitdir
and commondir. And indeed, they should be; this is the same case that
Dscho fixed in the first patch of his series.

I kind of wonder if one of you should take ownership and do a combined
series.

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-13 21:38       ` Brandon Williams
  2017-06-13 21:51         ` Jonathan Nieder
@ 2017-06-14  6:25         ` Jeff King
  2017-06-14 17:14           ` Brandon Williams
  1 sibling, 1 reply; 57+ messages in thread
From: Jeff King @ 2017-06-14  6:25 UTC (permalink / raw)
  To: Brandon Williams; +Cc: Jonathan Nieder, git, gitster, Johannes.Schindelin

On Tue, Jun 13, 2017 at 02:38:15PM -0700, Brandon Williams wrote:

> > The same comments as before still apply:
> > 
> > - this changes API to make opts->git_dir mandatory, which is error prone
> >   and easily avoidable, e.g. by making git_dir an argument to
> >   git_config_with_options
> 
> I still don't agree with this.  I have looked at all callers and ensured
> that 'git_dir' will be set when appropriate in the 'config_options'
> struct.  I find the notion ridiculous that I would need to change a
> function's name or arguments every time the internals of the function
> are adjusted or when an options struct obtains a new field.  Plus, there
> is already an aptly named parameter of type 'config_options' with which
> to hold options for the config machinery.  This struct is also added to
> in a later patch to include commondir so that the gitdir vs commondir
> issue can be resolved.

I've already said "I'm OK either way for this case", but let me clarify
a bit.

It's not about changing a function's internals, or even the struct
obtaining a new field. The key change here is that the _interface_
changed. Callers used to be able to pass NULL for the git_dir and have
the function behave one way, and now if they do so it behaves
differently. That leads to spooky action at a distance. Code which you
didn't know about still compiles but does something subtly different.

We can catch that at the compile stage, or we can catch it at the test
stage, or we can decide it's somebody else's problem to deal with if
they wrote code that the rest of the project hasn't seen.

But it is a real thing that comes up in a big, open project. There is no
"looked at all the callers", because you can't see the whole universe of
code. I do think it's a much bigger deal in a project like the kernel,
which has hundreds of long-lasting forks. Git has only a handful, and we
don't necessarily need to bend over backwards for people whose code
hasn't been shared.

> > - the commit message doesn't say anything about to git dir vs common dir
> >   change.  It needs to, or even better, the switch to use common dir
> >   instead of git dir can happen as a separate patch.
> 
> There really isn't any switching in this patch.  One of the following
> patches in this series addresses this problem in more detail though.

I would have expected that patch to actually come earlier. That fixes
the bug there, and then this conversion patch becomes that much more
straightforward.

-Peff

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 4/6] config: don't implicitly use gitdir
  2017-06-14  6:25         ` Jeff King
@ 2017-06-14 17:14           ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 17:14 UTC (permalink / raw)
  To: Jeff King; +Cc: Jonathan Nieder, git, gitster, Johannes.Schindelin

On 06/14, Jeff King wrote:
> On Tue, Jun 13, 2017 at 02:38:15PM -0700, Brandon Williams wrote:
> 
> > > The same comments as before still apply:
> > > 
> > > - this changes API to make opts->git_dir mandatory, which is error prone
> > >   and easily avoidable, e.g. by making git_dir an argument to
> > >   git_config_with_options
> > 
> > I still don't agree with this.  I have looked at all callers and ensured
> > that 'git_dir' will be set when appropriate in the 'config_options'
> > struct.  I find the notion ridiculous that I would need to change a
> > function's name or arguments every time the internals of the function
> > are adjusted or when an options struct obtains a new field.  Plus, there
> > is already an aptly named parameter of type 'config_options' with which
> > to hold options for the config machinery.  This struct is also added to
> > in a later patch to include commondir so that the gitdir vs commondir
> > issue can be resolved.
> 
> I've already said "I'm OK either way for this case", but let me clarify
> a bit.
> 
> It's not about changing a function's internals, or even the struct
> obtaining a new field. The key change here is that the _interface_
> changed. Callers used to be able to pass NULL for the git_dir and have
> the function behave one way, and now if they do so it behaves
> differently. That leads to spooky action at a distance. Code which you
> didn't know about still compiles but does something subtly different.
> 
> We can catch that at the compile stage, or we can catch it at the test
> stage, or we can decide it's somebody else's problem to deal with if
> they wrote code that the rest of the project hasn't seen.
> 
> But it is a real thing that comes up in a big, open project. There is no
> "looked at all the callers", because you can't see the whole universe of
> code. I do think it's a much bigger deal in a project like the kernel,
> which has hundreds of long-lasting forks. Git has only a handful, and we
> don't necessarily need to bend over backwards for people whose code
> hasn't been shared.

At this point I'm done arguing, I'll rename the function and drop the
'git' prefix as that's the only sensible name I can think of.

> 
> > > - the commit message doesn't say anything about to git dir vs common dir
> > >   change.  It needs to, or even better, the switch to use common dir
> > >   instead of git dir can happen as a separate patch.
> > 
> > There really isn't any switching in this patch.  One of the following
> > patches in this series addresses this problem in more detail though.
> 
> I would have expected that patch to actually come earlier. That fixes
> the bug there, and then this conversion patch becomes that much more
> straightforward.

True, I can reorder the patches in v3 so that this change flows better.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir
  2017-06-14  6:15     ` Jeff King
@ 2017-06-14 17:19       ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 17:19 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, Johannes.Schindelin, jrnieder

On 06/14, Jeff King wrote:
> On Tue, Jun 13, 2017 at 02:03:20PM -0700, Brandon Williams wrote:
> 
> > Currently 'discover_git_directory' only looks at the gitdir to determine
> > if a git directory was discovered.  This causes a problem in the event
> > that the gitdir which was discovered was in fact a per-worktree git
> > directory and not the common git directory.  This is because the
> > repository config, which is checked to verify the repository's format,
> > is stored in the commondir and not in the per-worktree gitdir.  Correct
> > this behavior by checking the config stored in the commondir.
> > 
> > It will also be of use for callers to have access to the commondir, so
> > lets also return that upon successfully discovering a git directory.
> 
> This makes sense, and I agree is the correct path forward for handling
> the config code's needs.
> 
> > diff --git a/cache.h b/cache.h
> > index fd45b8c55..a4176436d 100644
> > --- a/cache.h
> > +++ b/cache.h
> > @@ -530,7 +530,8 @@ extern void setup_work_tree(void);
> >   * appended to gitdir. The return value is either NULL if no repository was
> >   * found, or pointing to the path inside gitdir's buffer.
> >   */
> > -extern const char *discover_git_directory(struct strbuf *gitdir);
> > +extern const char *discover_git_directory(struct strbuf *commondir,
> > +					  struct strbuf *gitdir);
> 
> Does the docstring above the function need updating? What happens when
> you are not in a worktree? Are both strbufs filled out with the same
> value?

Yes I'll update the docstring to reflect the change.  And yes if you
aren't in a worktree, then both strbufs would hold the same value.

> That's what I'd assume (and what it looks like looking at the code), but
> it's probably worth being explicit.
> 
> We also return a pointer. I think this still points into the gitdir
> strbuf. Which I guess is reasonable, though probably should be
> documented.
> 
> Given that the callers only ever look at whether it's non-NULL, it
> probably would be better to just return a true/false value. This might
> be a good time to do that, because the function signature is changing
> already (so if we switch to the usual "0 is success", a newly added call
> won't silently do the wrong thing).

I agree with that.  I can tweak the return value to return a success
code.

> 
> > @@ -983,6 +987,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
> >  		warning("ignoring git dir '%s': %s",
> >  			gitdir->buf + gitdir_offset, err.buf);
> >  		strbuf_release(&err);
> > +		strbuf_setlen(commondir, commondir_offset);
> >  		return NULL;
> >  	}
> 
> I'd have expected these resetting setlens to be paired between gitdir
> and commondir. And indeed, they should be; this is the same case that
> Dscho fixed in the first patch of his series.
> 
> I kind of wonder if one of you should take ownership and do a combined
> series.

Yeah I think that Dschos series has less review to still take place (as
he just sent out a v3) so I'll just rebase ontop of his series.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* [PATCH v3 0/6] config.h
  2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
                     ` (5 preceding siblings ...)
  2017-06-13 21:03   ` [PATCH v2 6/6] config: respect commondir Brandon Williams
@ 2017-06-14 18:07   ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 1/6] config: create config.h Brandon Williams
                       ` (6 more replies)
  6 siblings, 7 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Changes in v3:

* tweaked the discover_git_directory function's API based on Peff's feedback
* reordered the last three patches so that they flowed a bit better
* renamed 'git_config_with_options'
* rebased ontop of v4 of Dscho's alias series
  https://public-inbox.org/git/cover.1497440104.git.johannes.schindelin@gmx.de/


Brandon Williams (6):
  config: create config.h
  config: remove git_config_iter
  config: don't include config.h by default
  setup: teach discover_git_directory to respect the commondir
  config: respect commondir
  config: don't implicitly use gitdir or commondir

 advice.c                         |   1 +
 alias.c                          |   1 +
 apply.c                          |   1 +
 archive-tar.c                    |   1 +
 archive-zip.c                    |   1 +
 archive.c                        |   1 +
 attr.c                           |   1 +
 bisect.c                         |   1 +
 branch.c                         |   1 +
 builtin/add.c                    |   1 +
 builtin/am.c                     |   1 +
 builtin/blame.c                  |   2 +
 builtin/branch.c                 |   1 +
 builtin/cat-file.c               |   1 +
 builtin/check-attr.c             |   1 +
 builtin/check-ignore.c           |   1 +
 builtin/check-mailmap.c          |   1 +
 builtin/checkout-index.c         |   1 +
 builtin/checkout.c               |   1 +
 builtin/clean.c                  |   1 +
 builtin/clone.c                  |   1 +
 builtin/column.c                 |   1 +
 builtin/commit-tree.c            |   1 +
 builtin/commit.c                 |   1 +
 builtin/config.c                 |  27 +++---
 builtin/count-objects.c          |   1 +
 builtin/describe.c               |   1 +
 builtin/diff-files.c             |   1 +
 builtin/diff-index.c             |   1 +
 builtin/diff-tree.c              |   1 +
 builtin/diff.c                   |   1 +
 builtin/difftool.c               |   1 +
 builtin/fast-export.c            |   1 +
 builtin/fetch.c                  |   1 +
 builtin/fmt-merge-msg.c          |   1 +
 builtin/for-each-ref.c           |   1 +
 builtin/fsck.c                   |   1 +
 builtin/gc.c                     |   1 +
 builtin/grep.c                   |   1 +
 builtin/hash-object.c            |   1 +
 builtin/help.c                   |   1 +
 builtin/index-pack.c             |   1 +
 builtin/init-db.c                |   1 +
 builtin/log.c                    |   1 +
 builtin/ls-files.c               |   1 +
 builtin/ls-tree.c                |   1 +
 builtin/merge-base.c             |   1 +
 builtin/merge-file.c             |   1 +
 builtin/merge.c                  |   1 +
 builtin/mv.c                     |   1 +
 builtin/name-rev.c               |   1 +
 builtin/notes.c                  |   1 +
 builtin/pack-objects.c           |   1 +
 builtin/patch-id.c               |   1 +
 builtin/pull.c                   |   1 +
 builtin/push.c                   |   1 +
 builtin/read-tree.c              |   1 +
 builtin/rebase--helper.c         |   1 +
 builtin/receive-pack.c           |   1 +
 builtin/reflog.c                 |   1 +
 builtin/remote.c                 |   1 +
 builtin/repack.c                 |   1 +
 builtin/replace.c                |   1 +
 builtin/rerere.c                 |   1 +
 builtin/reset.c                  |   1 +
 builtin/rev-list.c               |   1 +
 builtin/rev-parse.c              |   1 +
 builtin/revert.c                 |   1 +
 builtin/rm.c                     |   1 +
 builtin/send-pack.c              |   1 +
 builtin/shortlog.c               |   1 +
 builtin/show-branch.c            |   1 +
 builtin/stripspace.c             |   1 +
 builtin/submodule--helper.c      |   1 +
 builtin/symbolic-ref.c           |   1 +
 builtin/tag.c                    |   1 +
 builtin/unpack-file.c            |   1 +
 builtin/unpack-objects.c         |   1 +
 builtin/update-index.c           |   1 +
 builtin/update-ref.c             |   1 +
 builtin/update-server-info.c     |   1 +
 builtin/var.c                    |   1 +
 builtin/verify-commit.c          |   1 +
 builtin/verify-pack.c            |   1 +
 builtin/verify-tag.c             |   1 +
 builtin/worktree.c               |   1 +
 builtin/write-tree.c             |   1 +
 cache.h                          | 204 ++-------------------------------------
 color.c                          |   1 +
 column.c                         |   1 +
 compat/precompose_utf8.c         |   1 +
 config.c                         |  41 ++++----
 config.h                         | 194 +++++++++++++++++++++++++++++++++++++
 connect.c                        |   1 +
 convert.c                        |   1 +
 credential-cache--daemon.c       |   1 +
 credential.c                     |   1 +
 daemon.c                         |   1 +
 diff.c                           |   1 +
 dir.c                            |   1 +
 environment.c                    |   1 +
 fast-import.c                    |   1 +
 fetch-pack.c                     |   1 +
 git.c                            |   1 +
 gpg-interface.c                  |   1 +
 graph.c                          |   1 +
 grep.c                           |   1 +
 help.c                           |   1 +
 http-backend.c                   |   1 +
 http-fetch.c                     |   1 +
 http.c                           |   1 +
 ident.c                          |   1 +
 imap-send.c                      |   1 +
 ll-merge.c                       |   1 +
 log-tree.c                       |   1 +
 mailinfo.c                       |   1 +
 merge-recursive.c                |   1 +
 notes-utils.c                    |   1 +
 notes.c                          |   1 +
 pager.c                          |   1 +
 parse-options.c                  |   1 +
 pathspec.c                       |   1 +
 pretty.c                         |   1 +
 prompt.c                         |   1 +
 read-cache.c                     |   1 +
 refs.c                           |   1 +
 refs/files-backend.c             |   1 +
 remote-curl.c                    |   1 +
 remote.c                         |   1 +
 rerere.c                         |   1 +
 send-pack.c                      |   1 +
 sequencer.c                      |   1 +
 setup.c                          |  18 ++--
 sha1_file.c                      |   1 +
 sha1_name.c                      |   1 +
 submodule-config.c               |   1 +
 submodule.c                      |   1 +
 t/helper/test-config.c           |   1 +
 t/helper/test-submodule-config.c |   1 +
 trailer.c                        |   1 +
 transport.c                      |   1 +
 unpack-trees.c                   |   1 +
 upload-pack.c                    |   1 +
 userdiff.c                       |   1 +
 versioncmp.c                     |   1 +
 wrapper.c                        |   1 +
 xdiff-interface.c                |   1 +
 147 files changed, 398 insertions(+), 229 deletions(-)
 create mode 100644 config.h

-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply	[flat|nested] 57+ messages in thread

* [PATCH v3 1/6] config: create config.h
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 2/6] config: remove git_config_iter Brandon Williams
                       ` (5 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Move all config related declarations from cache.h to a new config.h
header file.  This makes cache.h smaller and allows for the opportunity
in a following patch to only include config.h when needed.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h  | 190 +------------------------------------------------------------
 config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+), 189 deletions(-)
 create mode 100644 config.h

diff --git a/cache.h b/cache.h
index 4d92aae0e..ed56f8818 100644
--- a/cache.h
+++ b/cache.h
@@ -11,6 +11,7 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
+#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
@@ -1872,188 +1873,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.
@@ -2061,16 +1883,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);
 
diff --git a/config.h b/config.h
new file mode 100644
index 000000000..f7f8b66c5
--- /dev/null
+++ b/config.h
@@ -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 *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 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);
+
+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 */
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v3 2/6] config: remove git_config_iter
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 1/6] config: create config.h Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 3/6] config: don't include config.h by default Brandon Williams
                       ` (4 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Since there is no implementation of the function 'git_config_iter',
let's stop exporting it and remove the prototype from config.h.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 config.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.h b/config.h
index f7f8b66c5..c70599bd5 100644
--- a/config.h
+++ b/config.h
@@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, co
 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);
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v3 3/6] config: don't include config.h by default
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 1/6] config: create config.h Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 2/6] config: remove git_config_iter Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 4/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
                       ` (3 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Stop including config.h by default in cache.h.  Instead only include
config.h in those files which require use of the config system.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 advice.c                         | 1 +
 alias.c                          | 1 +
 apply.c                          | 1 +
 archive-tar.c                    | 1 +
 archive-zip.c                    | 1 +
 archive.c                        | 1 +
 attr.c                           | 1 +
 bisect.c                         | 1 +
 branch.c                         | 1 +
 builtin/add.c                    | 1 +
 builtin/am.c                     | 1 +
 builtin/blame.c                  | 2 ++
 builtin/branch.c                 | 1 +
 builtin/cat-file.c               | 1 +
 builtin/check-attr.c             | 1 +
 builtin/check-ignore.c           | 1 +
 builtin/check-mailmap.c          | 1 +
 builtin/checkout-index.c         | 1 +
 builtin/checkout.c               | 1 +
 builtin/clean.c                  | 1 +
 builtin/clone.c                  | 1 +
 builtin/column.c                 | 1 +
 builtin/commit-tree.c            | 1 +
 builtin/commit.c                 | 1 +
 builtin/config.c                 | 1 +
 builtin/count-objects.c          | 1 +
 builtin/describe.c               | 1 +
 builtin/diff-files.c             | 1 +
 builtin/diff-index.c             | 1 +
 builtin/diff-tree.c              | 1 +
 builtin/diff.c                   | 1 +
 builtin/difftool.c               | 1 +
 builtin/fast-export.c            | 1 +
 builtin/fetch.c                  | 1 +
 builtin/fmt-merge-msg.c          | 1 +
 builtin/for-each-ref.c           | 1 +
 builtin/fsck.c                   | 1 +
 builtin/gc.c                     | 1 +
 builtin/grep.c                   | 1 +
 builtin/hash-object.c            | 1 +
 builtin/help.c                   | 1 +
 builtin/index-pack.c             | 1 +
 builtin/init-db.c                | 1 +
 builtin/log.c                    | 1 +
 builtin/ls-files.c               | 1 +
 builtin/ls-tree.c                | 1 +
 builtin/merge-base.c             | 1 +
 builtin/merge-file.c             | 1 +
 builtin/merge.c                  | 1 +
 builtin/mv.c                     | 1 +
 builtin/name-rev.c               | 1 +
 builtin/notes.c                  | 1 +
 builtin/pack-objects.c           | 1 +
 builtin/patch-id.c               | 1 +
 builtin/pull.c                   | 1 +
 builtin/push.c                   | 1 +
 builtin/read-tree.c              | 1 +
 builtin/rebase--helper.c         | 1 +
 builtin/receive-pack.c           | 1 +
 builtin/reflog.c                 | 1 +
 builtin/remote.c                 | 1 +
 builtin/repack.c                 | 1 +
 builtin/replace.c                | 1 +
 builtin/rerere.c                 | 1 +
 builtin/reset.c                  | 1 +
 builtin/rev-list.c               | 1 +
 builtin/rev-parse.c              | 1 +
 builtin/revert.c                 | 1 +
 builtin/rm.c                     | 1 +
 builtin/send-pack.c              | 1 +
 builtin/shortlog.c               | 1 +
 builtin/show-branch.c            | 1 +
 builtin/stripspace.c             | 1 +
 builtin/submodule--helper.c      | 1 +
 builtin/symbolic-ref.c           | 1 +
 builtin/tag.c                    | 1 +
 builtin/unpack-file.c            | 1 +
 builtin/unpack-objects.c         | 1 +
 builtin/update-index.c           | 1 +
 builtin/update-ref.c             | 1 +
 builtin/update-server-info.c     | 1 +
 builtin/var.c                    | 1 +
 builtin/verify-commit.c          | 1 +
 builtin/verify-pack.c            | 1 +
 builtin/verify-tag.c             | 1 +
 builtin/worktree.c               | 1 +
 builtin/write-tree.c             | 1 +
 cache.h                          | 1 -
 color.c                          | 1 +
 column.c                         | 1 +
 compat/precompose_utf8.c         | 1 +
 config.c                         | 1 +
 connect.c                        | 1 +
 convert.c                        | 1 +
 credential-cache--daemon.c       | 1 +
 credential.c                     | 1 +
 daemon.c                         | 1 +
 diff.c                           | 1 +
 dir.c                            | 1 +
 environment.c                    | 1 +
 fast-import.c                    | 1 +
 fetch-pack.c                     | 1 +
 git.c                            | 1 +
 gpg-interface.c                  | 1 +
 graph.c                          | 1 +
 grep.c                           | 1 +
 help.c                           | 1 +
 http-backend.c                   | 1 +
 http-fetch.c                     | 1 +
 http.c                           | 1 +
 ident.c                          | 1 +
 imap-send.c                      | 1 +
 ll-merge.c                       | 1 +
 log-tree.c                       | 1 +
 mailinfo.c                       | 1 +
 merge-recursive.c                | 1 +
 notes-utils.c                    | 1 +
 notes.c                          | 1 +
 pager.c                          | 1 +
 parse-options.c                  | 1 +
 pathspec.c                       | 1 +
 pretty.c                         | 1 +
 prompt.c                         | 1 +
 read-cache.c                     | 1 +
 refs.c                           | 1 +
 refs/files-backend.c             | 1 +
 remote-curl.c                    | 1 +
 remote.c                         | 1 +
 rerere.c                         | 1 +
 send-pack.c                      | 1 +
 sequencer.c                      | 1 +
 setup.c                          | 1 +
 sha1_file.c                      | 1 +
 sha1_name.c                      | 1 +
 submodule-config.c               | 1 +
 submodule.c                      | 1 +
 t/helper/test-config.c           | 1 +
 t/helper/test-submodule-config.c | 1 +
 trailer.c                        | 1 +
 transport.c                      | 1 +
 unpack-trees.c                   | 1 +
 upload-pack.c                    | 1 +
 userdiff.c                       | 1 +
 versioncmp.c                     | 1 +
 wrapper.c                        | 1 +
 xdiff-interface.c                | 1 +
 146 files changed, 146 insertions(+), 1 deletion(-)

diff --git a/advice.c b/advice.c
index b84ae4960..3fa04fca0 100644
--- a/advice.c
+++ b/advice.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
diff --git a/alias.c b/alias.c
index 5df052ae4..f7bc0f72b 100644
--- a/alias.c
+++ b/alias.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 struct config_alias_data
 {
diff --git a/apply.c b/apply.c
index c49cef063..87db9618d 100644
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index 073e60ebd..c6ed96ee7 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -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"
diff --git a/archive-zip.c b/archive-zip.c
index 27563e9e2..e8913e5a2 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2006 Rene Scharfe
  */
 #include "cache.h"
+#include "config.h"
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
diff --git a/archive.c b/archive.c
index b15a922da..60b3035a7 100644
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 7e2134471..9f8b02936 100644
--- a/attr.c
+++ b/attr.c
@@ -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"
diff --git a/bisect.c b/bisect.c
index c952df692..d8587d11c 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/branch.c b/branch.c
index 985316eb7..a8a548ccf 100644
--- a/branch.c
+++ b/branch.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "config.h"
 #include "branch.h"
 #include "refs.h"
 #include "remote.h"
diff --git a/builtin/add.c b/builtin/add.c
index d9a2491e4..f2415e99f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5ee146bfb..242d70361 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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"
diff --git a/builtin/blame.c b/builtin/blame.c
index d7a2df3b4..381927920 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,6 +6,8 @@
  */
 
 #include "cache.h"
+#include "config.h"
+#include "refs.h"
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/branch.c b/builtin/branch.c
index 83fcda43d..c958e9325 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4bffd7a2d..7efbc4019 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 4d01ca0c8..91444dc04 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index c7b8c0889..3e280b9c7 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cf0f54f6b..cdce144f3 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 07631d0c9..39c8be05d 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -5,6 +5,7 @@
  *
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a6b2af39d..45fab5a4d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index 142bf668c..ed954134d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 743f16ae2..4922a5496 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
diff --git a/builtin/column.c b/builtin/column.c
index 33314b4d7..0c3223d64 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index f39c2b273..a4a923d7c 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index da1ba4c86..805da4915 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
diff --git a/builtin/config.c b/builtin/config.c
index 7f6c25d4d..753c40a5c 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "parse-options.h"
 #include "urlmatch.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index acb05940f..1d82e61f2 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 893c8789f..70eb14460 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index a572da9d5..965f2fb76 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index f084826a2..ad9971f64 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e40111204..36c220f93 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "log-tree.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index 0c8f86e40..0d59e99ef 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index b9a892f26..9199227f6 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -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"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 24e29ad7e..0dfd980dd 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "object.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 47708451b..65317bd6c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2,6 +2,7 @@
  * "git fetch"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 70137b0b7..10cbb4341 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index eca365bf8..52be99cba 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index cb2ba6cd1..90593491e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/builtin/gc.c b/builtin/gc.c
index f484eda43..bd91f136f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "parse-options.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7df9c253e..7f720ca6c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -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"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index bbeaf20bc..d04baf999 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -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"
diff --git a/builtin/help.c b/builtin/help.c
index 49f7a07f8..334a8494a 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -2,6 +2,7 @@
  * Builtin help command
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 04b9dcaf0..edc1a91d8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "delta.h"
 #include "pack.h"
 #include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 8a6acb0ec..47823f9aa 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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"
diff --git a/builtin/log.c b/builtin/log.c
index e89ec941c..01d7213c1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
  *		 2006 Junio Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "color.h"
 #include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc31..c4357dc30 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -6,6 +6,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ee7b293b1..ef965408e 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 0c36a70ad..6dbd167d3 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 47dde7c39..b08803e61 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -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"
diff --git a/builtin/merge.c b/builtin/merge.c
index a4a098f40..2512370c1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "builtin.h"
 #include "lockfile.h"
diff --git a/builtin/mv.c b/builtin/mv.c
index 61d20037a..dcf6736b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Johannes Schindelin
  */
 #include "builtin.h"
+#include "config.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7fc7e66e8..e21715f1d 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 7196bff0e..8d14f434a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "notes.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f672225de..d5e96ed2d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 81552e02e..970d0d30b 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -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)
 {
diff --git a/builtin/pull.c b/builtin/pull.c
index da8b60fc8..0c77381da 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -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"
diff --git a/builtin/push.c b/builtin/push.c
index a597759d8..76aa713d2 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -2,6 +2,7 @@
  * "git push"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "run-command.h"
 #include "builtin.h"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 78d319365..6eb2a0e57 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "tree.h"
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index ca1ebb2fa..c82b4dce6 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "sequencer.h"
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b1706a573..71c0c768d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 920c16dac..44cdc2dbd 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe26..6273c0c23 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 38ba4ef82..f17a68a17 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index c921bc976..80a15cf35 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -9,6 +9,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1bf72423b..ffb66e290 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 430602d10..d0b604103 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 718c6059c..f8e2b7bf5 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index efdc14473..c78b7b33d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 345d9586a..16028b9ea 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 7c323d012..824d1de9e 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -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"
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index b8e2e74fe..633e0c3cd 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7cff1839f..43c4799ea 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "string-list.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 4a6cc6f49..e4cf1b5bb 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "builtin.h"
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e62a008c..bdf032886 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8cc648d85..4dcbfb952 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 70addef15..df75cb9d4 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "cache.h"
 #include "refs.h"
 #include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 1f74a56db..01154ea8d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "tag.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6fc6bcdf7..73f133419 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 
 static char *create_temp_file(unsigned char *sha1)
 {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 8bc999776..193f8b9d5 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ebfc09faa..0a4c23648 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -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"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0b2ecf41a..40ccfc193 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6c8cc3edc..873070e51 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53a2..6c6f46b4a 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,6 +4,7 @@
  * Copyright (C) Eric Biederman, 2005
  */
 #include "builtin.h"
+#include "config.h"
 
 static const char var_usage[] = "git var (-l | <variable>)";
 
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05b734e6d..ba38ac9b1 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -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"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c94e15693..c2a1a5c50 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "parse-options.h"
 
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5199553d9..f9a5f7535 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -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"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 793306ea5..0c5476ee9 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "dir.h"
 #include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 084c0df78..bd0a78aa3 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
diff --git a/cache.h b/cache.h
index ed56f8818..fd45b8c55 100644
--- a/cache.h
+++ b/cache.h
@@ -11,7 +11,6 @@
 #include "string-list.h"
 #include "pack-revindex.h"
 #include "hash.h"
-#include "config.h"
 
 #ifndef platform_SHA_CTX
 /*
diff --git a/color.c b/color.c
index dee61557e..31b6207a0 100644
--- a/color.c
+++ b/color.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
diff --git a/column.c b/column.c
index d55ead18e..ff7bdab1a 100644
--- a/column.c
+++ b/column.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "column.h"
 #include "string-list.h"
 #include "parse-options.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 4293b53b1..de61c15d3 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -6,6 +6,7 @@
 #define PRECOMPOSE_UNICODE_C
 
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
diff --git a/config.c b/config.c
index 12c172e29..990f15dc4 100644
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
diff --git a/connect.c b/connect.c
index c72b1d115..e78d3f43d 100644
--- a/connect.c
+++ b/connect.c
@@ -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"
diff --git a/convert.c b/convert.c
index f1e168bc3..5f4a4b1f5 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index f3814cc47..0d5c62509 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "credential.h"
 #include "unix-socket.h"
diff --git a/credential.c b/credential.c
index aa996669f..67a523353 100644
--- a/credential.c
+++ b/credential.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "string-list.h"
 #include "run-command.h"
diff --git a/daemon.c b/daemon.c
index ac7181a48..30747075f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index 5275c4b78..3458ec640 100644
--- a/diff.c
+++ b/diff.c
@@ -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"
diff --git a/dir.c b/dir.c
index 9efcf1eab..d4e4258ea 100644
--- a/dir.c
+++ b/dir.c
@@ -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"
diff --git a/environment.c b/environment.c
index aa478e71d..d40b21fb7 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
 #include "commit.h"
diff --git a/fast-import.c b/fast-import.c
index e69d21968..2881d4898 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -154,6 +154,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "blob.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index cd86865be..fbbc99c88 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/git.c b/git.c
index 58ef57029..c03de2c09 100644
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "help.h"
 #include "run-command.h"
diff --git a/gpg-interface.c b/gpg-interface.c
index e44cc27da..8ab32df45 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "gpg-interface.h"
diff --git a/graph.c b/graph.c
index 8b9049dd2..e7e20650d 100644
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "graph.h"
diff --git a/grep.c b/grep.c
index d03d424e5..62c7cf970 100644
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "grep.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/help.c b/help.c
index b44c55ec2..328ecd339 100644
--- a/help.c
+++ b/help.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/http-backend.c b/http-backend.c
index ba5ff1aa2..519025d2c 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "object.h"
diff --git a/http-fetch.c b/http-fetch.c
index 3b556d661..8af380050 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "http.h"
 #include "walker.h"
diff --git a/http.c b/http.c
index d2e11ec6f..013bb0cc6 100644
--- a/http.c
+++ b/http.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "http.h"
+#include "config.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/ident.c b/ident.c
index bea871c8e..d41fc9119 100644
--- a/ident.c
+++ b/ident.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2005 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
diff --git a/imap-send.c b/imap-send.c
index 857591660..59e9b12d2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -23,6 +23,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
diff --git a/ll-merge.c b/ll-merge.c
index ac0d4a5d7..24ff94e1d 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
diff --git a/log-tree.c b/log-tree.c
index a4ec11c2b..7e1dfd749 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "tag.h"
diff --git a/mailinfo.c b/mailinfo.c
index f92cb9f72..f59162453 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index ae5238d82..c2494f34f 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -4,6 +4,7 @@
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
 #include "cache.h"
+#include "config.h"
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/notes-utils.c b/notes-utils.c
index 031503d7b..3f6cbdc47 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index 542563b28..dbcfef4d7 100644
--- a/notes.c
+++ b/notes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "notes.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/pager.c b/pager.c
index c113d898a..4dd9e1b26 100644
--- a/pager.c
+++ b/pager.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
 
diff --git a/parse-options.c b/parse-options.c
index e5ad34a2c..0dd9fc6a0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "utf8.h"
diff --git a/pathspec.c b/pathspec.c
index 828405021..ecc5331c2 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "attr.h"
diff --git a/pretty.c b/pretty.c
index 09701bd2f..9c9f81b5b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "utf8.h"
 #include "diff.h"
diff --git a/prompt.c b/prompt.c
index 75406390c..6d5885d00 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
diff --git a/read-cache.c b/read-cache.c
index bc156a133..c8c766dab 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/refs.c b/refs.c
index f0685c925..84112c88e 100644
--- a/refs.c
+++ b/refs.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "lockfile.h"
 #include "iterator.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d8b3f7314..621a4086c 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,5 @@
 #include "../cache.h"
+#include "../config.h"
 #include "../refs.h"
 #include "refs-internal.h"
 #include "ref-cache.h"
diff --git a/remote-curl.c b/remote-curl.c
index ece45993d..0053b0954 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "strbuf.h"
 #include "walker.h"
diff --git a/remote.c b/remote.c
index 3649d60cd..68d20f650 100644
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "refs.h"
 #include "commit.h"
diff --git a/rerere.c b/rerere.c
index 3bd55caf3..344d6aa81 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
diff --git a/send-pack.c b/send-pack.c
index 78bb34ebe..ed3cee321 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/sequencer.c b/sequencer.c
index 924fb1d0c..86b0640d2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index 2435186e4..c6c00463a 100644
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "string-list.h"
 
diff --git a/sha1_file.c b/sha1_file.c
index 59a4ed2ed..44561e0b9 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "lockfile.h"
 #include "delta.h"
diff --git a/sha1_name.c b/sha1_name.c
index e9ffe685d..2875771ff 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
diff --git a/submodule-config.c b/submodule-config.c
index 4f58491dd..d8f8d5ea3 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
diff --git a/submodule.c b/submodule.c
index bf5a93d16..95328de61 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "dir.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 8e3ed6a76..1a7b8bd3d 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 2f144d539..c6c57bba0 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
diff --git a/trailer.c b/trailer.c
index 11f0b9fb4..751b56c00 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
diff --git a/transport.c b/transport.c
index 9bfcf870f..b9995306f 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "transport.h"
 #include "run-command.h"
 #include "pkt-line.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index d38c37e38..dd535bc84 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index 5330c02c1..7efff2fbf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
diff --git a/userdiff.c b/userdiff.c
index 8b732e40b..2c1502f71 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "userdiff.h"
 #include "attr.h"
 
diff --git a/versioncmp.c b/versioncmp.c
index 9f81dc106..069ee94a4 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
diff --git a/wrapper.c b/wrapper.c
index d83741770..487a9f753 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "config.h"
 
 static void do_nothing(size_t size)
 {
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 060038c2d..5ac07d734 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v3 4/6] setup: teach discover_git_directory to respect the commondir
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
                       ` (2 preceding siblings ...)
  2017-06-14 18:07     ` [PATCH v3 3/6] config: don't include config.h by default Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 5/6] config: respect commondir Brandon Williams
                       ` (2 subsequent siblings)
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Currently 'discover_git_directory' only looks at the gitdir to determine
if a git directory was discovered.  This causes a problem in the event
that the gitdir which was discovered was in fact a per-worktree git
directory and not the common git directory.  This is because the
repository config, which is checked to verify the repository's format,
is stored in the commondir and not in the per-worktree gitdir.  Correct
this behavior by checking the config stored in the commondir.

It will also be of use for callers to have access to the commondir, so
lets also return that upon successfully discovering a git directory.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h  | 15 +++++++++------
 config.c | 10 ++++++----
 setup.c  | 17 +++++++++++------
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/cache.h b/cache.h
index fd45b8c55..8fb2dfd27 100644
--- a/cache.h
+++ b/cache.h
@@ -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.
- */
-extern const char *discover_git_directory(struct strbuf *gitdir);
+ * 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 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);
diff --git a/config.c b/config.c
index 990f15dc4..e82e1d987 100644
--- a/config.c
+++ b/config.c
@@ -1655,7 +1655,8 @@ 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;
 
@@ -1669,12 +1670,13 @@ 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.git_dir = gitdir.buf;
 
 	git_config_with_options(cb, data, NULL, &opts);
 
-	strbuf_release(&buf);
+	strbuf_release(&commondir);
+	strbuf_release(&gitdir);
 }
 
 static void git_config_check_init(void);
diff --git a/setup.c b/setup.c
index c6c00463a..c26f1e0a3 100644
--- a/setup.c
+++ b/setup.c
@@ -946,19 +946,21 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
 	}
 }
 
-const char *discover_git_directory(struct strbuf *gitdir)
+int discover_git_directory(struct strbuf *commondir,
+			   struct strbuf *gitdir)
 {
 	struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
 	size_t gitdir_offset = gitdir->len, cwd_len;
+	size_t commondir_offset = commondir->len;
 	struct repository_format candidate;
 
 	if (strbuf_getcwd(&dir))
-		return NULL;
+		return -1;
 
 	cwd_len = dir.len;
 	if (setup_git_directory_gently_1(&dir, gitdir, 0) <= 0) {
 		strbuf_release(&dir);
-		return NULL;
+		return -1;
 	}
 
 	/*
@@ -974,8 +976,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
 	}
 
+	get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
 	strbuf_reset(&dir);
-	strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+	strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
 	read_repository_format(&candidate, dir.buf);
 	strbuf_release(&dir);
 
@@ -983,11 +987,12 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		warning("ignoring git dir '%s': %s",
 			gitdir->buf + gitdir_offset, err.buf);
 		strbuf_release(&err);
+		strbuf_setlen(commondir, commondir_offset);
 		strbuf_setlen(gitdir, gitdir_offset);
-		return NULL;
+		return -1;
 	}
 
-	return gitdir->buf + gitdir_offset;
+	return 0;
 }
 
 const char *setup_git_directory_gently(int *nongit_ok)
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v3 5/6] config: respect commondir
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
                       ` (3 preceding siblings ...)
  2017-06-14 18:07     ` [PATCH v3 4/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-14 18:07     ` [PATCH v3 6/6] config: don't implicitly use gitdir or commondir Brandon Williams
  2017-06-15 19:59     ` [PATCH v3 0/6] config.h Junio C Hamano
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

Worktrees present an interesting problem when it comes to the config.
Historically we could assume that the per-repository config lives at
'gitdir/config', but since worktrees were introduced this isn't the case
anymore.  There is currently no way to specify per-worktree
configuration, and as such the repository config is shared with all
worktrees and is located at 'commondir/config'.

Many users of the config machinery correctly set
'config_options.git_dir' with the repository's commondir, allowing the
config to be properly loaded when operating in a worktree.  But other's,
like 'read_early_config()', set 'config_options.git_dir' with the
repository's gitdir which can be incorrect when using worktrees.

To fix this issue, and to make things less ambiguous, lets add a
'commondir' field to the 'config_options' struct and have all callers
properly set both the 'git_dir' and 'commondir' fields so that the
config machinery is able to properly find the repository's config.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 config.c | 11 +++++++----
 config.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/config.c b/config.c
index e82e1d987..dd7ad5e1e 100644
--- a/config.c
+++ b/config.c
@@ -1547,8 +1547,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);
+	if (opts->commondir)
+		repo_config = mkpathdup("%s/config", opts->commondir);
 	else if (have_git_dir())
 		repo_config = git_pathdup("config");
 	else
@@ -1660,7 +1660,8 @@ void read_early_config(config_fn_t cb, void *data)
 
 	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
@@ -1670,8 +1671,10 @@ 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(&commondir, &gitdir))
+	} else if (!discover_git_directory(&commondir, &gitdir)) {
+		opts.commondir = commondir.buf;
 		opts.git_dir = gitdir.buf;
+	}
 
 	git_config_with_options(cb, data, NULL, &opts);
 
diff --git a/config.h b/config.h
index c70599bd5..63b92784c 100644
--- a/config.h
+++ b/config.h
@@ -30,6 +30,7 @@ enum config_origin_type {
 
 struct config_options {
 	unsigned int respect_includes : 1;
+	const char *commondir;
 	const char *git_dir;
 };
 
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v3 6/6] config: don't implicitly use gitdir or commondir
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
                       ` (4 preceding siblings ...)
  2017-06-14 18:07     ` [PATCH v3 5/6] config: respect commondir Brandon Williams
@ 2017-06-14 18:07     ` Brandon Williams
  2017-06-15 19:59     ` [PATCH v3 0/6] config.h Junio C Hamano
  6 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-14 18:07 UTC (permalink / raw)
  To: git; +Cc: peff, jrnieder, gitster, Johannes.Schindelin, Brandon Williams

'git_config_with_options()' takes a 'config_options' struct which
contains feilds for 'git_dir' and 'commondir'.  If those feilds happen
to be NULL the config machinery falls back to querying global repository
state.  Let's change this and instead use these fields in the
'config_options' struct explicilty all the time.  Since the API is
slightly changing to require these two fields to be set if callers want
the config machinery to load the repository's config, let's change the
name to 'config_with_optison()'.  This allows the config machinery to
not implicitly rely on any global repository state.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/config.c | 26 +++++++++++++++-----------
 config.c         | 21 +++++++++++----------
 config.h         |  6 +++---
 3 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 753c40a5c..82db29fae 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -243,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;
 
@@ -321,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)
@@ -353,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"))
@@ -442,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;
 
@@ -539,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';
@@ -583,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);
diff --git a/config.c b/config.c
index dd7ad5e1e..822d63787 100644
--- a/config.c
+++ b/config.c
@@ -219,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;
 
@@ -1549,8 +1547,6 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 	if (opts->commondir)
 		repo_config = mkpathdup("%s/config", opts->commondir);
-	else if (have_git_dir())
-		repo_config = git_pathdup("config");
 	else
 		repo_config = NULL;
 
@@ -1581,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;
 
@@ -1614,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
@@ -1676,7 +1677,7 @@ void read_early_config(config_fn_t cb, void *data)
 		opts.git_dir = gitdir.buf;
 	}
 
-	git_config_with_options(cb, data, NULL, &opts);
+	config_with_options(cb, data, NULL, &opts);
 
 	strbuf_release(&commondir);
 	strbuf_release(&gitdir);
diff --git a/config.h b/config.h
index 63b92784c..9e038cce2 100644
--- a/config.h
+++ b/config.h
@@ -45,9 +45,9 @@ 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 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 *);
-- 
2.13.1.518.g3df882009-goog


^ permalink raw reply related	[flat|nested] 57+ messages in thread

* Re: [PATCH v3 0/6] config.h
  2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
                       ` (5 preceding siblings ...)
  2017-06-14 18:07     ` [PATCH v3 6/6] config: don't implicitly use gitdir or commondir Brandon Williams
@ 2017-06-15 19:59     ` Junio C Hamano
  2017-06-15 20:33       ` Brandon Williams
  6 siblings, 1 reply; 57+ messages in thread
From: Junio C Hamano @ 2017-06-15 19:59 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, jrnieder, Johannes.Schindelin

Brandon Williams <bmwill@google.com> writes:

> Changes in v3:
>
> * tweaked the discover_git_directory function's API based on Peff's feedback
> * reordered the last three patches so that they flowed a bit better
> * renamed 'git_config_with_options'
> * rebased ontop of v4 of Dscho's alias series
>   https://public-inbox.org/git/cover.1497440104.git.johannes.schindelin@gmx.de/

Applying this series was messier than necessary, I'd have to say, as
this series would not apply cleanly on top of the result of applying
Dscho's v4 on top of the same base as Dscho's v3 was applied (which
is v2.13.0).  It applied cleanly only when Dscho's v4 and then this
series were applied on top of 02a2850a ("Sync with maint",
2017-06-13), which is a much newer commit than v2.13.0.

Which in turn means these two fixes cannot be merged to 'maint' as
you two collaboratively prepared.

I've applied Dscho's v4 on top of v2.13.0 (just like his v3 was
queued in my tree on the same base), and then tweaked this series to
apply on top of that, so that they can go to 'maint' if we chose to.

But it is possible that during this unnecessary patch shuffling, I
may have made some mistake, so please eyeball the resulting 12
patches carefully when they are pushed out.

Thanks.
>

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v3 0/6] config.h
  2017-06-15 19:59     ` [PATCH v3 0/6] config.h Junio C Hamano
@ 2017-06-15 20:33       ` Brandon Williams
  2017-06-15 21:09         ` Junio C Hamano
  0 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-15 20:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, peff, jrnieder, Johannes.Schindelin

On 06/15, Junio C Hamano wrote:
> Brandon Williams <bmwill@google.com> writes:
> 
> > Changes in v3:
> >
> > * tweaked the discover_git_directory function's API based on Peff's feedback
> > * reordered the last three patches so that they flowed a bit better
> > * renamed 'git_config_with_options'
> > * rebased ontop of v4 of Dscho's alias series
> >   https://public-inbox.org/git/cover.1497440104.git.johannes.schindelin@gmx.de/
> 
> Applying this series was messier than necessary, I'd have to say, as
> this series would not apply cleanly on top of the result of applying
> Dscho's v4 on top of the same base as Dscho's v3 was applied (which
> is v2.13.0).  It applied cleanly only when Dscho's v4 and then this
> series were applied on top of 02a2850a ("Sync with maint",
> 2017-06-13), which is a much newer commit than v2.13.0.
> 
> Which in turn means these two fixes cannot be merged to 'maint' as
> you two collaboratively prepared.
> 
> I've applied Dscho's v4 on top of v2.13.0 (just like his v3 was
> queued in my tree on the same base), and then tweaked this series to
> apply on top of that, so that they can go to 'maint' if we chose to.
> 
> But it is possible that during this unnecessary patch shuffling, I
> may have made some mistake, so please eyeball the resulting 12
> patches carefully when they are pushed out.

Ugh, I'm terribly sorry.  Completely my bad as I didn't consider what
you would need to do on your end.  When I built my patches on top of his
I naively just applied his v4 to what ever the current origin/master was
at that point in time.  I'll be sure to be more careful with this
next time.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v3 0/6] config.h
  2017-06-15 20:33       ` Brandon Williams
@ 2017-06-15 21:09         ` Junio C Hamano
  2017-06-15 21:18           ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Junio C Hamano @ 2017-06-15 21:09 UTC (permalink / raw)
  To: Brandon Williams; +Cc: git, peff, jrnieder, Johannes.Schindelin

Brandon Williams <bmwill@google.com> writes:

> On 06/15, Junio C Hamano wrote:
>
>> ... so please eyeball the resulting 12 patches carefully when
>> they are pushed out.
>
> Ugh, I'm terribly sorry.  Completely my bad as I didn't consider what
> you would need to do on your end.  When I built my patches on top of his
> I naively just applied his v4 to what ever the current origin/master was
> at that point in time.  I'll be sure to be more careful with this
> next time.

It's no big deal (otherwise I would have insisted you to rebase so
that the end result can be merged to 'maint', instead of doing it
myself).

But quite honestly, I do not understand why you rebased this on top
of the alias thing.  Help me make sure that I correctly undertand
what these two topics want to do:

 - The primary point of js/alias-early-config is to fix reading of
   pager config from a wrong place when alias expansion is involved,
   and its solution has a nice property that it simplifies the alias
   lookup and avoids the unpleasant save/restore-env dance by
   switching to use the early-config mechanism.

 - Unfortunately, the early-config mechanism is broken with respect
   to multi-worktree configuration because it does not pay attention
   to the common-dir stuff.

 - The primary objective of bw/config-h was to separate out the
   configuration related things out of the kitchen-sink cache.h, but
   as a nice side effect, it also fixes the early-config mechanism.

Assuming that the above reading of mine of these two topics are
correct, we can conclude that even if we merge js/alias-early-config
that forks from v2.13.0 to 'maint', the result by itself would
regress the use of alias in multi-worktree configuration.  For it to
be useful, it must be merged after bw/config-h gets merged.

So it looks to me that it would make more sense to build bw/config-h
on v2.13.0 and then base js/alias-early-config on top of the result.
If Dscho is too busy to rebase and you are volunteering to help,
perhaps the right way to help would be for you to do that rebasing,
not rebase bw/config-h on top of js/alias-early-config, which is
backwards and does not buy us very much.  Of course, we could make
the result of such rebasing into a single topic, but even in that
case, the order of changes feel backwards if bw/config-h comes
later.

Anyway, I think I have to tend to many more patches before I can
push out today's integration result, so ...



^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v3 0/6] config.h
  2017-06-15 21:09         ` Junio C Hamano
@ 2017-06-15 21:18           ` Brandon Williams
  2017-06-16  0:12             ` Brandon Williams
  0 siblings, 1 reply; 57+ messages in thread
From: Brandon Williams @ 2017-06-15 21:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, peff, jrnieder, Johannes.Schindelin

On 06/15, Junio C Hamano wrote:
> Brandon Williams <bmwill@google.com> writes:
> 
> > On 06/15, Junio C Hamano wrote:
> >
> >> ... so please eyeball the resulting 12 patches carefully when
> >> they are pushed out.
> >
> > Ugh, I'm terribly sorry.  Completely my bad as I didn't consider what
> > you would need to do on your end.  When I built my patches on top of his
> > I naively just applied his v4 to what ever the current origin/master was
> > at that point in time.  I'll be sure to be more careful with this
> > next time.
> 
> It's no big deal (otherwise I would have insisted you to rebase so
> that the end result can be merged to 'maint', instead of doing it
> myself).
> 
> But quite honestly, I do not understand why you rebased this on top
> of the alias thing.  Help me make sure that I correctly undertand
> what these two topics want to do:
> 
>  - The primary point of js/alias-early-config is to fix reading of
>    pager config from a wrong place when alias expansion is involved,
>    and its solution has a nice property that it simplifies the alias
>    lookup and avoids the unpleasant save/restore-env dance by
>    switching to use the early-config mechanism.
> 
>  - Unfortunately, the early-config mechanism is broken with respect
>    to multi-worktree configuration because it does not pay attention
>    to the common-dir stuff.
> 
>  - The primary objective of bw/config-h was to separate out the
>    configuration related things out of the kitchen-sink cache.h, but
>    as a nice side effect, it also fixes the early-config mechanism.
> 
> Assuming that the above reading of mine of these two topics are
> correct, we can conclude that even if we merge js/alias-early-config
> that forks from v2.13.0 to 'maint', the result by itself would
> regress the use of alias in multi-worktree configuration.  For it to
> be useful, it must be merged after bw/config-h gets merged.
> 
> So it looks to me that it would make more sense to build bw/config-h
> on v2.13.0 and then base js/alias-early-config on top of the result.
> If Dscho is too busy to rebase and you are volunteering to help,
> perhaps the right way to help would be for you to do that rebasing,
> not rebase bw/config-h on top of js/alias-early-config, which is
> backwards and does not buy us very much.  Of course, we could make
> the result of such rebasing into a single topic, but even in that
> case, the order of changes feel backwards if bw/config-h comes
> later.
> 
> Anyway, I think I have to tend to many more patches before I can
> push out today's integration result, so ...
> 
> 

Yeah I see that the order is probably backwards.  I think I just heard
Dscho say "I'm too busy" and went along with just rebasing on top of his
series.  If you do end up feeling like this should be done differently
(like if another reroll is needed etc) then I wouldn't mind taking
ownership and making the order more sane.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v3 0/6] config.h
  2017-06-15 21:18           ` Brandon Williams
@ 2017-06-16  0:12             ` Brandon Williams
  0 siblings, 0 replies; 57+ messages in thread
From: Brandon Williams @ 2017-06-16  0:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, peff, jrnieder, Johannes.Schindelin

On 06/15, Brandon Williams wrote:
> On 06/15, Junio C Hamano wrote:
> > Brandon Williams <bmwill@google.com> writes:
> > 
> > > On 06/15, Junio C Hamano wrote:
> > >
> > >> ... so please eyeball the resulting 12 patches carefully when
> > >> they are pushed out.

I just took a look at what you pushed out and they look good to me.

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2017-06-16  0:12 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-12 21:34 [PATCH 0/4] config.h Brandon Williams
2017-06-12 21:34 ` [PATCH 1/4] config: create config.h Brandon Williams
2017-06-12 21:34 ` [PATCH 2/4] config: remove git_config_iter Brandon Williams
2017-06-13  0:49   ` Jonathan Nieder
2017-06-13  0:57     ` Jeff King
2017-06-12 21:34 ` [PATCH 3/4] config: don't include config.h by default Brandon Williams
2017-06-12 21:34 ` [PATCH 4/4] config: don't implicitly use gitdir Brandon Williams
2017-06-13  1:05   ` Jonathan Nieder
2017-06-13  1:23     ` Brandon Williams
2017-06-13  1:33       ` Jonathan Nieder
2017-06-13  1:38       ` Jonathan Nieder
2017-06-13  2:59         ` Jeff King
2017-06-13  6:16           ` Brandon Williams
2017-06-13  6:45             ` Jeff King
2017-06-13  7:08             ` Jeff King
2017-06-13 14:43               ` Brandon Williams
2017-06-13 17:06           ` Jonathan Nieder
2017-06-13  5:52         ` Brandon Williams
2017-06-13  6:29           ` Jeff King
2017-06-13 14:47             ` Brandon Williams
2017-06-12 21:45 ` [PATCH 0/4] config.h Jeff King
2017-06-12 21:53   ` Brandon Williams
2017-06-12 22:02     ` Jeff King
2017-06-12 22:06       ` Brandon Williams
2017-06-13  1:07 ` Jonathan Nieder
2017-06-13 21:03 ` [PATCH v2 0/6] config.h Brandon Williams
2017-06-13 21:03   ` [PATCH v2 1/6] config: create config.h Brandon Williams
2017-06-13 21:13     ` Jonathan Nieder
2017-06-13 21:03   ` [PATCH v2 2/6] config: remove git_config_iter Brandon Williams
2017-06-13 21:14     ` Jonathan Nieder
2017-06-13 21:03   ` [PATCH v2 3/6] config: don't include config.h by default Brandon Williams
2017-06-13 21:58     ` Jonathan Nieder
2017-06-13 21:03   ` [PATCH v2 4/6] config: don't implicitly use gitdir Brandon Williams
2017-06-13 21:08     ` Jonathan Nieder
2017-06-13 21:38       ` Brandon Williams
2017-06-13 21:51         ` Jonathan Nieder
2017-06-13 21:55           ` Junio C Hamano
2017-06-13 22:05             ` Jonathan Nieder
2017-06-14  4:40               ` Jacob Keller
2017-06-14  6:25         ` Jeff King
2017-06-14 17:14           ` Brandon Williams
2017-06-13 21:03   ` [PATCH v2 5/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
2017-06-14  6:15     ` Jeff King
2017-06-14 17:19       ` Brandon Williams
2017-06-13 21:03   ` [PATCH v2 6/6] config: respect commondir Brandon Williams
2017-06-14 18:07   ` [PATCH v3 0/6] config.h Brandon Williams
2017-06-14 18:07     ` [PATCH v3 1/6] config: create config.h Brandon Williams
2017-06-14 18:07     ` [PATCH v3 2/6] config: remove git_config_iter Brandon Williams
2017-06-14 18:07     ` [PATCH v3 3/6] config: don't include config.h by default Brandon Williams
2017-06-14 18:07     ` [PATCH v3 4/6] setup: teach discover_git_directory to respect the commondir Brandon Williams
2017-06-14 18:07     ` [PATCH v3 5/6] config: respect commondir Brandon Williams
2017-06-14 18:07     ` [PATCH v3 6/6] config: don't implicitly use gitdir or commondir Brandon Williams
2017-06-15 19:59     ` [PATCH v3 0/6] config.h Junio C Hamano
2017-06-15 20:33       ` Brandon Williams
2017-06-15 21:09         ` Junio C Hamano
2017-06-15 21:18           ` Brandon Williams
2017-06-16  0:12             ` Brandon Williams

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).