]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: move Git config parsing into "environment.c"
authorPatrick Steinhardt <ps@pks.im>
Wed, 23 Jul 2025 14:08:41 +0000 (16:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jul 2025 15:15:22 +0000 (08:15 -0700)
In "config.c" we host both the business logic to read and write config
files as well as the logic to parse specific Git-related variables. On
the one hand this is mixing concerns, but even more importantly it means
that we cannot easily remove the dependency on `the_repository` in our
config parsing logic.

Move the logic into "environment.c". This file is a grab bag of all
kinds of global state already, so it is quite a good fit. Furthermore,
it also hosts most of the global variables that we're parsing the config
values into, making this an even better fit.

Note that there is one hidden change: in `parse_fsync_components()` we
use an `int` to iterate through `ARRAY_SIZE(fsync_component_names)`. But
as -Wsign-compare warnings are enabled in this file this causes a
compiler warning. The issue is fixed by using a `size_t` instead.

This change allows us to drop the `USE_THE_REPOSITORY_VARIABLE`
declaration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
55 files changed:
builtin/add.c
builtin/check-ignore.c
builtin/check-mailmap.c
builtin/checkout--worker.c
builtin/checkout-index.c
builtin/clean.c
builtin/commit-graph.c
builtin/commit-tree.c
builtin/count-objects.c
builtin/credential.c
builtin/fast-export.c
builtin/for-each-ref.c
builtin/fsmonitor--daemon.c
builtin/grep.c
builtin/hash-object.c
builtin/help.c
builtin/hook.c
builtin/interpret-trailers.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge-base.c
builtin/merge-tree.c
builtin/multi-pack-index.c
builtin/pack-refs.c
builtin/patch-id.c
builtin/pull.c
builtin/read-tree.c
builtin/replace.c
builtin/rm.c
builtin/send-pack.c
builtin/show-ref.c
builtin/symbolic-ref.c
builtin/unpack-file.c
builtin/update-ref.c
builtin/update-server-info.c
builtin/var.c
builtin/verify-commit.c
builtin/verify-pack.c
builtin/verify-tag.c
builtin/write-tree.c
commit-graph.c
config.c
config.h
environment.c
environment.h
fsck.c
http-fetch.c
http.c
imap-send.c
mailinfo.c
reflog.c
rerere.c
t/helper/test-advise.c
t/helper/test-read-cache.c
xdiff-interface.c

index 7c292ffdc6c2c92e6c9a156d5ba713e07a629fac..88d1d330fa8fe60635cac91dae3bab5ec41fae65 100644 (file)
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
+#include "environment.h"
 #include "lockfile.h"
 #include "editor.h"
 #include "dir.h"
index 03033499cb083247dc17737386cca304e5134b23..644c9a414ffa1e6585aaafc2107378c3c5d0c38c 100644 (file)
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "quote.h"
 #include "pathspec.h"
index 634626c672848f052e1a0a42226236374580d32f..9cc5c598302657bf1dc61651d416629bca1e1704 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "ident.h"
 #include "mailmap.h"
index 27a7d4f0409893b21c9fdcde4002fe3e2b1ef708..e0772b718b27bf0a6063aa417d280ebbc31bd3f0 100644 (file)
@@ -4,6 +4,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "entry.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parallel-checkout.h"
 #include "parse-options.h"
index 7f74bc702fa73984d1a8c8a489ae4700a2151365..188128aebd9bc04d21cc309660012c99b97f6e1c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "lockfile.h"
 #include "quote.h"
index 5ee147c4acc05334c02c8e485ae0bfa31f0f31f1..a1977b92dc89dd227e2f7ff3c823a74bf931dbe9 100644 (file)
@@ -13,6 +13,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "path.h"
index c5cc601844cce54e72481d4da42440fddad7e746..4992ac146e14d1c15a63dfa8cde32368bd144672 100644 (file)
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "parse-options.h"
index 2f1df28d41394d072884f9eaa4efd9ae3feeaa8f..5189e685a7eccd5d6f7ec007f7b2db3c9b8d64dd 100644 (file)
@@ -6,6 +6,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
index 433daff805abf9d12b2038bfc401e2f227976117..b1148a68fa826fe362a0f29724758e54fcc6c19e 100644 (file)
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "path.h"
 #include "parse-options.h"
index 52f172e80cb4965ff070a7c5cff6342f7584f30f..a295c80b366b95aceef3ddb18fd254ab7601ad4c 100644 (file)
@@ -3,6 +3,7 @@
 #include "git-compat-util.h"
 #include "credential.h"
 #include "builtin.h"
+#include "environment.h"
 #include "config.h"
 
 static const char usage_msg[] =
index 17027b859e0caf1f38306d2793522e9d9610ab4b..66a3a98c9384fe1408d722f60c426a0dbd84266f 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
index 3d2207ec7733b2c0a77169de638fdc28e1b7f460..a8f7f8c7625623c0d069882a369f454cc0ed7fef 100644 (file)
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "commit.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object.h"
 #include "parse-options.h"
index 469c62b555bcde727ce204bc307b736983fd77d5..242c594646d1f5efc5022a936a636b2fe07ca36e 100644 (file)
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "dir.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "fsmonitor-ll.h"
index 8fcb69dbf2cba5670df58f58dffb279d6b9078d5..5df653733371d809d63c4be283c231de468b8ffd 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "builtin.h"
 #include "abspath.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "config.h"
index c3ad1e91c96fd98a4e8ed2c8eecb5d4efb57a28b..5d900a6b8c953ecc6451aaeaa67fd223ddd5e3c4 100644 (file)
@@ -8,6 +8,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-file.h"
index d79ecd946a640cd8513cf0f8dc4f27007aa688bc..c09cbc8912deb69acf25a748684c639cbec1955e 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "exec-cmd.h"
 #include "gettext.h"
 #include "pager.h"
index 044c27aa95dba6809bc59169efcabe6722bc3a63..7afec380d2e579d0b704434144aaf21bdfcb030c 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hook.h"
 #include "parse-options.h"
index 3141c37b853ff06065f6b530ff962c9f87f06bd5..41b0750e5af32431b5ab125e743e48b68c39f993 100644 (file)
@@ -6,6 +6,7 @@
  */
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "string-list.h"
index ff975e7be06045bd7412b3a306cfe8bd38c137bc..c06a6f33e41c56cd0d4e465bccb0f091a9a4d8a2 100644 (file)
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "convert.h"
+#include "environment.h"
 #include "quote.h"
 #include "dir.h"
 #include "gettext.h"
index 4ba84e519672d329b3834a7f6007c939236d432d..5d55731ca35b7aa00f614132c0af6328978a3e93 100644 (file)
@@ -7,6 +7,7 @@
 #include "builtin.h"
 
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
index 8fde35c1751ee1e04c809a08891231a1fc23a1d8..3f82781245bd27d33e7c9bd3f4b40ba1d764eb07 100644 (file)
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "commit.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "object-name.h"
index 99a6495fd52f79e494cd2c853b1798c5d444342b..203f0e6456a751448f81efb59bf4e67ce2cb2425 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
+#include "environment.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
 #include "help.h"
index 9a113f0f1f33ceb819bd6eda8eb3980d9f9ac086..d3b9e98be37424b02d7bfc6c1b456fe765a227ce 100644 (file)
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "midx.h"
index e47bae1c803bc81e28910a30213a27dbbdef6a10..5e28d0f9e80996e619be68ea6c7a0831401ed9c9 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "refs.h"
index a659f00531a0f45a133a85f5c07a6676415b7812..d26e9d0c1eae6a195919e009ad93d3bebb6e383b 100644 (file)
@@ -3,6 +3,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
index 5ea51c31f5878b40d886afe0c7a8d4f200adfc97..e6d3535c3b59d57c1ecec4141892df72a6f0c8a1 100644 (file)
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "merge.h"
index 00eef756e67b0c853eb14771d698ed28ed2fc655..34f7a59f38ee22b8aca68c432109b18da54168ab 100644 (file)
@@ -6,6 +6,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
index 3fe39e9df731dff4c166fc431bed853666a4d73a..19897ef927fea8dfe34969dd561602df39decd8f 100644 (file)
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "editor.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
index 8c0da7a3ce7a66bfc37213513131b60931ad0faa..05d89e98c3c6b80d8542ecfaefe51859cb072334 100644 (file)
@@ -9,6 +9,7 @@
 #include "builtin.h"
 #include "advice.h"
 #include "config.h"
+#include "environment.h"
 #include "lockfile.h"
 #include "dir.h"
 #include "gettext.h"
index 28b69d26b483d2279a7d9c009651306c91822acf..8b81c8a84863eb0b0bb20a9fdcecffd5dada5c6c 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "pkt-line.h"
 #include "run-command.h"
index 414e55b92d5fef50d0fc7648cb3c4a0ec2c667ea..0b6f9edf86c24f0198163abc4140e0e8dae71279 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs/refs-internal.h"
index 5c4623067c53729db325ce1ee7f1be2a15696239..231e41e715b95aff0f532ccde54c28e7075851f9 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "refs.h"
 #include "parse-options.h"
index ae871adc909074bc4f16f71bbc7704a65a937ea4..87877a9fabc6f614e2e1d57afaea8759d8a191df 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "hex.h"
 #include "object-file.h"
 #include "object-name.h"
index cb9366432430883b06d21c9973c5d847bc6a0f15..195437e7c656ff526a3309f1768871b9dce9fc05 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hash.h"
 #include "hex.h"
index ba702d30efdc17d51454d9e5c77979b30edabbc1..4c12968a8360f235962cd778ec28d0ff9435db74 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "server-info.h"
index beeac12dccf3eaade85d906cdc9295738f3be852..a2d790d45320ae7c4ef61c64ad73b2104bde77fc 100644 (file)
@@ -11,6 +11,7 @@
 #include "attr.h"
 #include "config.h"
 #include "editor.h"
+#include "environment.h"
 #include "ident.h"
 #include "pager.h"
 #include "refs.h"
index 5f749a30daf0155514f54de628a217b09ea0cf91..62398acd72106080852d4deb5dffa30d7bc5a98d 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "object-name.h"
 #include "commit.h"
index d9f66f5e76777658029eb92f32612828d3d14b48..65fd6629a0079dde4d317f8b5f3b113efcd1b364 100644 (file)
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
index ed1c40338fd88ca59e4553c3a656542a9be9c880..cd6bc11095d01aa03f15f00ac962d563bd690e32 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "tag.h"
 #include "object-name.h"
index 3465c70a48a7ebf8119ae0a5947fc577dcd6b9c5..e3bd1a40dbf3892451755a10943b401e2fb5edcb 100644 (file)
@@ -6,6 +6,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "tree.h"
index bd7b6f5338bd9dbef1694292a4171b82d9ecac18..e0d92b816f5938d7a69376795ef74da709c0f799 100644 (file)
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "csum-file.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
index 285cab0ce2a6a241eda779d83e513b81e670031c..947fba3d8d440492a397448316de381a73da8e7d 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,12 +6,10 @@
  *
  */
 
-#define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
 #include "abspath.h"
-#include "advice.h"
 #include "date.h"
 #include "branch.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
 #include "git-zlib.h"
-#include "ident.h"
 #include "repository.h"
 #include "lockfile.h"
-#include "mailmap.h"
-#include "attr.h"
 #include "exec-cmd.h"
 #include "strbuf.h"
 #include "quote.h"
@@ -32,7 +27,6 @@
 #include "string-list.h"
 #include "object-name.h"
 #include "odb.h"
-#include "pager.h"
 #include "path.h"
 #include "utf8.h"
 #include "color.h"
@@ -41,7 +35,6 @@
 #include "strvec.h"
 #include "trace2.h"
 #include "wildmatch.h"
-#include "ws.h"
 #include "write-or-die.h"
 
 struct config_source {
@@ -71,9 +64,6 @@ struct config_source {
 };
 #define CONFIG_SOURCE_INIT { 0 }
 
-static int pack_compression_seen;
-static int zlib_compression_seen;
-
 /*
  * Config that comes from trusted scopes, namely:
  * - CONFIG_SCOPE_SYSTEM (e.g. /etc/gitconfig)
@@ -1262,80 +1252,6 @@ double git_config_double(const char *name, const char *value,
        return ret;
 }
 
-static const struct fsync_component_name {
-       const char *name;
-       enum fsync_component component_bits;
-} fsync_component_names[] = {
-       { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT },
-       { "pack", FSYNC_COMPONENT_PACK },
-       { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA },
-       { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
-       { "index", FSYNC_COMPONENT_INDEX },
-       { "objects", FSYNC_COMPONENTS_OBJECTS },
-       { "reference", FSYNC_COMPONENT_REFERENCE },
-       { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA },
-       { "committed", FSYNC_COMPONENTS_COMMITTED },
-       { "added", FSYNC_COMPONENTS_ADDED },
-       { "all", FSYNC_COMPONENTS_ALL },
-};
-
-static enum fsync_component parse_fsync_components(const char *var, const char *string)
-{
-       enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT;
-       enum fsync_component positive = 0, negative = 0;
-
-       while (string) {
-               int i;
-               size_t len;
-               const char *ep;
-               int negated = 0;
-               int found = 0;
-
-               string = string + strspn(string, ", \t\n\r");
-               ep = strchrnul(string, ',');
-               len = ep - string;
-               if (!strcmp(string, "none")) {
-                       current = FSYNC_COMPONENT_NONE;
-                       goto next_name;
-               }
-
-               if (*string == '-') {
-                       negated = 1;
-                       string++;
-                       len--;
-                       if (!len)
-                               warning(_("invalid value for variable %s"), var);
-               }
-
-               if (!len)
-                       break;
-
-               for (i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) {
-                       const struct fsync_component_name *n = &fsync_component_names[i];
-
-                       if (strncmp(n->name, string, len))
-                               continue;
-
-                       found = 1;
-                       if (negated)
-                               negative |= n->component_bits;
-                       else
-                               positive |= n->component_bits;
-               }
-
-               if (!found) {
-                       char *component = xstrndup(string, len);
-                       warning(_("ignoring unknown core.fsync component '%s'"), component);
-                       free(component);
-               }
-
-next_name:
-               string = ep;
-       }
-
-       return (current & ~negative) | positive;
-}
-
 int git_config_bool_or_int(const char *name, const char *value,
                           const struct key_value_info *kvi, int *is_bool)
 {
@@ -1393,433 +1309,6 @@ int git_config_color(char *dest, const char *var, const char *value)
        return 0;
 }
 
-static int git_default_core_config(const char *var, const char *value,
-                                  const struct config_context *ctx, void *cb)
-{
-       /* This needs a better name */
-       if (!strcmp(var, "core.filemode")) {
-               trust_executable_bit = git_config_bool(var, value);
-               return 0;
-       }
-       if (!strcmp(var, "core.trustctime")) {
-               trust_ctime = git_config_bool(var, value);
-               return 0;
-       }
-       if (!strcmp(var, "core.checkstat")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               if (!strcasecmp(value, "default"))
-                       check_stat = 1;
-               else if (!strcasecmp(value, "minimal"))
-                       check_stat = 0;
-               else
-                       return error(_("invalid value for '%s': '%s'"),
-                                    var, value);
-       }
-
-       if (!strcmp(var, "core.quotepath")) {
-               quote_path_fully = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.symlinks")) {
-               has_symlinks = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.ignorecase")) {
-               ignore_case = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.attributesfile")) {
-               FREE_AND_NULL(git_attributes_file);
-               return git_config_pathname(&git_attributes_file, var, value);
-       }
-
-       if (!strcmp(var, "core.bare")) {
-               is_bare_repository_cfg = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.ignorestat")) {
-               assume_unchanged = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.abbrev")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               if (!strcasecmp(value, "auto"))
-                       default_abbrev = -1;
-               else if (!git_parse_maybe_bool_text(value))
-                       default_abbrev = GIT_MAX_HEXSZ;
-               else {
-                       int abbrev = git_config_int(var, value, ctx->kvi);
-                       if (abbrev < minimum_abbrev)
-                               return error(_("abbrev length out of range: %d"), abbrev);
-                       default_abbrev = abbrev;
-               }
-               return 0;
-       }
-
-       if (!strcmp(var, "core.disambiguate"))
-               return set_disambiguate_hint_config(var, value);
-
-       if (!strcmp(var, "core.loosecompression")) {
-               int level = git_config_int(var, value, ctx->kvi);
-               if (level == -1)
-                       level = Z_DEFAULT_COMPRESSION;
-               else if (level < 0 || level > Z_BEST_COMPRESSION)
-                       die(_("bad zlib compression level %d"), level);
-               zlib_compression_level = level;
-               zlib_compression_seen = 1;
-               return 0;
-       }
-
-       if (!strcmp(var, "core.compression")) {
-               int level = git_config_int(var, value, ctx->kvi);
-               if (level == -1)
-                       level = Z_DEFAULT_COMPRESSION;
-               else if (level < 0 || level > Z_BEST_COMPRESSION)
-                       die(_("bad zlib compression level %d"), level);
-               if (!zlib_compression_seen)
-                       zlib_compression_level = level;
-               if (!pack_compression_seen)
-                       pack_compression_level = level;
-               return 0;
-       }
-
-       if (!strcmp(var, "core.autocrlf")) {
-               if (value && !strcasecmp(value, "input")) {
-                       auto_crlf = AUTO_CRLF_INPUT;
-                       return 0;
-               }
-               auto_crlf = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.safecrlf")) {
-               int eol_rndtrp_die;
-               if (value && !strcasecmp(value, "warn")) {
-                       global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
-                       return 0;
-               }
-               eol_rndtrp_die = git_config_bool(var, value);
-               global_conv_flags_eol = eol_rndtrp_die ?
-                       CONV_EOL_RNDTRP_DIE : 0;
-               return 0;
-       }
-
-       if (!strcmp(var, "core.eol")) {
-               if (value && !strcasecmp(value, "lf"))
-                       core_eol = EOL_LF;
-               else if (value && !strcasecmp(value, "crlf"))
-                       core_eol = EOL_CRLF;
-               else if (value && !strcasecmp(value, "native"))
-                       core_eol = EOL_NATIVE;
-               else
-                       core_eol = EOL_UNSET;
-               return 0;
-       }
-
-       if (!strcmp(var, "core.checkroundtripencoding")) {
-               FREE_AND_NULL(check_roundtrip_encoding);
-               return git_config_string(&check_roundtrip_encoding, var, value);
-       }
-
-       if (!strcmp(var, "core.editor")) {
-               FREE_AND_NULL(editor_program);
-               return git_config_string(&editor_program, var, value);
-       }
-
-       if (!strcmp(var, "core.commentchar") ||
-           !strcmp(var, "core.commentstring")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               else if (!strcasecmp(value, "auto"))
-                       auto_comment_line_char = 1;
-               else if (value[0]) {
-                       if (strchr(value, '\n'))
-                               return error(_("%s cannot contain newline"), var);
-                       comment_line_str = value;
-                       FREE_AND_NULL(comment_line_str_to_free);
-                       auto_comment_line_char = 0;
-               } else
-                       return error(_("%s must have at least one character"), var);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.askpass")) {
-               FREE_AND_NULL(askpass_program);
-               return git_config_string(&askpass_program, var, value);
-       }
-
-       if (!strcmp(var, "core.excludesfile")) {
-               FREE_AND_NULL(excludes_file);
-               return git_config_pathname(&excludes_file, var, value);
-       }
-
-       if (!strcmp(var, "core.whitespace")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               whitespace_rule_cfg = parse_whitespace_rule(value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.fsync")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               fsync_components = parse_fsync_components(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.fsyncmethod")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               if (!strcmp(value, "fsync"))
-                       fsync_method = FSYNC_METHOD_FSYNC;
-               else if (!strcmp(value, "writeout-only"))
-                       fsync_method = FSYNC_METHOD_WRITEOUT_ONLY;
-               else if (!strcmp(value, "batch"))
-                       fsync_method = FSYNC_METHOD_BATCH;
-               else
-                       warning(_("ignoring unknown core.fsyncMethod value '%s'"), value);
-
-       }
-
-       if (!strcmp(var, "core.fsyncobjectfiles")) {
-               if (fsync_object_files < 0)
-                       warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead"));
-               fsync_object_files = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.createobject")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               if (!strcmp(value, "rename"))
-                       object_creation_mode = OBJECT_CREATION_USES_RENAMES;
-               else if (!strcmp(value, "link"))
-                       object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
-               else
-                       die(_("invalid mode for object creation: %s"), value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.sparsecheckout")) {
-               core_apply_sparse_checkout = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.sparsecheckoutcone")) {
-               core_sparse_checkout_cone = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.precomposeunicode")) {
-               precomposed_unicode = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.protecthfs")) {
-               protect_hfs = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.protectntfs")) {
-               protect_ntfs = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "core.maxtreedepth")) {
-               max_allowed_tree_depth = git_config_int(var, value, ctx->kvi);
-               return 0;
-       }
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return platform_core_config(var, value, ctx, cb);
-}
-
-static int git_default_sparse_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
-               sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
-               return 0;
-       }
-
-       /* Add other config variables here and to Documentation/config/sparse.adoc. */
-       return 0;
-}
-
-static int git_default_i18n_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "i18n.commitencoding")) {
-               FREE_AND_NULL(git_commit_encoding);
-               return git_config_string(&git_commit_encoding, var, value);
-       }
-
-       if (!strcmp(var, "i18n.logoutputencoding")) {
-               FREE_AND_NULL(git_log_output_encoding);
-               return git_config_string(&git_log_output_encoding, var, value);
-       }
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return 0;
-}
-
-static int git_default_branch_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "branch.autosetupmerge")) {
-               if (value && !strcmp(value, "always")) {
-                       git_branch_track = BRANCH_TRACK_ALWAYS;
-                       return 0;
-               } else if (value && !strcmp(value, "inherit")) {
-                       git_branch_track = BRANCH_TRACK_INHERIT;
-                       return 0;
-               } else if (value && !strcmp(value, "simple")) {
-                       git_branch_track = BRANCH_TRACK_SIMPLE;
-                       return 0;
-               }
-               git_branch_track = git_config_bool(var, value);
-               return 0;
-       }
-       if (!strcmp(var, "branch.autosetuprebase")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               else if (!strcmp(value, "never"))
-                       autorebase = AUTOREBASE_NEVER;
-               else if (!strcmp(value, "local"))
-                       autorebase = AUTOREBASE_LOCAL;
-               else if (!strcmp(value, "remote"))
-                       autorebase = AUTOREBASE_REMOTE;
-               else if (!strcmp(value, "always"))
-                       autorebase = AUTOREBASE_ALWAYS;
-               else
-                       return error(_("malformed value for %s"), var);
-               return 0;
-       }
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return 0;
-}
-
-static int git_default_push_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "push.default")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               else if (!strcmp(value, "nothing"))
-                       push_default = PUSH_DEFAULT_NOTHING;
-               else if (!strcmp(value, "matching"))
-                       push_default = PUSH_DEFAULT_MATCHING;
-               else if (!strcmp(value, "simple"))
-                       push_default = PUSH_DEFAULT_SIMPLE;
-               else if (!strcmp(value, "upstream"))
-                       push_default = PUSH_DEFAULT_UPSTREAM;
-               else if (!strcmp(value, "tracking")) /* deprecated */
-                       push_default = PUSH_DEFAULT_UPSTREAM;
-               else if (!strcmp(value, "current"))
-                       push_default = PUSH_DEFAULT_CURRENT;
-               else {
-                       error(_("malformed value for %s: %s"), var, value);
-                       return error(_("must be one of nothing, matching, simple, "
-                                      "upstream or current"));
-               }
-               return 0;
-       }
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return 0;
-}
-
-static int git_default_mailmap_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "mailmap.file")) {
-               FREE_AND_NULL(git_mailmap_file);
-               return git_config_pathname(&git_mailmap_file, var, value);
-       }
-
-       if (!strcmp(var, "mailmap.blob")) {
-               FREE_AND_NULL(git_mailmap_blob);
-               return git_config_string(&git_mailmap_blob, var, value);
-       }
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return 0;
-}
-
-static int git_default_attr_config(const char *var, const char *value)
-{
-       if (!strcmp(var, "attr.tree")) {
-               FREE_AND_NULL(git_attr_tree);
-               return git_config_string(&git_attr_tree, var, value);
-       }
-
-       /*
-        * Add other attribute related config variables here and to
-        * Documentation/config/attr.adoc.
-        */
-       return 0;
-}
-
-int git_default_config(const char *var, const char *value,
-                      const struct config_context *ctx, void *cb)
-{
-       if (starts_with(var, "core."))
-               return git_default_core_config(var, value, ctx, cb);
-
-       if (starts_with(var, "user.") ||
-           starts_with(var, "author.") ||
-           starts_with(var, "committer."))
-               return git_ident_config(var, value, ctx, cb);
-
-       if (starts_with(var, "i18n."))
-               return git_default_i18n_config(var, value);
-
-       if (starts_with(var, "branch."))
-               return git_default_branch_config(var, value);
-
-       if (starts_with(var, "push."))
-               return git_default_push_config(var, value);
-
-       if (starts_with(var, "mailmap."))
-               return git_default_mailmap_config(var, value);
-
-       if (starts_with(var, "attr."))
-               return git_default_attr_config(var, value);
-
-       if (starts_with(var, "advice.") || starts_with(var, "color.advice"))
-               return git_default_advice_config(var, value);
-
-       if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
-               pager_use_color = git_config_bool(var,value);
-               return 0;
-       }
-
-       if (!strcmp(var, "pack.packsizelimit")) {
-               pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
-               return 0;
-       }
-
-       if (!strcmp(var, "pack.compression")) {
-               int level = git_config_int(var, value, ctx->kvi);
-               if (level == -1)
-                       level = Z_DEFAULT_COMPRESSION;
-               else if (level < 0 || level > Z_BEST_COMPRESSION)
-                       die(_("bad pack compression level %d"), level);
-               pack_compression_level = level;
-               pack_compression_seen = 1;
-               return 0;
-       }
-
-       if (starts_with(var, "sparse."))
-               return git_default_sparse_config(var, value);
-
-       /* Add other config variables here and to Documentation/config.adoc. */
-       return 0;
-}
-
 /*
  * All source specific fields in the union, die_on_error, name and the callbacks
  * fgetc, ungetc, ftell of top need to be initialized before calling
index 87baf8eeffe0a1892997b3de61f6c02c932d4e33..65fc47966e6b52380fe1008c9e3427776e8207f2 100644 (file)
--- a/config.h
+++ b/config.h
@@ -165,9 +165,6 @@ struct config_context {
 typedef int (*config_fn_t)(const char *, const char *,
                           const struct config_context *, void *);
 
-int git_default_config(const char *, const char *,
-                      const struct config_context *, void *);
-
 /**
  * Read a specific file in git-config format.
  * This function takes the same callback and data parameters as `repo_config`.
index 7c2480b22e599192adc822b012e45a51b3578453..ae1427bb9e8e6243051159dcfc28a94febe024e3 100644 (file)
 
 #include "git-compat-util.h"
 #include "abspath.h"
+#include "advice.h"
+#include "attr.h"
 #include "branch.h"
+#include "color.h"
 #include "convert.h"
 #include "environment.h"
 #include "gettext.h"
 #include "git-zlib.h"
+#include "ident.h"
+#include "mailmap.h"
+#include "object-name.h"
 #include "repository.h"
 #include "config.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
 #include "commit.h"
 #include "strvec.h"
+#include "pager.h"
 #include "path.h"
+#include "quote.h"
 #include "chdir-notify.h"
 #include "setup.h"
+#include "ws.h"
 #include "write-or-die.h"
 
+static int pack_compression_seen;
+static int zlib_compression_seen;
+
 int trust_executable_bit = 1;
 int trust_ctime = 1;
 int check_stat = 1;
@@ -231,3 +243,503 @@ int print_sha1_ellipsis(void)
        }
        return cached_result;
 }
+
+static const struct fsync_component_name {
+       const char *name;
+       enum fsync_component component_bits;
+} fsync_component_names[] = {
+       { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT },
+       { "pack", FSYNC_COMPONENT_PACK },
+       { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA },
+       { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
+       { "index", FSYNC_COMPONENT_INDEX },
+       { "objects", FSYNC_COMPONENTS_OBJECTS },
+       { "reference", FSYNC_COMPONENT_REFERENCE },
+       { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA },
+       { "committed", FSYNC_COMPONENTS_COMMITTED },
+       { "added", FSYNC_COMPONENTS_ADDED },
+       { "all", FSYNC_COMPONENTS_ALL },
+};
+
+static enum fsync_component parse_fsync_components(const char *var, const char *string)
+{
+       enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT;
+       enum fsync_component positive = 0, negative = 0;
+
+       while (string) {
+               size_t len;
+               const char *ep;
+               int negated = 0;
+               int found = 0;
+
+               string = string + strspn(string, ", \t\n\r");
+               ep = strchrnul(string, ',');
+               len = ep - string;
+               if (!strcmp(string, "none")) {
+                       current = FSYNC_COMPONENT_NONE;
+                       goto next_name;
+               }
+
+               if (*string == '-') {
+                       negated = 1;
+                       string++;
+                       len--;
+                       if (!len)
+                               warning(_("invalid value for variable %s"), var);
+               }
+
+               if (!len)
+                       break;
+
+               for (size_t i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) {
+                       const struct fsync_component_name *n = &fsync_component_names[i];
+
+                       if (strncmp(n->name, string, len))
+                               continue;
+
+                       found = 1;
+                       if (negated)
+                               negative |= n->component_bits;
+                       else
+                               positive |= n->component_bits;
+               }
+
+               if (!found) {
+                       char *component = xstrndup(string, len);
+                       warning(_("ignoring unknown core.fsync component '%s'"), component);
+                       free(component);
+               }
+
+next_name:
+               string = ep;
+       }
+
+       return (current & ~negative) | positive;
+}
+
+static int git_default_core_config(const char *var, const char *value,
+                                  const struct config_context *ctx, void *cb)
+{
+       /* This needs a better name */
+       if (!strcmp(var, "core.filemode")) {
+               trust_executable_bit = git_config_bool(var, value);
+               return 0;
+       }
+       if (!strcmp(var, "core.trustctime")) {
+               trust_ctime = git_config_bool(var, value);
+               return 0;
+       }
+       if (!strcmp(var, "core.checkstat")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcasecmp(value, "default"))
+                       check_stat = 1;
+               else if (!strcasecmp(value, "minimal"))
+                       check_stat = 0;
+               else
+                       return error(_("invalid value for '%s': '%s'"),
+                                    var, value);
+       }
+
+       if (!strcmp(var, "core.quotepath")) {
+               quote_path_fully = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.symlinks")) {
+               has_symlinks = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.ignorecase")) {
+               ignore_case = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.attributesfile")) {
+               FREE_AND_NULL(git_attributes_file);
+               return git_config_pathname(&git_attributes_file, var, value);
+       }
+
+       if (!strcmp(var, "core.bare")) {
+               is_bare_repository_cfg = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.ignorestat")) {
+               assume_unchanged = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.abbrev")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcasecmp(value, "auto"))
+                       default_abbrev = -1;
+               else if (!git_parse_maybe_bool_text(value))
+                       default_abbrev = GIT_MAX_HEXSZ;
+               else {
+                       int abbrev = git_config_int(var, value, ctx->kvi);
+                       if (abbrev < minimum_abbrev)
+                               return error(_("abbrev length out of range: %d"), abbrev);
+                       default_abbrev = abbrev;
+               }
+               return 0;
+       }
+
+       if (!strcmp(var, "core.disambiguate"))
+               return set_disambiguate_hint_config(var, value);
+
+       if (!strcmp(var, "core.loosecompression")) {
+               int level = git_config_int(var, value, ctx->kvi);
+               if (level == -1)
+                       level = Z_DEFAULT_COMPRESSION;
+               else if (level < 0 || level > Z_BEST_COMPRESSION)
+                       die(_("bad zlib compression level %d"), level);
+               zlib_compression_level = level;
+               zlib_compression_seen = 1;
+               return 0;
+       }
+
+       if (!strcmp(var, "core.compression")) {
+               int level = git_config_int(var, value, ctx->kvi);
+               if (level == -1)
+                       level = Z_DEFAULT_COMPRESSION;
+               else if (level < 0 || level > Z_BEST_COMPRESSION)
+                       die(_("bad zlib compression level %d"), level);
+               if (!zlib_compression_seen)
+                       zlib_compression_level = level;
+               if (!pack_compression_seen)
+                       pack_compression_level = level;
+               return 0;
+       }
+
+       if (!strcmp(var, "core.autocrlf")) {
+               if (value && !strcasecmp(value, "input")) {
+                       auto_crlf = AUTO_CRLF_INPUT;
+                       return 0;
+               }
+               auto_crlf = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.safecrlf")) {
+               int eol_rndtrp_die;
+               if (value && !strcasecmp(value, "warn")) {
+                       global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
+                       return 0;
+               }
+               eol_rndtrp_die = git_config_bool(var, value);
+               global_conv_flags_eol = eol_rndtrp_die ?
+                       CONV_EOL_RNDTRP_DIE : 0;
+               return 0;
+       }
+
+       if (!strcmp(var, "core.eol")) {
+               if (value && !strcasecmp(value, "lf"))
+                       core_eol = EOL_LF;
+               else if (value && !strcasecmp(value, "crlf"))
+                       core_eol = EOL_CRLF;
+               else if (value && !strcasecmp(value, "native"))
+                       core_eol = EOL_NATIVE;
+               else
+                       core_eol = EOL_UNSET;
+               return 0;
+       }
+
+       if (!strcmp(var, "core.checkroundtripencoding")) {
+               FREE_AND_NULL(check_roundtrip_encoding);
+               return git_config_string(&check_roundtrip_encoding, var, value);
+       }
+
+       if (!strcmp(var, "core.editor")) {
+               FREE_AND_NULL(editor_program);
+               return git_config_string(&editor_program, var, value);
+       }
+
+       if (!strcmp(var, "core.commentchar") ||
+           !strcmp(var, "core.commentstring")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               else if (!strcasecmp(value, "auto"))
+                       auto_comment_line_char = 1;
+               else if (value[0]) {
+                       if (strchr(value, '\n'))
+                               return error(_("%s cannot contain newline"), var);
+                       comment_line_str = value;
+                       FREE_AND_NULL(comment_line_str_to_free);
+                       auto_comment_line_char = 0;
+               } else
+                       return error(_("%s must have at least one character"), var);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.askpass")) {
+               FREE_AND_NULL(askpass_program);
+               return git_config_string(&askpass_program, var, value);
+       }
+
+       if (!strcmp(var, "core.excludesfile")) {
+               FREE_AND_NULL(excludes_file);
+               return git_config_pathname(&excludes_file, var, value);
+       }
+
+       if (!strcmp(var, "core.whitespace")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               whitespace_rule_cfg = parse_whitespace_rule(value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.fsync")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               fsync_components = parse_fsync_components(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.fsyncmethod")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcmp(value, "fsync"))
+                       fsync_method = FSYNC_METHOD_FSYNC;
+               else if (!strcmp(value, "writeout-only"))
+                       fsync_method = FSYNC_METHOD_WRITEOUT_ONLY;
+               else if (!strcmp(value, "batch"))
+                       fsync_method = FSYNC_METHOD_BATCH;
+               else
+                       warning(_("ignoring unknown core.fsyncMethod value '%s'"), value);
+
+       }
+
+       if (!strcmp(var, "core.fsyncobjectfiles")) {
+               if (fsync_object_files < 0)
+                       warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead"));
+               fsync_object_files = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.createobject")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcmp(value, "rename"))
+                       object_creation_mode = OBJECT_CREATION_USES_RENAMES;
+               else if (!strcmp(value, "link"))
+                       object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
+               else
+                       die(_("invalid mode for object creation: %s"), value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.sparsecheckout")) {
+               core_apply_sparse_checkout = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.sparsecheckoutcone")) {
+               core_sparse_checkout_cone = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.precomposeunicode")) {
+               precomposed_unicode = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.protecthfs")) {
+               protect_hfs = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.protectntfs")) {
+               protect_ntfs = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.maxtreedepth")) {
+               max_allowed_tree_depth = git_config_int(var, value, ctx->kvi);
+               return 0;
+       }
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return platform_core_config(var, value, ctx, cb);
+}
+
+static int git_default_sparse_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
+               sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
+               return 0;
+       }
+
+       /* Add other config variables here and to Documentation/config/sparse.adoc. */
+       return 0;
+}
+
+static int git_default_i18n_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "i18n.commitencoding")) {
+               FREE_AND_NULL(git_commit_encoding);
+               return git_config_string(&git_commit_encoding, var, value);
+       }
+
+       if (!strcmp(var, "i18n.logoutputencoding")) {
+               FREE_AND_NULL(git_log_output_encoding);
+               return git_config_string(&git_log_output_encoding, var, value);
+       }
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return 0;
+}
+
+static int git_default_branch_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "branch.autosetupmerge")) {
+               if (value && !strcmp(value, "always")) {
+                       git_branch_track = BRANCH_TRACK_ALWAYS;
+                       return 0;
+               } else if (value && !strcmp(value, "inherit")) {
+                       git_branch_track = BRANCH_TRACK_INHERIT;
+                       return 0;
+               } else if (value && !strcmp(value, "simple")) {
+                       git_branch_track = BRANCH_TRACK_SIMPLE;
+                       return 0;
+               }
+               git_branch_track = git_config_bool(var, value);
+               return 0;
+       }
+       if (!strcmp(var, "branch.autosetuprebase")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               else if (!strcmp(value, "never"))
+                       autorebase = AUTOREBASE_NEVER;
+               else if (!strcmp(value, "local"))
+                       autorebase = AUTOREBASE_LOCAL;
+               else if (!strcmp(value, "remote"))
+                       autorebase = AUTOREBASE_REMOTE;
+               else if (!strcmp(value, "always"))
+                       autorebase = AUTOREBASE_ALWAYS;
+               else
+                       return error(_("malformed value for %s"), var);
+               return 0;
+       }
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return 0;
+}
+
+static int git_default_push_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "push.default")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               else if (!strcmp(value, "nothing"))
+                       push_default = PUSH_DEFAULT_NOTHING;
+               else if (!strcmp(value, "matching"))
+                       push_default = PUSH_DEFAULT_MATCHING;
+               else if (!strcmp(value, "simple"))
+                       push_default = PUSH_DEFAULT_SIMPLE;
+               else if (!strcmp(value, "upstream"))
+                       push_default = PUSH_DEFAULT_UPSTREAM;
+               else if (!strcmp(value, "tracking")) /* deprecated */
+                       push_default = PUSH_DEFAULT_UPSTREAM;
+               else if (!strcmp(value, "current"))
+                       push_default = PUSH_DEFAULT_CURRENT;
+               else {
+                       error(_("malformed value for %s: %s"), var, value);
+                       return error(_("must be one of nothing, matching, simple, "
+                                      "upstream or current"));
+               }
+               return 0;
+       }
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return 0;
+}
+
+static int git_default_mailmap_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "mailmap.file")) {
+               FREE_AND_NULL(git_mailmap_file);
+               return git_config_pathname(&git_mailmap_file, var, value);
+       }
+
+       if (!strcmp(var, "mailmap.blob")) {
+               FREE_AND_NULL(git_mailmap_blob);
+               return git_config_string(&git_mailmap_blob, var, value);
+       }
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return 0;
+}
+
+static int git_default_attr_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "attr.tree")) {
+               FREE_AND_NULL(git_attr_tree);
+               return git_config_string(&git_attr_tree, var, value);
+       }
+
+       /*
+        * Add other attribute related config variables here and to
+        * Documentation/config/attr.adoc.
+        */
+       return 0;
+}
+
+int git_default_config(const char *var, const char *value,
+                      const struct config_context *ctx, void *cb)
+{
+       if (starts_with(var, "core."))
+               return git_default_core_config(var, value, ctx, cb);
+
+       if (starts_with(var, "user.") ||
+           starts_with(var, "author.") ||
+           starts_with(var, "committer."))
+               return git_ident_config(var, value, ctx, cb);
+
+       if (starts_with(var, "i18n."))
+               return git_default_i18n_config(var, value);
+
+       if (starts_with(var, "branch."))
+               return git_default_branch_config(var, value);
+
+       if (starts_with(var, "push."))
+               return git_default_push_config(var, value);
+
+       if (starts_with(var, "mailmap."))
+               return git_default_mailmap_config(var, value);
+
+       if (starts_with(var, "attr."))
+               return git_default_attr_config(var, value);
+
+       if (starts_with(var, "advice.") || starts_with(var, "color.advice"))
+               return git_default_advice_config(var, value);
+
+       if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
+               pager_use_color = git_config_bool(var,value);
+               return 0;
+       }
+
+       if (!strcmp(var, "pack.packsizelimit")) {
+               pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
+               return 0;
+       }
+
+       if (!strcmp(var, "pack.compression")) {
+               int level = git_config_int(var, value, ctx->kvi);
+               if (level == -1)
+                       level = Z_DEFAULT_COMPRESSION;
+               else if (level < 0 || level > Z_BEST_COMPRESSION)
+                       die(_("bad pack compression level %d"), level);
+               pack_compression_level = level;
+               pack_compression_seen = 1;
+               return 0;
+       }
+
+       if (starts_with(var, "sparse."))
+               return git_default_sparse_config(var, value);
+
+       /* Add other config variables here and to Documentation/config.adoc. */
+       return 0;
+}
index 3d806ced6e45524f884aa291930b738955115227..8cfce41015b3c8ec32686fde91224b62ab3853cb 100644 (file)
@@ -104,6 +104,9 @@ int use_optional_locks(void);
 const char *get_git_namespace(void);
 const char *strip_namespace(const char *namespaced_ref);
 
