git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder@ira.uka.de>
Cc: Jeff King <peff@peff.net>,
	Christian Couder <christian.couder@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCHv3 1/2] config: add '--names-only' option to list only variable names
Date: Mon, 10 Aug 2015 10:18:17 -0700	[thread overview]
Message-ID: <xmqqvbcnuko6.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1439199967-9655-2-git-send-email-szeder@ira.uka.de> ("SZEDER Gábor"'s message of "Mon, 10 Aug 2015 11:46:06 +0200")

SZEDER Gábor <szeder@ira.uka.de> writes:

> 'git config' can only show values or name-value pairs, so if a shell
> script needs the names of set config variables it has to run 'git config
> --list' or '--get-regexp' and parse the output to separate config
> variable names from their values.  However, such a parsing can't cope
> with multi-line values.  Though 'git config' can produce null-terminated
> output for newline-safe parsing, that's of no use in such a case, becase

s/becase/because/;

> shells can't cope with null characters.
>
> Even our own bash completion script suffers from these issues.
>
> Help the completion script, and shell scripts in general, by introducing
> the '--names-only' option to modify the output of '--list' and
> '--get-regexp' to list only the names of config variables, so they don't
> have to perform error-prone post processing to separate variable names
> from their values anymore.

I agree with Peff that "--names-only" has a subtle difference with
an existing and well known subcommand option and it would be a bit
irritating to remember which options is for which command.

> diff --git a/builtin/config.c b/builtin/config.c
> index 7188405f7e..307980ab50 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -13,6 +13,7 @@ static char *key;
>  static regex_t *key_regexp;
>  static regex_t *regexp;
>  static int show_keys;
> +static int omit_values;
>  static int use_key_regexp;
>  static int do_all;
>  static int do_not_match;
> ...
> @@ -91,7 +93,7 @@ static void check_argc(int argc, int min, int max) {
>  
>  static int show_all_config(const char *key_, const char *value_, void *cb)
>  {
> -	if (value_)
> +	if (!omit_values && value_)

Hmmmm.  As we have "show_keys",

	if (show_values && value_)

would be a lot more intuitive, no?

> @@ -117,6 +119,10 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
>  		strbuf_addstr(buf, key_);
>  		must_print_delim = 1;
>  	}
> +	if (omit_values) {
> +		strbuf_addch(buf, term);
> +		return 0;
> +	}

This hunk makes me wonder what the assignment to "must_print_delim"
is about.  When the code is told to show only keys and not values,
it shouldn't even have to worry about key_delim, but that assignment
is done to control exactly that.  It happens that you are lucky that
you can "return 0" early here so that the assignment does not have
any effect, but still conceptually the code structure is made ugly
by this patch.

Isn't it more like the existing "show_keys" can be replaced/enhanced
with a single "show" tri-state toggle that chooses one among:

    * show both keys and values (for --list)
    * show only keys (for your new feature)
    * show only value (for --get)

perhaps?

I see get_urlmatch() abuses show_keys variable in a strange way, and
it may not be as trivial as removing show_keys and replacing it with
a new tri-state toggle, though.

  parent reply	other threads:[~2015-08-10 17:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10  9:46 [PATCHv3 0/2] 'git config --names-only' to help the completion script SZEDER Gábor
2015-08-10  9:46 ` [PATCHv3 1/2] config: add '--names-only' option to list only variable names SZEDER Gábor
2015-08-10 13:41   ` Jeff King
2015-08-10 17:18   ` Junio C Hamano [this message]
2015-08-12 23:47     ` SZEDER Gábor
2015-08-13  1:39       ` Junio C Hamano
2015-08-20 14:14         ` [PATCH] config: restructure format_config() for better control flow SZEDER Gábor
2015-08-20 14:45           ` Jeff King
2015-08-20 14:46             ` [PATCH 1/3] format_config: don't init strbuf Jeff King
2015-08-20 14:47             ` [PATCH 2/3] format_config: simplify buffer handling Jeff King
2015-08-21 11:52               ` SZEDER Gábor
2015-08-21 17:42               ` Junio C Hamano
2015-08-21 17:43                 ` Junio C Hamano
2015-08-21 19:40                   ` Jeff King
2015-08-20 14:49             ` [PATCH 3/3] get_urlmatch: avoid useless strbuf write Jeff King
2015-08-20 20:19             ` [PATCH] config: restructure format_config() for better control flow Junio C Hamano
2015-08-10  9:46 ` [PATCHv3 2/2] completion: list variable names reliably with 'git config --names-only' SZEDER Gábor
2015-08-10 13:45   ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqvbcnuko6.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=szeder@ira.uka.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).