am, sequencer: stop parsing our own committer ident

For the --committer-date-is-author-date option of git-am and git-rebase, we format the committer ident, then re-parse it to find the name and email, and then feed those back to fmt_ident(). We can simplify this by handling it all at the time of the fmt_ident() call. We pass in the appropriate getenv() results, and if they're not present, then our WANT_COMMITTER_IDENT flag tells fmt_ident() to fill in the appropriate value from the config. Which is exactly what git_committer_ident() was doing under the hood. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 23, 2020 at 03:26 UTC 2020451c5bcc5289b8e6f25c7092d4fdb702257a
3 files changed +5 -44
builtin/am.c
+3 -16
@@ -98,8 +98,6 @@ struct am_state {
98 char *author_name;
99 char *author_email;
100 char *author_date;
101 - char *committer_name;
102 - char *committer_email;
101 char *msg;
102 size_t msg_len;
103
@@ -132,8 +130,6 @@ struct am_state {
130 */
131 static void am_state_init(struct am_state *state)
132 {
135 - const char *committer;
136 - struct ident_split id;
133 int gpgsign;
134
135 memset(state, 0, sizeof(*state));
@@ -154,14 +150,6 @@ static void am_state_init(struct am_state *state)
150
151 if (!git_config_get_bool("commit.gpgsign", &gpgsign))
152 state->sign_commit = gpgsign ? "" : NULL;
157 -
158 - committer = git_committer_info(IDENT_STRICT);
159 - if (split_ident_line(&id, committer, strlen(committer)) < 0)
160 - die(_("invalid committer: %s"), committer);
161 - state->committer_name =
162 - xmemdupz(id.name_begin, id.name_end - id.name_begin);
163 - state->committer_email =
164 - xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
153 }
154
155 /**
@@ -173,8 +161,6 @@ static void am_state_release(struct am_state *state)
161 free(state->author_name);
162 free(state->author_email);
163 free(state->author_date);
176 - free(state->committer_name);
177 - free(state->committer_email);
164 free(state->msg);
165 argv_array_clear(&state->git_apply_opts);
166 }
@@ -1594,8 +1580,9 @@ static void do_commit(const struct am_state *state)
1580 IDENT_STRICT);
1581
1582 if (state->committer_date_is_author_date)
1597 - committer = fmt_ident(state->committer_name,
1598 - state->committer_email, WANT_COMMITTER_IDENT,
1583 + committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
1584 + getenv("GIT_COMMITTER_EMAIL"),
1585 + WANT_COMMITTER_IDENT,
1586 state->ignore_date ? NULL
1587 : state->author_date,
1588 IDENT_STRICT);
sequencer.c
+2 -26
@@ -304,8 +304,6 @@ int sequencer_remove_state(struct replay_opts *opts)
304 }
305 }
306
307 - free(opts->committer_name);
308 - free(opts->committer_email);
307 free(opts->gpg_sign);
308 free(opts->strategy);
309 for (i = 0; i < opts->xopts_nr; i++)
@@ -1458,8 +1456,8 @@ static int try_to_commit(struct repository *r,
1456 } else {
1457 reset_ident_date();
1458 }
1461 - committer = fmt_ident(opts->committer_name,
1462 - opts->committer_email,
1459 + committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
1460 + getenv("GIT_COMMITTER_EMAIL"),
1461 WANT_COMMITTER_IDENT,
1462 opts->ignore_date ? NULL : date.buf,
1463 IDENT_STRICT);
@@ -4358,22 +4356,6 @@ static int commit_staged_changes(struct repository *r,
4356 return 0;
4357 }
4358
4361 -static int init_committer(struct replay_opts *opts)
4362 -{
4363 - struct ident_split id;
4364 - const char *committer;
4365 -
4366 - committer = git_committer_info(IDENT_STRICT);
4367 - if (split_ident_line(&id, committer, strlen(committer)) < 0)
4368 - return error(_("invalid committer '%s'"), committer);
4369 - opts->committer_name =
4370 - xmemdupz(id.name_begin, id.name_end - id.name_begin);
4371 - opts->committer_email =
4372 - xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
4373 -
4374 - return 0;
4375 -}
4376 -
4359 int sequencer_continue(struct repository *r, struct replay_opts *opts)
4360 {
4361 struct todo_list todo_list = TODO_LIST_INIT;
@@ -4385,9 +4367,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4367 if (read_populate_opts(opts))
4368 return -1;
4369 if (is_rebase_i(opts)) {
4388 - if (opts->committer_date_is_author_date && init_committer(opts))
4389 - return -1;
4390 -
4370 if ((res = read_populate_todo(r, &todo_list, opts)))
4371 goto release_todo_list;
4372
@@ -5264,9 +5243,6 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
5243
5244 res = -1;
5245
5267 - if (opts->committer_date_is_author_date && init_committer(opts))
5268 - goto cleanup;
5269 -
5246 if (checkout_onto(r, opts, onto_name, &oid, orig_head))
5247 goto cleanup;
5248
sequencer.h
-2
@@ -50,8 +50,6 @@ struct replay_opts {
50
51 int mainline;
52
53 - char *committer_name;
54 - char *committer_email;
53 char *gpg_sign;
54 enum commit_msg_cleanup_mode default_msg_cleanup;
55 int explicit_cleanup;