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

[PATCH v3 03/10] config: Make git_config() more flexible.

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Feb 17, 2009, 13:52 UTC
Message-ID
<1234878776-13250-3-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1234878776-13250-2-git-send-email-felipe.contreras@gmail.com>

Currently git_config() returns an error if there is no repo config file available (cwd is not a git repo); it will correctly parse the system and global config files, but still return an error.

It doesn't affect anything else since almost nobody is checking for the return code (with the exception of 'git remote update').

A reorganization in 'git config' would benefit from being able to properly detect errors in git_config without the noise generated when cwd is not a git repo.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 config.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/config.c b/config.c
index 7dc1b0f..68ce519 100644
--- a/config.c
+++ b/config.c
@@ -649,28 +649,37 @@ int git_config_global(void)
 
 int git_config(config_fn_t fn, void *data)
 {
-	int ret = 0;
+	int ret = 0, found = 0;
 	char *repo_config = NULL;
 	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))
+	if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
 		ret += git_config_from_file(fn, git_etc_gitconfig(),
 					    data);
+		found += 1;
+	}
 
 	home = getenv("HOME");
 	if (git_config_global() && home) {
 		char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
-		if (!access(user_config, R_OK))
+		if (!access(user_config, R_OK)) {
 			ret += git_config_from_file(fn, user_config, data);
+			found += 1;
+		}
 		free(user_config);
 	}
 
 	repo_config = git_pathdup("config");
-	ret += git_config_from_file(fn, repo_config, data);
+	if (!access(repo_config, R_OK)) {
+		ret += git_config_from_file(fn, repo_config, data);
+		found += 1;
+	}
 	free(repo_config);
+	if (found == 0)
+		return -1;
 	return ret;
 }
 
-- 
1.6.1.3
Previous: Felipe ContrerasNext: Felipe Contreras
Message 3 of 16 in “config: Codestyle cleanups.”
  1. 01/10 config: Codestyle cleanups.Felipe Contreras, Feb 17, 2009
  2. 02/10 config: Cleanup editor action.Felipe Contreras, Feb 17, 2009
  3. 03/10 config: Make git_config() more flexible.Felipe Contreras, Feb 17, 2009
  4. 04/10 config: Trivial rename in preparation for parseopt.Felipe Contreras, Feb 17, 2009
  5. 05/10 config: Reorganize get_color*.Felipe Contreras, Feb 17, 2009
  6. 06/10 config: Use parseopt.Felipe Contreras, Feb 17, 2009
  7. 07/10 config: Disallow --getcolor* and other actions.Felipe Contreras, Feb 17, 2009
  8. 08/10 config: Disallow multiple config file locations.Felipe Contreras, Feb 17, 2009
  9. 09/10 config: Disallow multiple variable types.Felipe Contreras, Feb 17, 2009
  10. 10/10 config: Don't allow extra arguments for -e or -l.Felipe Contreras, Feb 17, 2009
  11. Junio C HamanoFeb 18, 2009
  12. Felipe ContrerasFeb 18, 2009
  13. Junio C HamanoFeb 18, 2009
  14. Sverre RabbelierFeb 17, 2009
  15. Felipe ContrerasFeb 18, 2009
  16. Junio C HamanoFeb 18, 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.