Browse Source

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>
maint
Junio C Hamano 13 years ago
parent
commit
64589a03a8
  1. 15
      attr.c
  2. 2
      builtin/check-attr.c
  3. 1
      cache.h
  4. 3
      config.c
  5. 1
      environment.c

15
attr.c

@ -20,8 +20,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
#define ATTR__UNSET NULL #define ATTR__UNSET NULL
#define ATTR__UNKNOWN git_attr__unknown #define ATTR__UNKNOWN git_attr__unknown


static const char *attributes_file;

/* This is a randomly chosen prime. */ /* This is a randomly chosen prime. */
#define HASHSIZE 257 #define HASHSIZE 257


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


static int git_attr_config(const char *var, const char *value, void *dummy)
{
if (!strcmp(var, "core.attributesfile"))
return git_config_pathname(&attributes_file, var, value);

return 0;
}

static void bootstrap_attr_stack(void) static void bootstrap_attr_stack(void)
{ {
if (!attr_stack) { if (!attr_stack) {
@ -521,9 +511,8 @@ static void bootstrap_attr_stack(void)
} }
} }


git_config(git_attr_config, NULL); if (git_attributes_file) {
if (attributes_file) { elem = read_attr_from_file(git_attributes_file, 1);
elem = read_attr_from_file(attributes_file, 1);
if (elem) { if (elem) {
elem->origin = NULL; elem->origin = NULL;
elem->prev = attr_stack; elem->prev = attr_stack;

2
builtin/check-attr.c

@ -92,6 +92,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
struct git_attr_check *check; struct git_attr_check *check;
int cnt, i, doubledash, filei; int cnt, i, doubledash, filei;


git_config(git_default_config, NULL);

argc = parse_options(argc, argv, prefix, check_attr_options, argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH); check_attr_usage, PARSE_OPT_KEEP_DASHDASH);



1
cache.h

@ -589,6 +589,7 @@ extern int warn_ambiguous_refs;
extern int shared_repository; extern int shared_repository;
extern const char *apply_default_whitespace; extern const char *apply_default_whitespace;
extern const char *apply_default_ignorewhitespace; extern const char *apply_default_ignorewhitespace;
extern const char *git_attributes_file;
extern int zlib_compression_level; extern int zlib_compression_level;
extern int core_compression_level; extern int core_compression_level;
extern int core_compression_seen; extern int core_compression_seen;

3
config.c

@ -491,6 +491,9 @@ static int git_default_core_config(const char *var, const char *value)
return 0; return 0;
} }


if (!strcmp(var, "core.attributesfile"))
return git_config_pathname(&git_attributes_file, var, value);

if (!strcmp(var, "core.bare")) { if (!strcmp(var, "core.bare")) {
is_bare_repository_cfg = git_config_bool(var, value); is_bare_repository_cfg = git_config_bool(var, value);
return 0; return 0;

1
environment.c

@ -29,6 +29,7 @@ const char *git_log_output_encoding;
int shared_repository = PERM_UMASK; int shared_repository = PERM_UMASK;
const char *apply_default_whitespace; const char *apply_default_whitespace;
const char *apply_default_ignorewhitespace; const char *apply_default_ignorewhitespace;
const char *git_attributes_file;
int zlib_compression_level = Z_BEST_SPEED; int zlib_compression_level = Z_BEST_SPEED;
int core_compression_level; int core_compression_level;
int core_compression_seen; int core_compression_seen;

Loading…
Cancel
Save