git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: William Hubbs <williamh@gentoo.org>
Cc: git@vger.kernel.org, chutzpah@gentoo.org
Subject: Re: [PATCH v3 1/1] config: allow giving separate author and committer idents
Date: Tue, 29 Jan 2019 15:33:35 -0800	[thread overview]
Message-ID: <xmqqfttb599s.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190129230806.5295-2-williamh@gentoo.org> (William Hubbs's message of "Tue, 29 Jan 2019 17:08:06 -0600")

William Hubbs <williamh@gentoo.org> writes:

> diff --git a/cache.h b/cache.h
> index 009e8b3b15..375be1f68b 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -1494,10 +1494,19 @@ int date_overflows(timestamp_t date);
>  #define IDENT_STRICT	       1
>  #define IDENT_NO_DATE	       2
>  #define IDENT_NO_NAME	       4
> +
> +enum want_ident {
> +	WANT_BLANK_IDENT,
> +	WANT_AUTHOR_IDENT,
> +	WANT_COMMITTER_IDENT,

I do not recall we crossed the bridge to allow trailing comma here
at the end of enum definition.

> +};


> +extern const char *fmt_ident(const char *name, const char *email,
> +		enum want_ident whose_ident,
> +		const char *date_str, int);
> +extern const char *fmt_name(enum want_ident);

Nice interface.

> diff --git a/config.c b/config.c
> index ff521eb27a..4bd5920dea 100644
> --- a/config.c
> +++ b/config.c
> @@ -1484,6 +1484,12 @@ int git_default_config(const char *var, const char *value, void *cb)
>  		return 0;
>  	}
>  
> +	if (starts_with(var, "author."))
> +		return git_ident_config(var, value, cb);
> +
> +	if (starts_with(var, "committer."))
> +		return git_ident_config(var, value, cb);
> +

I'd rather see this done close to where "user." is already handled,
perhaps like

        -	if (starts_with(var, "user."))
        +	if (starts_with(var, "user.") ||
        +	    starts_with(var, "author.") ||
        +	    starts_with(var, "committer."))
                        return git_ident_config(...);

> -int git_ident_config(const char *var, const char *value, void *data)
> +static int set_ident(const char *var, const char *value)
>  {
> -	if (!strcmp(var, "user.useconfigonly")) {
> -		ident_use_config_only = git_config_bool(var, value);
> +	if (!strcmp(var, "author.name")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		strbuf_reset(&git_author_name);
> +		strbuf_addstr(&git_author_name, value);
> +		author_ident_explicitly_given |= IDENT_NAME_GIVEN;
> +		ident_config_given |= IDENT_NAME_GIVEN;
> +		return 0;
> +	}
> +
> +	if (!strcmp(var, "author.email")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		strbuf_reset(&git_author_email);
> +		strbuf_addstr(&git_author_email, value);
> +		author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
> +		ident_config_given |= IDENT_MAIL_GIVEN;
> +		return 0;
> +	}
> +
> +	if (!strcmp(var, "committer.name")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		strbuf_reset(&git_committer_name);
> +		strbuf_addstr(&git_committer_name, value);
> +		committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
> +		ident_config_given |= IDENT_NAME_GIVEN;
> +		return 0;
> +	}
> +
> +	if (!strcmp(var, "committer.email")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		strbuf_reset(&git_committer_email);
> +		strbuf_addstr(&git_committer_email, value);
> +		committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
> +		ident_config_given |= IDENT_MAIL_GIVEN;
>  		return 0;

So, when we see "committer.phone", git_default_config() would call
git_ident_config() which in turn would call this, and the unknown
variable is silently ignored, which is good.

> diff --git a/log-tree.c b/log-tree.c
> index 3cb14256ec..1e56df62a7 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -687,8 +687,7 @@ void show_log(struct rev_info *opt)
>  	 */
>  	if (ctx.need_8bit_cte >= 0 && opt->add_signoff)
>  		ctx.need_8bit_cte =
> -			has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
> -					       getenv("GIT_COMMITTER_EMAIL")));
> +			has_non_ascii(fmt_name(WANT_COMMITTER_IDENT));

Very nice.

  reply	other threads:[~2019-01-29 23:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 23:08 [PATCH v3 0/1] config: allow giving different author and committer idents William Hubbs
2019-01-29 23:08 ` [PATCH v3 1/1] config: allow giving separate " William Hubbs
2019-01-29 23:33   ` Junio C Hamano [this message]
2019-02-04 12:17     ` Johannes Schindelin
2019-02-04 18:57       ` 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

  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=xmqqfttb599s.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=chutzpah@gentoo.org \
    --cc=git@vger.kernel.org \
    --cc=williamh@gentoo.org \
    /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).