attr: read core.attributesfile from git_default_core_config

This code calls git_config from a helper function to parse the config entry it is interested in. Calling git_config in this way may cause a problem if the helper function can be called after a previous call to git_config by another function since the second call to git_config may reset some variable to the value in the config file which was previously overridden. The above is not a problem in this case since the function passed to git_config only parses one config entry and the variable it sets is not assigned outside of the parsing function. But a programmer who desires all of the standard config options to be parsed may be tempted to modify git_attr_config() so that it falls back to git_default_config() and then it _would_ be vulnerable to the above described behavior. So, move the call to git_config up into the top-level cmd_* function and move the responsibility for parsing core.attributesfile into the main config file parser. Which is only the logical thing to do ;-) Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 6, 2011 at 13:22 UTC 64589a03a8ffb3eb4fb2ff8f416ff638a9aaa439
5 files changed +9 -13
attr.c
+2 -13
@@ -20,8 +20,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
20 #define ATTR__UNSET NULL
21 #define ATTR__UNKNOWN git_attr__unknown
22
23 -static const char *attributes_file;
24 -
23 /* This is a randomly chosen prime. */
24 #define HASHSIZE 257
25
@@ -494,14 +492,6 @@ static int git_attr_system(void)
492 return !git_env_bool("GIT_ATTR_NOSYSTEM", 0);
493 }
494
497 -static int git_attr_config(const char *var, const char *value, void *dummy)
498 -{
499 - if (!strcmp(var, "core.attributesfile"))
500 - return git_config_pathname(&attributes_file, var, value);
501 -
502 - return 0;
503 -}
504 -
495 static void bootstrap_attr_stack(void)
496 {
497 if (!attr_stack) {
@@ -521,9 +511,8 @@ static void bootstrap_attr_stack(void)
511 }
512 }
513
524 - git_config(git_attr_config, NULL);
525 - if (attributes_file) {
526 - elem = read_attr_from_file(attributes_file, 1);
514 + if (git_attributes_file) {
515 + elem = read_attr_from_file(git_attributes_file, 1);
516 if (elem) {
517 elem->origin = NULL;
518 elem->prev = attr_stack;
builtin/check-attr.c
+2
@@ -92,6 +92,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
92 struct git_attr_check *check;
93 int cnt, i, doubledash, filei;
94
95 + git_config(git_default_config, NULL);
96 +
97 argc = parse_options(argc, argv, prefix, check_attr_options,
98 check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
99
cache.h
+1
@@ -589,6 +589,7 @@ extern int warn_ambiguous_refs;
589 extern int shared_repository;
590 extern const char *apply_default_whitespace;
591 extern const char *apply_default_ignorewhitespace;
592 +extern const char *git_attributes_file;
593 extern int zlib_compression_level;
594 extern int core_compression_level;
595 extern int core_compression_seen;
config.c
+3
@@ -491,6 +491,9 @@ static int git_default_core_config(const char *var, const char *value)
491 return 0;
492 }
493
494 + if (!strcmp(var, "core.attributesfile"))
495 + return git_config_pathname(&git_attributes_file, var, value);
496 +
497 if (!strcmp(var, "core.bare")) {
498 is_bare_repository_cfg = git_config_bool(var, value);
499 return 0;
environment.c
+1
@@ -29,6 +29,7 @@ const char *git_log_output_encoding;
29 int shared_repository = PERM_UMASK;
30 const char *apply_default_whitespace;
31 const char *apply_default_ignorewhitespace;
32 +const char *git_attributes_file;
33 int zlib_compression_level = Z_BEST_SPEED;
34 int core_compression_level;
35 int core_compression_seen;