git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 10/11] Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Nov 13, 2007, 20:05 UTC
Message-ID
<1194984306-3181-11-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<1194984306-3181-10-git-send-email-johannes.sixt@telecom.at>

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>
---
 Makefile         |    5 ++++-
 builtin-config.c |    4 ++--
 cache.h          |    1 +
 config.c         |    9 +++++++--
 4 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 18c61f3..e32f07e 100644
--- a/Makefile
+++ b/Makefile
@@ -752,7 +752,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)
@@ -901,6 +901,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)"' $<
 
diff --git a/builtin-config.c b/builtin-config.c
index e5e243f..f672c9c 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -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 28870c5..0eb7b43 100644
--- a/cache.h
+++ b/cache.h
@@ -551,6 +551,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)
diff --git a/config.c b/config.c
index dc3148d..dd7e9ad 100644
--- a/config.c
+++ b/config.c
@@ -452,6 +452,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;
@@ -464,8 +469,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)
-- 
1.5.3.5.1592.g0d6db
Previous: Johannes SixtNext: Johannes Sixt
Message 11 of 35 in “Miscellaneous MinGW port fallout”
  1. 0/11 Miscellaneous MinGW port falloutJohannes Sixt, Nov 13, 2007
  2. 01/11 t5300-pack-object.sh: Split the big verify-pack test into smaller parts.Johannes Sixt, Nov 13, 2007
  3. 02/11 t7501-commit.sh: Not all seds understand option -iJohannes Sixt, Nov 13, 2007
  4. 03/11 t5302-pack-index: Skip tests of 64-bit offsets if necessary.Johannes Sixt, Nov 13, 2007
  5. 04/11 Skip t3902-quoted.sh if the file system does not support funny names.Johannes Sixt, Nov 13, 2007
  6. 05/11 Use is_absolute_path() in sha1_file.c.Johannes Sixt, Nov 13, 2007
  7. 06/11 Move #include <sys/select.h> and <sys/ioctl.h> to git-compat-util.h.Johannes Sixt, Nov 13, 2007
  8. 07/11 builtin run_command: do not exit with -1.Johannes Sixt, Nov 13, 2007
  9. 08/11 Close files opened by lock_file() before unlinking.Johannes Sixt, Nov 13, 2007
  10. 09/11 Allow a relative builtin template directory.Johannes Sixt, Nov 13, 2007
  11. 10/11 Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.Johannes Sixt, Nov 13, 2007
  12. 11/11 Allow ETC_GITCONFIG to be a relative path.Johannes Sixt, Nov 13, 2007
  13. Steffen ProhaskaNov 15, 2007
  14. Johannes SixtNov 15, 2007
  15. Steffen ProhaskaNov 15, 2007
  16. Johannes SixtNov 15, 2007
  17. Steffen ProhaskaNov 15, 2007
  18. Johannes SchindelinNov 13, 2007
  19. Johannes SixtNov 13, 2007
  20. Johannes SchindelinNov 13, 2007
  21. Johannes SchindelinNov 13, 2007
  22. Johannes SchindelinNov 13, 2007
  23. Johannes SixtNov 13, 2007
  24. Johannes SchindelinNov 13, 2007
  25. Robin RosenbergNov 14, 2007
  26. Johannes SixtNov 13, 2007
  27. Junio C HamanoNov 13, 2007
  28. Johannes SixtNov 13, 2007
  29. Johannes SchindelinNov 13, 2007
  30. Johannes SixtNov 13, 2007
  31. Junio C HamanoNov 13, 2007
  32. Junio C HamanoNov 14, 2007
  33. Johannes SchindelinNov 14, 2007
  34. Junio C HamanoNov 14, 2007
  35. Johannes SchindelinNov 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.