+int git_default_config(const char *, const char *,
+                      const struct config_context *, void *);
+
 /*
  * TODO: All the below state either explicitly or implicitly relies on
  * `the_repository`. We should eventually get rid of these and make the
diff --git a/fsck.c b/fsck.c
index 23965e1880fedead833a14e2b1db3197be494f85..171b424dd57de12093a88d2b10d122639dbb0a43 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -3,6 +3,7 @@
 #include "git-compat-util.h"
 #include "date.h"
 #include "dir.h"
+#include "environment.h"
 #include "hex.h"
 #include "odb.h"
 #include "path.h"
index 17b9fe4ff8c7a27365a8ce38af0e158b3d1f4717..1922e23fcd3f979d6def1676cda6b23fd1a1c93d 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "git-compat-util.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "http.h"
diff --git a/http.c b/http.c
index d94e8f63b573805f29f0b25199e9bc62e0bb5034..33ae9429fd81a103533064a87ee4badc19103e01 100644 (file)
--- a/http.c
+++ b/http.c
@@ -3,6 +3,7 @@
 
 #include "git-compat-util.h"
 #include "git-curl-compat.h"
+#include "environment.h"
 #include "hex.h"
 #include "http.h"
 #include "config.h"
index 9b26c669c01558c69e84ff61e6c0829564f23eaf..254ec83ab7817940f6cf98cdfb90f0dae58e62d0 100644 (file)
@@ -28,6 +28,7 @@
 #include "advice.h"
 #include "config.h"
 #include "credential.h"
+#include "environment.h"
 #include "gettext.h"
 #include "run-command.h"
 #include "parse-options.h"
index b4e815b2d8b03c4d228b1c4178cf1a3fdc3d88e5..99ac596e096e70e11926eed2e930b8f94ddeb032 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "git-compat-util.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex-ll.h"
 #include "utf8.h"
index 39c205fd26e77b2a71ffe8c22812479f87b8d8bd..a974005134629b3a86abd33a6c314479a70d057e 100644 (file)
--- a/reflog.c
+++ b/reflog.c
@@ -3,6 +3,7 @@
 
 #include "git-compat-util.h"
 #include "config.h"
+#include "environment.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "odb.h"
index c7c3e535ce50459bfbec985ace524eec83d0c594..6ec55964e2ae4a516a4a28a5dc93bf05be27bc61 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -5,6 +5,7 @@
 #include "abspath.h"
 #include "config.h"
 #include "copy.h"
+#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
index 77c15a46cfa07d25c3028c9e2d77a3e0b47c9e92..81ed93a05c9ac7bec8ac1c4665c2d2b1e0991458 100644 (file)
@@ -3,6 +3,7 @@
 #include "test-tool.h"
 #include "advice.h"
 #include "config.h"
+#include "environment.h"
 #include "setup.h"
 
 int cmd__advise_if_enabled(int argc, const char **argv)
index b2da48eda05185dd345f388c4713d2db4f7237fd..9ae71cefb302c9d5b77b96cfe06723a27c3361d7 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "test-tool.h"
 #include "config.h"
+#include "environment.h"
 #include "read-cache-ll.h"
 #include "repository.h"
 #include "setup.h"
index 0e5d38c96003d3272706869502160c663a205d84..4971f722b3e5f476d225a470b0038133b2ad5437 100644 (file)
@@ -2,6 +2,7 @@
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
+#include "environment.h"
 #include "gettext.h"
 #include "config.h"
 #include "hex.h"