git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Soukaina NAIT HMID <nhsoukaina@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [add-default-config 4/5] add defaults for path/int/bool
Date: Sun, 12 Nov 2017 15:45:18 +0000	[thread overview]
Message-ID: <20171112154518.ozbbebzazhko7byl@sigill.intra.peff.net> (raw)
In-Reply-To: <0102015fb0bf3086-fe6c887d-592b-45f0-8f8e-bdbe2d18a218-000000@eu-west-1.amazonses.com>

On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:

> @@ -256,8 +258,15 @@ static int get_value(const char *key_, const char *regex_)
>  			fwrite(buf->buf, 1, buf->len, stdout);
>  		strbuf_release(buf);
>  	}
> -	free(values.items);
>  
> +	if (values.nr == 0 && default_value) {
> +		if(types == TYPE_INT || types == TYPE_BOOL || types == TYPE_BOOL_OR_INT || types == TYPE_PATH ) {
> +			char* xstr = normalize_value(key, default_value);
> +			fwrite(xstr, 1, strlen(xstr), stdout);
> +			fwrite("\n", 1, 1, stdout);
> +		}
> +	}
> +	free(values.items);

OK, this location makes more sense to me for handling --default. I think
it's still a bit lower in the function than I'd expect, though.

The loop just above the code you added is showing all of the values we
found. So I think that's the spot where'd say "we didn't find any
values; pretend like we found default_value". Including, I think, making
sure that the return value from the function is still 0. So realy right
after config_with_options() returns, I'd expect to check something like:

  if (!values.nr && default_value) {
          /* insert default_value into values list */
  }

We'd also want to use format_config(), not normalize_config(). We do
format_config() to show values, whereas normalize_config() is usually
for values we're putting into a config file (so for example TYPE_PATH
doesn't get normalized, but we would want it converted here to show the
user).

I'm also not sure that we need to check "types" as you have here.
Wouldn't we want to apply the default regardless of type, and let
format_config() handle it?

> @@ -272,6 +281,7 @@ static int get_value(const char *key_, const char *regex_)
>  	return ret;
>  }
>  
> +
>  static char *normalize_value(const char *key, const char *value)

Watch out for stray changes like this one creeping into your commits.

> diff --git a/t/t4026-color2.sh b/t/t4026-color2.sh
> deleted file mode 100755
> index 695ce9dd6f8d4..0000000000000

This part is obviously good and rectifying the problem from patch 3.
Once they're squashed together, we won't see it at all. :)

-Peff

  reply	other threads:[~2017-11-12 15:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-12 15:00 [add-default-config 1/5] add --color option to git config Soukaina NAIT HMID
2017-11-12 15:00 ` [add-default-config 5/5] fix return code on default + add tests Soukaina NAIT HMID
2017-11-12 16:04   ` Jeff King
2017-11-12 15:00 ` [add-default-config 3/5] add same test for new command format with --default and --color Soukaina NAIT HMID
2017-11-12 15:37   ` Jeff King
2017-11-12 15:00 ` [add-default-config 4/5] add defaults for path/int/bool Soukaina NAIT HMID
2017-11-12 15:45   ` Jeff King [this message]
2017-11-12 15:00 ` [add-default-config 2/5] adding default to color Soukaina NAIT HMID
2017-11-12 15:37   ` Jeff King
2017-11-13  3:40     ` Junio C Hamano
2017-11-13  3:55       ` Jeff King
2017-11-12 15:22 ` [add-default-config 1/5] add --color option to git config Jeff King
2017-11-28 21:43 ` [add-default-config] add --default " Soukaina NAIT HMID
2017-12-02 20:33   ` Philip Oakley

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=20171112154518.ozbbebzazhko7byl@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=nhsoukaina@gmail.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.
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).