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

Re: [PATCH] buitin_config: return postitive status in get_value

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2012, 20:43 UTC
Message-ID
<7v4noqwb6e.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vipd7vzql.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> I personally think that the documentation unnecessarily exposes the
> useless value assignment of the exit codes (the use of different
> exit codes was done merely to aid debugging the git-config command
> itself) by describing the then-current set of conditions, and should
> be reduced to say "0 for success, non-zero for any error".
>
> But if we really want to follow that "documented" subset of possible
> conditions, I agree that your version to return "1" in this case,
> together with a change to initialize "ret" to "7" and document it as
> "all other errors (ret=7), would make more sense.  Other conditions
> that have been added since that partial enumeration of the exit code
> was done are regexp errors, which I think will get -1 from the same
> function.
IOW, something like this.
 Documentation/git-config.txt | 18 ++++++++++--------
 builtin/config.c             |  8 ++++++--
 2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 2d6ef32..b071d65 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -54,19 +54,21 @@ configuration file by default, and options '--system', '--global',
 '--file <filename>' can be used to tell the command to write to
 that location (you can say '--local' but that is the default).
 
-This command will fail (with exit code ret) if:
+This command will fail with non-zero status if:
 
+. The section name or key name is invalid (ret=1),
+. No section name or key name was provided (ret=2),
 . The config file is invalid (ret=3),
-. can not write to the config file (ret=4),
-. no section or name was provided (ret=2),
-. the section or key is invalid (ret=1),
-. you try to unset an option which does not exist (ret=5),
-. you try to unset/set an option for which multiple lines match (ret=5),
-. you try to use an invalid regexp (ret=6), or
-. you use '--global' option without $HOME being properly set (ret=128).
+. The config file cannot be written (ret=4),
+. You try to unset an option which does not exist (ret=5),
+. You try to unset/set an option for which multiple lines match (ret=5),
+. You try to use an invalid regexp (ret=6),
+. You use '--global' option without $HOME being properly set (ret=128),
+. Any other errors (ret=7).
 
 On success, the command returns the exit code 0.
 
+
 OPTIONS
 -------
 
diff --git a/builtin/config.c b/builtin/config.c
index 8cd08da..2318308 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -160,7 +160,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
 
 static int get_value(const char *key_, const char *regex_)
 {
-	int ret = -1;
+	int ret = 7;
 	char *global = NULL, *xdg = NULL, *repo_config = NULL;
 	const char *system_wide = NULL, *local;
 	struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -196,11 +196,14 @@ static int get_value(const char *key_, const char *regex_)
 		if (regcomp(key_regexp, key, REG_EXTENDED)) {
 			fprintf(stderr, "Invalid key pattern: %s\n", key_);
 			free(key);
+			ret = 6;
 			goto free_strings;
 		}
 	} else {
-		if (git_config_parse_key(key_, &key, NULL))
+		if (git_config_parse_key(key_, &key, NULL)) {
+			ret = 1;
 			goto free_strings;
+		}
 	}
 
 	if (regex_) {
@@ -212,6 +215,7 @@ static int get_value(const char *key_, const char *regex_)
 		regexp = (regex_t*)xmalloc(sizeof(regex_t));
 		if (regcomp(regexp, regex_, REG_EXTENDED)) {
 			fprintf(stderr, "Invalid pattern: %s\n", regex_);
+			ret = 6;
 			goto free_strings;
 		}
 	}
Previous: Junio C HamanoNext: Jeff King
Message 6 of 10 in “buitin_config: return postitive status in get_value”
  1. buitin_config: return postitive status in get_valueNikolai Vladimirov, Jul 28, 2012
  2. Nguyen Thai Ngoc DuyJul 28, 2012
  3. Nikolay VladimirovJul 28, 2012
  4. Nguyen Thai Ngoc DuyJul 28, 2012
  5. Junio C HamanoJul 29, 2012
  6. Junio C HamanoJul 29, 2012
  7. Jeff KingJul 29, 2012
  8. Nguyen Thai Ngoc DuyJul 30, 2012
  9. Junio C HamanoJul 30, 2012
  10. Jeff KingJul 29, 2012

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.