From: Junio C Hamano <gitster@pobox.com>
To: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Patrick Steinhardt <ps@pks.im>,
Phillip Wood <phillip.wood123@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
ZheNing Hu <adlternative@gmail.com>
Subject: Re: [PATCH v3] commit: add --committer option
Date: Wed, 12 Nov 2025 10:56:19 -0800 [thread overview]
Message-ID: <xmqqfrajqdv0.fsf@gitster.g> (raw)
In-Reply-To: <pull.1997.v3.git.1762966535495.gitgitgadget@gmail.com> (ZheNing Hu via GitGitGadget's message of "Wed, 12 Nov 2025 16:55:35 +0000")
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +`--committer=<committer>`::
> + Override the committer for the commit. Specify an explicit committer using the
Isn't "set" or "use" more appropirate verb to use here?
We already take the committer identity from multiple plases, like
user.{name,email}, or GIT_COMMITTER_{NAME,EMAIL} configuration, and
with the patch we also take it from a command line option, with the
usual precedence order (i.e., command line trumps environment which
trumps configuration).
> -static void determine_author_info(struct strbuf *author_ident)
> +static void determine_identity(struct strbuf *ident_str, int is_author)
"is_author" does not sound grammatical for this case; if you are
giving an ident of an unknown kind to this function and supplying
another parameter to let it know which kind, "is_author" may make
sense, but not here.
As you will convert it into WANT_{AUTHOR,COMMITTER}_IDENT before
using anyway, why not let the caller use the "enum want_ident" to
tell this function what to do?
> {
> char *name, *email, *date;
> - struct ident_split author;
> -
> - name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME"));
> - email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL"));
> - date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE"));
> -
> - if (author_message) {
> - struct ident_split ident;
> + struct ident_split ident;
> + const char *env_name = is_author ? "GIT_AUTHOR_NAME" : "GIT_COMMITTER_NAME";
> + const char *env_email = is_author ? "GIT_AUTHOR_EMAIL" : "GIT_COMMITTER_EMAIL";
> + const char *env_date = is_author ? "GIT_AUTHOR_DATE" : "GIT_COMMITTER_DATE";
> + const char *force_ident = is_author ? force_author : force_committer;
> + const char *param_name = is_author ? "--author" : "--committer";
> + int ident_flag = is_author ? WANT_AUTHOR_IDENT : WANT_COMMITTER_IDENT;
> +
> + name = xstrdup_or_null(getenv(env_name));
> + email = xstrdup_or_null(getenv(env_email));
> + date = xstrdup_or_null(getenv(env_date));
> +
> + if (is_author && author_message) {
> + struct ident_split msg_ident;
> size_t len;
> const char *a;
>
> a = find_commit_header(author_message_buffer, "author", &len);
> if (!a)
> die(_("commit '%s' lacks author header"), author_message);
> - if (split_ident_line(&ident, a, len) < 0)
> + if (split_ident_line(&msg_ident, a, len) < 0)
> die(_("commit '%s' has malformed author line"), author_message);
>
> - set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
> - set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
> + set_ident_var(&name, xmemdupz(msg_ident.name_begin, msg_ident.name_end - msg_ident.name_begin));
> + set_ident_var(&email, xmemdupz(msg_ident.mail_begin, msg_ident.mail_end - msg_ident.mail_begin));
>
> - if (ident.date_begin) {
> + if (msg_ident.date_begin) {
> struct strbuf date_buf = STRBUF_INIT;
> strbuf_addch(&date_buf, '@');
> - strbuf_add(&date_buf, ident.date_begin, ident.date_end - ident.date_begin);
> + strbuf_add(&date_buf, msg_ident.date_begin, msg_ident.date_end - msg_ident.date_begin);
> strbuf_addch(&date_buf, ' ');
> - strbuf_add(&date_buf, ident.tz_begin, ident.tz_end - ident.tz_begin);
> + strbuf_add(&date_buf, msg_ident.tz_begin, msg_ident.tz_end - msg_ident.tz_begin);
> set_ident_var(&date, strbuf_detach(&date_buf, NULL));
> }
> }
The helper tries to be generic between both kinds of ident, but we
still need conditional that says "this part of the function is only
when we are looking for author", which is rather unsatisfactory.
Also why do we need this much patch noise, only because you renamed
one variable? I wonder if it would make it cleaner to move the body
of this if() {} statement into a separate helper function, leaving
only
if (whose_ident == WANT_AUTHOR_IDENT)
set_author_from_message(&name, &email, &date);
or something simple here?
next prev parent reply other threads:[~2025-11-12 18:56 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-09 10:22 [PATCH] commit: add --committer option ZheNing Hu via GitGitGadget
2025-11-10 9:24 ` Patrick Steinhardt
2025-11-10 14:17 ` ZheNing Hu
2025-11-10 17:38 ` Junio C Hamano
2025-11-11 13:19 ` ZheNing Hu
2025-11-10 16:50 ` Phillip Wood
2025-11-10 18:01 ` brian m. carlson
2025-11-10 20:11 ` Jeff King
2025-11-10 22:06 ` Junio C Hamano
2025-11-11 6:54 ` Patrick Steinhardt
2025-11-11 14:53 ` Phillip Wood
2025-11-12 16:11 ` ZheNing Hu
2025-11-11 13:42 ` ZheNing Hu
2025-11-11 19:15 ` Jeff King
2025-11-11 20:16 ` Junio C Hamano
2025-11-11 21:33 ` Jeff King
2025-11-11 21:58 ` Junio C Hamano
2025-11-11 22:23 ` Jeff King
2025-11-12 16:51 ` ZheNing Hu
2025-11-12 16:48 ` ZheNing Hu
2025-11-12 16:46 ` ZheNing Hu
2025-11-12 16:41 ` ZheNing Hu
2025-11-12 16:37 ` ZheNing Hu
2025-11-11 13:01 ` ZheNing Hu
2025-11-11 14:38 ` Phillip Wood
2025-11-12 15:58 ` ZheNing Hu
2025-11-12 17:24 ` Junio C Hamano
2025-11-15 5:29 ` ZheNing Hu
2025-11-16 1:06 ` Junio C Hamano
2025-11-17 15:06 ` ZheNing Hu
2025-11-16 22:12 ` Matej Dujava
2025-11-17 14:27 ` Phillip Wood
2025-11-17 15:18 ` ZheNing Hu
2025-11-17 15:15 ` ZheNing Hu
2025-11-10 16:56 ` [PATCH v2] " ZheNing Hu via GitGitGadget
2025-11-10 19:22 ` Junio C Hamano
2025-11-10 19:29 ` Junio C Hamano
2025-11-11 13:36 ` ZheNing Hu
2025-11-11 15:40 ` Junio C Hamano
2025-11-12 16:23 ` ZheNing Hu
2025-11-12 16:55 ` [PATCH v3] " ZheNing Hu via GitGitGadget
2025-11-12 18:56 ` Junio C Hamano [this message]
2025-11-15 6:33 ` ZheNing Hu
2025-11-15 15:43 ` [PATCH v4] " ZheNing Hu via GitGitGadget
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=xmqqfrajqdv0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=adlternative@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/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).