attr: expose and rename accessor functions

Right now, the functions which determine the current system and global gitattributes files are not exposed. We'd like to use them in a future commit, but they're not ideally named. Rename them to something more suitable as a public interface, expose them, and document them. Signed-off-by: brian m. carlson <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jun 27, 2023 at 16:19 UTC 15780bb4f0cb07624ca6bac3c430ef07e9501663
2 files changed +16 -7
attr.c
+7 -7
@@ -870,7 +870,7 @@ static struct attr_stack *read_attr(struct index_state *istate,
870 return res;
871 }
872
873 -static const char *git_etc_gitattributes(void)
873 +const char *git_attr_system_file(void)
874 {
875 static const char *system_wide;
876 if (!system_wide)
@@ -878,7 +878,7 @@ static const char *git_etc_gitattributes(void)
878 return system_wide;
879 }
880
881 -static const char *get_home_gitattributes(void)
881 +const char *git_attr_global_file(void)
882 {
883 if (!git_attributes_file)
884 git_attributes_file = xdg_config_home("attributes");
@@ -886,7 +886,7 @@ static const char *get_home_gitattributes(void)
886 return git_attributes_file;
887 }
888
889 -static int git_attr_system(void)
889 +int git_attr_system_is_enabled(void)
890 {
891 return !git_env_bool("GIT_ATTR_NOSYSTEM", 0);
892 }
@@ -920,14 +920,14 @@ static void bootstrap_attr_stack(struct index_state *istate,
920 push_stack(stack, e, NULL, 0);
921
922 /* system-wide frame */
923 - if (git_attr_system()) {
924 - e = read_attr_from_file(git_etc_gitattributes(), flags);
923 + if (git_attr_system_is_enabled()) {
924 + e = read_attr_from_file(git_attr_system_file(), flags);
925 push_stack(stack, e, NULL, 0);
926 }
927
928 /* home directory */
929 - if (get_home_gitattributes()) {
930 - e = read_attr_from_file(get_home_gitattributes(), flags);
929 + if (git_attr_global_file()) {
930 + e = read_attr_from_file(git_attr_global_file(), flags);
931 push_stack(stack, e, NULL, 0);
932 }
933
attr.h
+9
@@ -227,4 +227,13 @@ void git_attr_set_direction(enum git_attr_direction new_direction);
227
228 void attr_start(void);
229
230 +/* Return the system gitattributes file. */
231 +const char *git_attr_system_file(void);
232 +
233 +/* Return the global gitattributes file, if any. */
234 +const char *git_attr_global_file(void);
235 +
236 +/* Return whether the system gitattributes file is enabled and should be used. */
237 +int git_attr_system_is_enabled(void);
238 +
239 #endif /* ATTR_H */