Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.
In a subsequent patch the path to the system-wide config file will be computed. This is a preparation for that change. It turns all accesses of ETC_GITCONFIG into function calls. There is no change in behavior. As a consequence, config.c is the only file that needs the definition of ETC_GITCONFIG. Hence, -DETC_GITCONFIG is removed from the CFLAGS and a special build rule for config.c is introduced. As a side-effect, changing the defintion of ETC_GITCONFIG (e.g. in config.mak) does not trigger a complete rebuild anymore. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Nov 13, 2007 at 21:05 UTC
506b17b136ba8ee29098c2ee26b94f527cea9ebc
4 files changed
+14
-5
Makefile
+4
-1
@@ -754,7 +754,7 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
754
LIBS = $(GITLIBS) $(EXTLIBS)
755
756
BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
757
- -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
757
+ $(COMPAT_CFLAGS)
758
LIB_OBJS += $(COMPAT_OBJS)
759
760
ALL_CFLAGS += $(BASIC_CFLAGS)
@@ -903,6 +903,9 @@ exec_cmd.o: exec_cmd.c GIT-CFLAGS
903
builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
904
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
905
906
+config.o: config.c GIT-CFLAGS
907
+ $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<
908
+
909
http.o: http.c GIT-CFLAGS
910
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
911
builtin-config.c
+2
-2
@@ -81,7 +81,7 @@ static int get_value(const char* key_, const char* regex_)
81
local = repo_config = xstrdup(git_path("config"));
82
if (home)
83
global = xstrdup(mkpath("%s/.gitconfig", home));
84
- system_wide = ETC_GITCONFIG;
84
+ system_wide = git_etc_gitconfig();
85
}
86
87
key = xstrdup(key_);
@@ -191,7 +191,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
191
}
192
}
193
else if (!strcmp(argv[1], "--system"))
194
- setenv(CONFIG_ENVIRONMENT, ETC_GITCONFIG, 1);
194
+ setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1);
195
else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
196
if (argc < 3)
197
usage(git_config_set_usage);
cache.h
+1
@@ -557,6 +557,7 @@ extern int git_config_bool(const char *, const char *);
557
extern int git_config_set(const char *, const char *);
558
extern int git_config_set_multivar(const char *, const char *, const char *, int);
559
extern int git_config_rename_section(const char *, const char *);
560
+extern const char *git_etc_gitconfig(void);
561
extern int check_repository_format_version(const char *var, const char *value);
562
563
#define MAX_GITNAME (1000)
config.c
+7
-2
@@ -459,6 +459,11 @@ int git_config_from_file(config_fn_t fn, const char *filename)
459
return ret;
460
}
461
462
+const char *git_etc_gitconfig(void)
463
+{
464
+ return ETC_GITCONFIG;
465
+}
466
+
467
int git_config(config_fn_t fn)
468
{
469
int ret = 0;
@@ -471,8 +476,8 @@ int git_config(config_fn_t fn)
476
* config file otherwise. */
477
filename = getenv(CONFIG_ENVIRONMENT);
478
if (!filename) {
474
- if (!access(ETC_GITCONFIG, R_OK))
475
- ret += git_config_from_file(fn, ETC_GITCONFIG);
479
+ if (!access(git_etc_gitconfig(), R_OK))
480
+ ret += git_config_from_file(fn, git_etc_gitconfig());
481
home = getenv("HOME");
482
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
483
if (!filename)