Skip to content

Commit 2020451

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f35edd commit 2020451

File tree

3 files changed

+5
-44
lines changed

3 files changed

+5
-44
lines changed

builtin/am.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ struct am_state {
9898
char *author_name;
9999
char *author_email;
100100
char *author_date;
101-
char *committer_name;
102-
char *committer_email;
103101
char *msg;
104102
size_t msg_len;
105103

@@ -132,8 +130,6 @@ struct am_state {
132130
*/
133131
static void am_state_init(struct am_state *state)
134132
{
135-
const char *committer;
136-
struct ident_split id;
137133
int gpgsign;
138134

139135
memset(state, 0, sizeof(*state));
@@ -154,14 +150,6 @@ static void am_state_init(struct am_state *state)
154150

155151
if (!git_config_get_bool("commit.gpgsign", &gpgsign))
156152
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);
165153
}
166154

167155
/**
@@ -173,8 +161,6 @@ static void am_state_release(struct am_state *state)
173161
free(state->author_name);
174162
free(state->author_email);
175163
free(state->author_date);
176-
free(state->committer_name);
177-
free(state->committer_email);
178164
free(state->msg);
179165
argv_array_clear(&state->git_apply_opts);
180166
}
@@ -1594,8 +1580,9 @@ static void do_commit(const struct am_state *state)
15941580
IDENT_STRICT);
15951581

15961582
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,
15991586
state->ignore_date ? NULL
16001587
: state->author_date,
16011588
IDENT_STRICT);

sequencer.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ int sequencer_remove_state(struct replay_opts *opts)
304304
}
305305
}
306306

307-
free(opts->committer_name);
308-
free(opts->committer_email);
309307
free(opts->gpg_sign);
310308
free(opts->strategy);
311309
for (i = 0; i < opts->xopts_nr; i++)
@@ -1458,8 +1456,8 @@ static int try_to_commit(struct repository *r,
14581456
} else {
14591457
reset_ident_date();
14601458
}
1461-
committer = fmt_ident(opts->committer_name,
1462-
opts->committer_email,
1459+
committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
1460+
getenv("GIT_COMMITTER_EMAIL"),
14631461
WANT_COMMITTER_IDENT,
14641462
opts->ignore_date ? NULL : date.buf,
14651463
IDENT_STRICT);
@@ -4358,22 +4356,6 @@ static int commit_staged_changes(struct repository *r,
43584356
return 0;
43594357
}
43604358

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-
43774359
int sequencer_continue(struct repository *r, struct replay_opts *opts)
43784360
{
43794361
struct todo_list todo_list = TODO_LIST_INIT;
@@ -4385,9 +4367,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
43854367
if (read_populate_opts(opts))
43864368
return -1;
43874369
if (is_rebase_i(opts)) {
4388-
if (opts->committer_date_is_author_date && init_committer(opts))
4389-
return -1;
4390-
43914370
if ((res = read_populate_todo(r, &todo_list, opts)))
43924371
goto release_todo_list;
43934372

@@ -5264,9 +5243,6 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
52645243

52655244
res = -1;
52665245

5267-
if (opts->committer_date_is_author_date && init_committer(opts))
5268-
goto cleanup;
5269-
52705246
if (checkout_onto(r, opts, onto_name, &oid, orig_head))
52715247
goto cleanup;
52725248

sequencer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ struct replay_opts {
5050

5151
int mainline;
5252

53-
char *committer_name;
54-
char *committer_email;
5553
char *gpg_sign;
5654
enum commit_msg_cleanup_mode default_msg_cleanup;
5755
int explicit_cleanup;

0 commit comments

Comments
 (0)