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

[PATCH RFC 7/8] config: add git_config_norepo

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jul 20, 2009, 17:49 UTC
Message-ID
<1248112195-3761-8-git-send-email-bonzini@gnu.org>
In-Reply-To
<1248112195-3761-1-git-send-email-bonzini@gnu.org>

This function will be needed to read the configuration in git-clone before the new repository is created.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
 cache.h  |    1 +
 config.c |   37 ++++++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/cache.h b/cache.h
index a46bfe6..c349cd1 100644
--- a/cache.h
+++ b/cache.h
@@ -893,6 +893,7 @@ typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int git_tracking_config(const char *, const char *, struct tracking_config *);
 extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
+extern int git_config_norepo(config_fn_t fn, void *);
 extern int git_config(config_fn_t fn, void *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_config_int(const char *, const char *);
diff --git a/config.c b/config.c
index 37d95a4..d50a261 100644
--- a/config.c
+++ b/config.c
@@ -709,19 +709,14 @@ int git_config_global(void)
 	return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
 }
 
-int git_config(config_fn_t fn, void *data)
+static int git_config_extra_repo(config_fn_t fn, void *data, int *found)
 {
-	int ret = 0, found = 0;
-	char *repo_config = NULL;
+	int ret = 0;
 	const char *home = NULL;
-
-	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
-	if (config_exclusive_filename)
-		return git_config_from_file(fn, config_exclusive_filename, data);
 	if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
 		ret += git_config_from_file(fn, git_etc_gitconfig(),
 					    data);
-		found += 1;
+		*found += 1;
 	}
 
 	home = getenv("HOME");
@@ -729,11 +724,35 @@ int git_config(config_fn_t fn, void *data)
 		char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
 		if (!access(user_config, R_OK)) {
 			ret += git_config_from_file(fn, user_config, data);
-			found += 1;
+			*found += 1;
 		}
 		free(user_config);
 	}
+	return ret;
+}
+
+int git_config_norepo(config_fn_t fn, void *data)
+{
+	int ret, found = 0;
+
+	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
+	if (config_exclusive_filename)
+		return git_config_from_file(fn, config_exclusive_filename, data);
+	ret = git_config_extra_repo (fn, data, &found);
+	if (found == 0)
+		return -1;
+	return ret;
+}
 
+int git_config(config_fn_t fn, void *data)
+{
+	int ret, found = 0;
+	char *repo_config;
+
+	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
+	if (config_exclusive_filename)
+		return git_config_from_file(fn, config_exclusive_filename, data);
+	ret = git_config_extra_repo (fn, data, &found);
 	repo_config = git_pathdup("config");
 	if (!access(repo_config, R_OK)) {
 		ret += git_config_from_file(fn, repo_config, data);
-- 
1.6.2.5
Previous: Paolo BonziniNext: Paolo Bonzini
Message 12 of 16 in “introduce 'git remote add --push' and 'git clone --push'”
  1. 0/8 introduce 'git remote add --push' and 'git clone --push'Paolo Bonzini, Jul 20, 2009
  2. 1/8 reintroduce PUSH_DEFAULT_UNSPECIFIEDPaolo Bonzini, Jul 20, 2009
  3. 2/8 push: add push.default = mirrorPaolo Bonzini, Jul 20, 2009
  4. Junio C HamanoJul 20, 2009
  5. Paolo BonziniJul 20, 2009
  6. Junio C HamanoJul 20, 2009
  7. Paolo BonziniJul 20, 2009
  8. 3/8 git remote add: refactor configurationPaolo Bonzini, Jul 20, 2009
  9. 4/8 git remote add: add --push optionPaolo Bonzini, Jul 20, 2009
  10. 5/8 clone: refactoring of building the fetch refspecPaolo Bonzini, Jul 20, 2009
  11. 6/8 clone: use setup_remote_configPaolo Bonzini, Jul 20, 2009
  12. 7/8 config: add git_config_norepoPaolo Bonzini, Jul 20, 2009
  13. 8/8 clone: add --push optionPaolo Bonzini, Jul 20, 2009
  14. Junio C HamanoJul 20, 2009
  15. Paolo BonziniJul 21, 2009
  16. Junio C HamanoJul 21, 2009

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.