All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 7/8] config: Don't return negative exit codes.
Date: Sun, 15 Feb 2009 15:30:12 +0200	[thread overview]
Message-ID: <20090215133012.GA13801@annwn> (raw)
In-Reply-To: <94a0d4530902150439peac228ckec79f8c692b84e4e@mail.gmail.com>

On Sun, Feb 15, 2009 at 02:39:47PM +0200, Felipe Contreras wrote:
> On Sun, Feb 15, 2009 at 2:22 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > Hi,
> >
> > On Sun, 15 Feb 2009, Felipe Contreras wrote:
> >
> >
> >>       else if (actions & ACTION_RENAME_SECTION) {
> >> -             int ret;
> >>               check_argc(argc, 2, 2);
> >>               ret = git_config_rename_section(argv[0], argv[1]);
> >> -             if (ret < 0)
> >> -                     return ret;
> >>               if (ret == 0)
> >>                       die("No such section!");
> >>       }
> >
> > You need an "if (ret > 0) ret = 0;" to avoid regressions.
> >
> >>       else if (actions & ACTION_REMOVE_SECTION) {
> >> -             int ret;
> >>               check_argc(argc, 1, 1);
> >>               ret = git_config_rename_section(argv[0], NULL);
> >> -             if (ret < 0)
> >> -                     return ret;
> >>               if (ret == 0)
> >>                       die("No such section!");
> >>       }
> >
> > Likewise.
> 
> True. Fixed in the attached patch.

I'm inlining the patch as Johannes requested:

---
 builtin-config.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/builtin-config.c b/builtin-config.c
index 5891a4e..0606ada 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -307,6 +307,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
 {
 	int nongit;
 	char* value;
+	int ret = 0;
 	const char *prefix = setup_git_directory_gently(&nongit);
 
 	config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
@@ -380,57 +381,55 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
 	else if (actions & ACTION_ADD) {
 		check_argc(argc, 2, 2);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set_multivar(argv[0], value, "^$", 0);
+		ret = git_config_set_multivar(argv[0], value, "^$", 0);
 	}
 	else if (actions & ACTION_REPLACE_ALL) {
 		check_argc(argc, 2, 3);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set_multivar(argv[0], value, argv[2], 1);
+		ret = git_config_set_multivar(argv[0], value, argv[2], 1);
 	}
 	else if (actions & ACTION_GET) {
 		check_argc(argc, 1, 2);
-		return get_value(argv[0], argv[1]);
+		ret = get_value(argv[0], argv[1]);
 	}
 	else if (actions & ACTION_GET_ALL) {
 		do_all = 1;
 		check_argc(argc, 1, 2);
-		return get_value(argv[0], argv[1]);
+		ret = get_value(argv[0], argv[1]);
 	}
 	else if (actions & ACTION_GET_REGEXP) {
 		show_keys = 1;
 		use_key_regexp = 1;
 		do_all = 1;
 		check_argc(argc, 1, 2);
-		return get_value(argv[0], argv[1]);
+		ret = get_value(argv[0], argv[1]);
 	}
 	else if (actions & ACTION_UNSET) {
 		check_argc(argc, 1, 2);
 		if (argc == 2)
-			return git_config_set_multivar(argv[0], NULL, argv[1], 0);
+			ret = git_config_set_multivar(argv[0], NULL, argv[1], 0);
 		else
-			return git_config_set(argv[0], NULL);
+			ret = git_config_set(argv[0], NULL);
 	}
 	else if (actions & ACTION_UNSET_ALL) {
 		check_argc(argc, 1, 2);
-		return git_config_set_multivar(argv[0], NULL, argv[1], 1);
+		ret = git_config_set_multivar(argv[0], NULL, argv[1], 1);
 	}
 	else if (actions & ACTION_RENAME_SECTION) {
-		int ret;
 		check_argc(argc, 2, 2);
 		ret = git_config_rename_section(argv[0], argv[1]);
-		if (ret < 0)
-			return ret;
 		if (ret == 0)
 			die("No such section!");
+		if (ret > 0)
+			ret = 0;
 	}
 	else if (actions & ACTION_REMOVE_SECTION) {
-		int ret;
 		check_argc(argc, 1, 1);
 		ret = git_config_rename_section(argv[0], NULL);
-		if (ret < 0)
-			return ret;
 		if (ret == 0)
 			die("No such section!");
+		if (ret > 0)
+			ret = 0;
 	}
 	else if (get_color_slot) {
 		get_color(argv[0]);
@@ -440,8 +439,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
 			stdout_is_tty = git_config_bool("command line", argv[0]);
 		else if (argc == 0)
 			stdout_is_tty = isatty(1);
-		return get_colorbool(argc != 1);
+		ret = get_colorbool(argc != 1);
 	}
 
-	return 0;
+	return !!ret;
 }
-- 
1.6.1.3

-- 
Felipe Contreras

  reply	other threads:[~2009-02-15 13:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-15  9:00 [PATCH 1/8] config: Trivial rename in preparation for parseopt Felipe Contreras
2009-02-15  9:00 ` [PATCH 2/8] config: Cleanup config file handling Felipe Contreras
2009-02-15  9:00   ` [PATCH 3/8] config: Use parseopt Felipe Contreras
2009-02-15  9:00     ` [PATCH 4/8] config: Improve variable 'type' handling Felipe Contreras
2009-02-15  9:00       ` [PATCH 5/8] config: Disallow multiple config file locations Felipe Contreras
2009-02-15  9:00         ` [PATCH 6/8] config: Don't allow extra arguments for -e or -l Felipe Contreras
2009-02-15  9:00           ` [PATCH 7/8] config: Don't return negative exit codes Felipe Contreras
2009-02-15  9:01             ` [PATCH 8/8] config: Codestyle cleanups Felipe Contreras
2009-02-15 12:22             ` [PATCH 7/8] config: Don't return negative exit codes Johannes Schindelin
2009-02-15 12:39               ` Felipe Contreras
2009-02-15 13:30                 ` Felipe Contreras [this message]
2009-02-15 12:26         ` [PATCH 5/8] config: Disallow multiple config file locations Johannes Schindelin
2009-02-15 12:44           ` Felipe Contreras
2009-02-15 13:35             ` Felipe Contreras
2009-02-15 12:24       ` [PATCH 4/8] config: Improve variable 'type' handling Johannes Schindelin
2009-02-15 12:43         ` Felipe Contreras
2009-02-15 13:34           ` Felipe Contreras
2009-02-15 20:15   ` [PATCH 2/8] config: Cleanup config file handling Jeff King
2009-02-16  1:15   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090215133012.GA13801@annwn \
    --to=felipe.contreras@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.