diff --git a/attr.c b/attr.c index 4999b7e09da930f7701e6fbd22306531c6f67ca8..08deec22c29d9775cb3d33e5f97d044036e45154 100644 --- a/attr.c +++ b/attr.c @@ -879,14 +879,6 @@ const char *git_attr_system_file(void) return system_wide; } -const char *git_attr_global_file(void) -{ - if (!git_attributes_file) - git_attributes_file = xdg_config_home("attributes"); - - return git_attributes_file; -} - int git_attr_system_is_enabled(void) { return !git_env_bool("GIT_ATTR_NOSYSTEM", 0); @@ -927,8 +919,8 @@ static void bootstrap_attr_stack(struct index_state *istate, } /* home directory */ - if (git_attr_global_file()) { - e = read_attr_from_file(git_attr_global_file(), flags); + if (repo_settings_get_attributesfile_path(istate->repo)) { + e = read_attr_from_file(repo_settings_get_attributesfile_path(istate->repo), flags); push_stack(stack, e, NULL, 0); } diff --git a/attr.h b/attr.h index a04a5210921e222551a48398a7b098d2c449d368..956ce6ba627419b3305994073695e1c8adebec5d 100644 --- a/attr.h +++ b/attr.h @@ -232,9 +232,6 @@ void attr_start(void); /* Return the system gitattributes file. */ const char *git_attr_system_file(void); -/* Return the global gitattributes file, if any. */ -const char *git_attr_global_file(void); - /* Return whether the system gitattributes file is enabled and should be used. */ int git_attr_system_is_enabled(void); diff --git a/builtin/var.c b/builtin/var.c index cc3a43cde25a6c1a9f17e5de8959ec870a112f32..fd577f29306988011074bffd1905b06ecd5205a3 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -72,7 +72,7 @@ static char *git_attr_val_system(int ident_flag UNUSED) static char *git_attr_val_global(int ident_flag UNUSED) { - char *file = xstrdup_or_null(git_attr_global_file()); + char *file = xstrdup_or_null(repo_settings_get_attributesfile_path(the_repository)); if (file) { normalize_path_copy(file, file); return file; diff --git a/environment.c b/environment.c index a770b5921d9546818b350157f7b4501db1261f4c..ed7d8f42d991d8bca17df0739de597d31bfc9b45 100644 --- a/environment.c +++ b/environment.c @@ -53,7 +53,6 @@ char *git_commit_encoding; char *git_log_output_encoding; char *apply_default_whitespace; char *apply_default_ignorewhitespace; -char *git_attributes_file; int zlib_compression_level = Z_BEST_SPEED; int pack_compression_level = Z_DEFAULT_COMPRESSION; int fsync_object_files = -1; @@ -363,11 +362,6 @@ static int git_default_core_config(const char *var, const char *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; diff --git a/environment.h b/environment.h index 51898c99cd1e451a47c1a4aae32869cfbddbce45..3512a7072e75b6ce8aa08cc5d847969281d3dc58 100644 --- a/environment.h +++ b/environment.h @@ -152,7 +152,6 @@ extern int assume_unchanged; extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; extern char *apply_default_ignorewhitespace; -extern char *git_attributes_file; extern int zlib_compression_level; extern int pack_compression_level; extern unsigned long pack_size_limit_cfg; diff --git a/repo-settings.c b/repo-settings.c index 195c24e9c07606f00aa4d02eaf4ad25b6642a67f..d89d7893d496a6c1bb01393fdd98e5353721181b 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -5,6 +5,7 @@ #include "midx.h" #include "pack-objects.h" #include "setup.h" +#include "path.h" static void repo_cfg_bool(struct repository *r, const char *key, int *dest, int def) @@ -158,6 +159,7 @@ void repo_settings_clear(struct repository *r) struct repo_settings empty = REPO_SETTINGS_INIT; FREE_AND_NULL(r->settings.fsmonitor); FREE_AND_NULL(r->settings.hooks_path); + FREE_AND_NULL(r->settings.git_attributes_file); r->settings = empty; } @@ -230,3 +232,10 @@ void repo_settings_reset_shared_repository(struct repository *repo) { repo->settings.shared_repository_initialized = 0; } +const char *repo_settings_get_attributesfile_path(struct repository *repo) { + if (!repo->settings.git_attributes_file) { + if (repo_config_get_pathname(repo, "core.attributesfile", &repo->settings.git_attributes_file)) + repo->settings.git_attributes_file = xdg_config_home("attributes"); + } + return repo->settings.git_attributes_file; +} diff --git a/repo-settings.h b/repo-settings.h index d477885561449727db7fbc2ca8ece2280c4e7610..362f35526727fa87f4441047cfcf73e02d59ea9e 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -68,6 +68,7 @@ struct repo_settings { unsigned long big_file_threshold; char *hooks_path; + char *git_attributes_file; }; #define REPO_SETTINGS_INIT { \ .shared_repository = -1, \ @@ -99,4 +100,11 @@ int repo_settings_get_shared_repository(struct repository *repo); void repo_settings_set_shared_repository(struct repository *repo, int value); void repo_settings_reset_shared_repository(struct repository *repo); +/* + * Read the value for "core.attributesfile". + * Defaults to xdg_config_home("attributes") if the core.attributesfile + * isn't available. + */ +const char *repo_settings_get_attributesfile_path(struct repository *repo); + #endif /* REPO_SETTINGS_H */