OSDN Git Service

Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.
authorJohannes Sixt <johannes.sixt@telecom.at>
Tue, 13 Nov 2007 20:05:05 +0000 (21:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2007 23:18:39 +0000 (15:18 -0800)
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>
Makefile
builtin-config.c
cache.h
config.c

index e830bc7..817f3c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -754,7 +754,7 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 LIBS = $(GITLIBS) $(EXTLIBS)
 
 BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
-       -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
+       $(COMPAT_CFLAGS)
 LIB_OBJS += $(COMPAT_OBJS)
 
 ALL_CFLAGS += $(BASIC_CFLAGS)
@@ -903,6 +903,9 @@ exec_cmd.o: exec_cmd.c GIT-CFLAGS
 builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
        $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
 
+config.o: config.c GIT-CFLAGS
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<
+
 http.o: http.c GIT-CFLAGS
        $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
 
index e5e243f..f672c9c 100644 (file)
@@ -81,7 +81,7 @@ static int get_value(const char* key_, const char* regex_)
                        local = repo_config = xstrdup(git_path("config"));
                if (home)
                        global = xstrdup(mkpath("%s/.gitconfig", home));
-               system_wide = ETC_GITCONFIG;
+               system_wide = git_etc_gitconfig();
        }
 
        key = xstrdup(key_);
@@ -191,7 +191,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                        }
                }
                else if (!strcmp(argv[1], "--system"))
-                       setenv(CONFIG_ENVIRONMENT, ETC_GITCONFIG, 1);
+                       setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1);
                else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
                        if (argc < 3)
                                usage(git_config_set_usage);
diff --git a/cache.h b/cache.h
index dc75f9d..a0b9377 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -557,6 +557,7 @@ extern int git_config_bool(const char *, const char *);
 extern int git_config_set(const char *, const char *);
 extern int git_config_set_multivar(const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
+extern const char *git_etc_gitconfig(void);
 extern int check_repository_format_version(const char *var, const char *value);
 
 #define MAX_GITNAME (1000)
index 56e99fc..cee2d26 100644 (file)
--- a/config.c
+++ b/config.c
@@ -459,6 +459,11 @@ int git_config_from_file(config_fn_t fn, const char *filename)
        return ret;
 }
 
+const char *git_etc_gitconfig(void)
+{
+       return ETC_GITCONFIG;
+}
+
 int git_config(config_fn_t fn)
 {
        int ret = 0;
@@ -471,8 +476,8 @@ int git_config(config_fn_t fn)
         * config file otherwise. */
        filename = getenv(CONFIG_ENVIRONMENT);
        if (!filename) {
-               if (!access(ETC_GITCONFIG, R_OK))
-                       ret += git_config_from_file(fn, ETC_GITCONFIG);
+               if (!access(git_etc_gitconfig(), R_OK))
+                       ret += git_config_from_file(fn, git_etc_gitconfig());
                home = getenv("HOME");
                filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
                if (!filename)