Skip to content

Commit 64589a0

Browse files
committed
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d0ff65 commit 64589a0

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

attr.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
2020
#define ATTR__UNSET NULL
2121
#define ATTR__UNKNOWN git_attr__unknown
2222

23-
static const char *attributes_file;
24-
2523
/* This is a randomly chosen prime. */
2624
#define HASHSIZE 257
2725

@@ -494,14 +492,6 @@ static int git_attr_system(void)
494492
return !git_env_bool("GIT_ATTR_NOSYSTEM", 0);
495493
}
496494

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-
505495
static void bootstrap_attr_stack(void)
506496
{
507497
if (!attr_stack) {
@@ -521,9 +511,8 @@ static void bootstrap_attr_stack(void)
521511
}
522512
}
523513

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);
527516
if (elem) {
528517
elem->origin = NULL;
529518
elem->prev = attr_stack;

builtin/check-attr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
9292
struct git_attr_check *check;
9393
int cnt, i, doubledash, filei;
9494

95+
git_config(git_default_config, NULL);
96+
9597
argc = parse_options(argc, argv, prefix, check_attr_options,
9698
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
9799

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ extern int warn_ambiguous_refs;
589589
extern int shared_repository;
590590
extern const char *apply_default_whitespace;
591591
extern const char *apply_default_ignorewhitespace;
592+
extern const char *git_attributes_file;
592593
extern int zlib_compression_level;
593594
extern int core_compression_level;
594595
extern int core_compression_seen;

config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ static int git_default_core_config(const char *var, const char *value)
491491
return 0;
492492
}
493493

494+
if (!strcmp(var, "core.attributesfile"))
495+
return git_config_pathname(&git_attributes_file, var, value);
496+
494497
if (!strcmp(var, "core.bare")) {
495498
is_bare_repository_cfg = git_config_bool(var, value);
496499
return 0;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const char *git_log_output_encoding;
2929
int shared_repository = PERM_UMASK;
3030
const char *apply_default_whitespace;
3131
const char *apply_default_ignorewhitespace;
32+
const char *git_attributes_file;
3233
int zlib_compression_level = Z_BEST_SPEED;
3334
int core_compression_level;
3435
int core_compression_seen;

0 commit comments

Comments
 (0)