From: Felipe Contreras Date: Sun, 15 Feb 2009 13:35:57 GMT Subject: Re: [PATCH 5/8] config: Disallow multiple config file locations. Message-ID: <20090215133557.GB13810@annwn> In-Reply-To: <94a0d4530902150444t6e4dcd3btda79aaa0efebfe62@mail.gmail.com> On Sun, Feb 15, 2009 at 02:44:29PM +0200, Felipe Contreras wrote: > On Sun, Feb 15, 2009 at 2:26 PM, Johannes Schindelin > wrote: > > Hi, > > > > On Sun, 15 Feb 2009, Felipe Contreras wrote: > > > >> Either --global, --system, or --file should be used, but not any > >> combination. > >> > >> Signed-off-by: Felipe Contreras > >> --- > >> builtin-config.c | 10 ++++++++++ > >> 1 files changed, 10 insertions(+), 0 deletions(-) > >> > >> diff --git a/builtin-config.c b/builtin-config.c > >> index 83f8b74..e744ad8 100644 > >> --- a/builtin-config.c > >> +++ b/builtin-config.c > >> @@ -314,6 +314,16 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) > >> > >> argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0); > >> > >> + { > >> + int config_file_count = use_global_config + use_system_config; > >> + if (given_config_file) > >> + config_file_count++; > >> + if (config_file_count > 1) { > >> + error("only one config file at a time."); > >> + usage_with_options(builtin_config_usage, builtin_config_options); > >> + } > >> + } > > > > Hmm. Is this a convoluted way to write > > > > if (use_global_config + use_system_config + !!given_config_file > 1) > > > > or am I misunderstanding anything? > > Ah, much better. (the !!foo trick is new to me) Now inlined: --- builtin-config.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/builtin-config.c b/builtin-config.c index 30de93e..cdd8a12 100644 --- a/builtin-config.c +++ b/builtin-config.c @@ -313,6 +313,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0); + if (use_global_config + use_system_config + !!given_config_file > 1) { + error("only one config file at a time."); + usage_with_options(builtin_config_usage, builtin_config_options); + } + if (use_global_config) { char *home = getenv("HOME"); if (home) { -- 1.6.1.3 -- Felipe Contreras