git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 1/1] config: allow giving separate author and committer idents

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 29, 2019, 23:33 UTC
Message-ID
<xmqqfttb599s.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190129230806.5295-2-williamh@gentoo.org>
William Hubbs <williamh@gentoo.org> writes:
Show 13 quoted lines
> 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.
Show 14 quoted lines
> 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(...);
Show 43 quoted lines
> -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.

Show 11 quoted lines
> 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.
Previous: William HubbsNext: Johannes Schindelin
Message 3 of 5 in “config: allow giving different author and committer idents”
  1. 0/1 config: allow giving different author and committer identsWilliam Hubbs, Jan 29, 2019
  2. 1/1 config: allow giving separate author and committer identsWilliam Hubbs, Jan 29, 2019
  3. Junio C HamanoJan 29, 2019
  4. Johannes SchindelinFeb 4, 2019
  5. Junio C HamanoFeb 4, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.