From: Felipe Contreras <felipe.contreras@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] config: Use parseopt.
Date: Sat, 14 Feb 2009 14:15:37 +0200 [thread overview]
Message-ID: <94a0d4530902140415j4168d09dh8abac0d6eba0b8cf@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.1.00.0902141230250.10279@pacific.mpi-cbg.de>
On Sat, Feb 14, 2009 at 1:40 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Sat, 14 Feb 2009, Felipe Contreras wrote:
>
>> Then why are you asking?
>
> Out of curiosity, I guess, as it would happen to answer my curiosity as
> well.
>
>> This is more a "I would like to increase the chances of my patches
>> being accepted so I'd do some chores to gain the trust of some
>> developers", and Johannes Schindelin was pushing me to do this.
>
> Heh, I'll gladly take the blame for that!
>
> Note that in contrast to Junio, I think "git config" is a chimera between
> plumbing and porcelain, and would benefit tremendously from a nice help.
I agree on that.
>> >> +static int type_int, type_bool, type_bool_or_int;
>> >
>> > You can have either (no type specified, int, bool, bool-or-int) at the
>> > end. Using three independent variables does not feel right.
>> >
>> > Hint: OPTION_SET_INT.
>>
>> That definitely makes things easier, it would have been nice to see an
>> example of this; I didn't knew it was there.
>>
>> The only problem is that --bool and --int would be possible in the
>> same command and there would be no way to output an error, but I guess
>> that's not a big problem.
>
> I think that is okay.
>
>> >> + else if (do_add) {
>> >> + if (argc > 2)
>> >> + die("Too many arguments.");
>> >> + if (argc != 2)
>> >> + die("Need name value.");
>> >> + value = normalize_value(argv[0], argv[1]);
>> >> + return git_config_set_multivar(argv[0], value, "^$", 0);
>> >
>> > This part did not lose argc error checking, but...
>> >
>> >> + }
>> >> + else if (do_replace_all) {
>> >> + value = normalize_value(argv[0], argv[1]);
>> >> + return git_config_set_multivar(argv[0], value, (argc == 3 ? argv[2] : NULL), 1);
>> >
>> > You do not check argc here (nor in many "else if" below) to make sure you
>> > have sufficient number of arguments. "git config --unset" is now allowed
>> > to segfault, and "git config --unset a b c d e f" can silently ignore
>> > excess arguments for example?
>>
>> Yes the arguments check need to be revised.
>>
>> My hope was somebody would review this and suggest a clever and
>> generic way of doing this. Perhaps a util function check_min_args, or
>> maybe something in parseopt that receives the number of args?
>
> Maybe a helper, yes. Something like:
>
> static void check_argc(int argc, int min, int max) {
> if (argc >= min && argc <= max)
> return;
> fprintf(stderr, "Wrong number of arguments: %d\n", argc);
> usage_with_options(config_usage, config_options);
> }
>
> Of course, this assumes that config_usage and config_options are global...
Cool.
I've sent a new patch with this helper (a bit modified), and all the
changes Junio suggested.
I still have a few doubts:
1) --list when no config file is given uses all the config files,
wouldn't it make sense to have a --repo option?
2) --get-colorbool prints "true" or "false" only when there are two
arguments, is that correct or should stdout_is_tty be used instead?
3) should the documentation be updated for the --get-color* options to
use 'slot' instead of 'name'?
--
Felipe Contreras
next prev parent reply other threads:[~2009-02-14 12:21 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-14 2:05 [PATCH] config: Use parseopt Felipe Contreras
2009-02-14 9:28 ` Junio C Hamano
2009-02-14 9:35 ` Junio C Hamano
2009-02-14 10:41 ` Felipe Contreras
2009-02-14 10:37 ` Felipe Contreras
2009-02-14 11:40 ` Johannes Schindelin
2009-02-14 12:03 ` [PATCH v2] " Felipe Contreras
2009-02-14 15:21 ` Jeff King
2009-02-14 15:24 ` Felipe Contreras
2009-02-14 19:59 ` Johannes Schindelin
2009-02-14 20:19 ` Junio C Hamano
2009-02-14 21:08 ` human readable diffs, was " Johannes Schindelin
2009-02-14 20:31 ` Felipe Contreras
2009-02-14 22:32 ` Johannes Schindelin
2009-02-14 22:36 ` Jakub Narebski
2009-02-14 22:54 ` Johannes Schindelin
2009-02-15 9:04 ` Felipe Contreras
2009-02-15 11:26 ` Johannes Schindelin
2009-02-15 12:07 ` Felipe Contreras
2009-02-15 12:33 ` Johannes Schindelin
2009-02-15 12:51 ` Felipe Contreras
2009-02-15 13:38 ` Felipe Contreras
2009-02-15 19:31 ` Junio C Hamano
2009-02-15 19:41 ` Johannes Schindelin
2009-02-15 21:22 ` Junio C Hamano
2009-02-15 21:29 ` Johannes Schindelin
2009-02-17 0:50 ` Felipe Contreras
2009-02-15 19:36 ` Junio C Hamano
2009-02-14 12:15 ` Felipe Contreras [this message]
2009-02-14 19:11 ` [PATCH] " Johannes Schindelin
2009-02-14 19:14 ` Felipe Contreras
2009-02-14 19:24 ` Johannes Schindelin
2009-02-14 19:26 ` Johannes Schindelin
2009-02-14 21:13 ` Felipe Contreras
2009-02-14 19:29 ` Junio C Hamano
2009-02-14 20:09 ` Felipe Contreras
2009-02-14 20:35 ` Junio C Hamano
2009-02-14 21:01 ` Felipe Contreras
2009-02-14 21:10 ` Junio C Hamano
2009-02-14 21:24 ` Felipe Contreras
2009-02-14 21:15 ` Johannes Schindelin
2009-02-15 2:22 ` Junio C Hamano
2009-02-14 11:52 ` Jakub Narebski
2009-02-14 12:06 ` Felipe Contreras
2009-02-14 15:17 ` Jeff King
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=94a0d4530902140415j4168d09dh8abac0d6eba0b8cf@mail.gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).