]> git.ipfire.org Git - thirdparty/git.git/commitdiff
am, sequencer: stop parsing our own committer ident
authorJeff King <peff@peff.net>
Fri, 23 Oct 2020 07:26:30 +0000 (03:26 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Oct 2020 16:59:57 +0000 (09:59 -0700)
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>
builtin/am.c
sequencer.c
sequencer.h

index af931e588c757b877322b8b9da0383108ef273b9..b1f45eb768325f9ff82efc306a990effd488ed3f 100644 (file)
@@ -98,8 +98,6 @@ struct am_state {
        char *author_name;
        char *author_email;
        char *author_date;
-       char *committer_name;
-       char *committer_email;
        char *msg;
        size_t msg_len;
 
@@ -132,8 +130,6 @@ struct am_state {
  */
 static void am_state_init(struct am_state *state)
 {
-       const char *committer;
-       struct ident_split id;
        int gpgsign;
 
        memset(state, 0, sizeof(*state));
@@ -154,14 +150,6 @@ static void am_state_init(struct am_state *state)
 
        if (!git_config_get_bool("commit.gpgsign", &gpgsign))
                state->sign_commit = gpgsign ? "" : NULL;
-
-       committer = git_committer_info(IDENT_STRICT);
-       if (split_ident_line(&id, committer, strlen(committer)) < 0)
-               die(_("invalid committer: %s"), committer);
-       state->committer_name =
-               xmemdupz(id.name_begin, id.name_end - id.name_begin);
-       state->committer_email =
-               xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
 }
 
 /**
@@ -173,8 +161,6 @@ static void am_state_release(struct am_state *state)
        free(state->author_name);
        free(state->author_email);
        free(state->author_date);
-       free(state->committer_name);
-       free(state->committer_email);
        free(state->msg);
        argv_array_clear(&state->git_apply_opts);
 }
@@ -1594,8 +1580,9 @@ static void do_commit(const struct am_state *state)
                        IDENT_STRICT);
 
        if (state->committer_date_is_author_date)
-               committer = fmt_ident(state->committer_name,
-                                     state->committer_email, WANT_COMMITTER_IDENT,
+               committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
+                                     getenv("GIT_COMMITTER_EMAIL"),
+                                     WANT_COMMITTER_IDENT,
                                      state->ignore_date ? NULL
                                                         : state->author_date,
                                      IDENT_STRICT);
index 9dcd3db3ef9e453b76c317f1991cb44633eda285..452c571d999131285b169ac81ac6e286d1b033c4 100644 (file)
@@ -304,8 +304,6 @@ int sequencer_remove_state(struct replay_opts *opts)
                }
        }
 
-       free(opts->committer_name);
-       free(opts->committer_email);
        free(opts->gpg_sign);
        free(opts->strategy);
        for (i = 0; i < opts->xopts_nr; i++)
@@ -1458,8 +1456,8 @@ static int try_to_commit(struct repository *r,
                } else {
                        reset_ident_date();
                }
-               committer = fmt_ident(opts->committer_name,
-                                     opts->committer_email,
+               committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
+                                     getenv("GIT_COMMITTER_EMAIL"),
                                      WANT_COMMITTER_IDENT,
                                      opts->ignore_date ? NULL : date.buf,
                                      IDENT_STRICT);
@@ -4358,22 +4356,6 @@ static int commit_staged_changes(struct repository *r,
        return 0;
 }
 
-static int init_committer(struct replay_opts *opts)
-{
-       struct ident_split id;
-       const char *committer;
-
-       committer = git_committer_info(IDENT_STRICT);
-       if (split_ident_line(&id, committer, strlen(committer)) < 0)
-               return error(_("invalid committer '%s'"), committer);
-       opts->committer_name =
-               xmemdupz(id.name_begin, id.name_end - id.name_begin);
-       opts->committer_email =
-               xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
-
-       return 0;
-}
-
 int sequencer_continue(struct repository *r, struct replay_opts *opts)
 {
        struct todo_list todo_list = TODO_LIST_INIT;
@@ -4385,9 +4367,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
        if (read_populate_opts(opts))
                return -1;
        if (is_rebase_i(opts)) {
-               if (opts->committer_date_is_author_date && init_committer(opts))
-                       return -1;
-
                if ((res = read_populate_todo(r, &todo_list, opts)))
                        goto release_todo_list;
 
@@ -5264,9 +5243,6 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
 
        res = -1;
 
-       if (opts->committer_date_is_author_date && init_committer(opts))
-               goto cleanup;
-
        if (checkout_onto(r, opts, onto_name, &oid, orig_head))
                goto cleanup;
 
index 20493a2be2121c76e3e02aab14e3deff358baa94..3587878e3b6546603a6a6d18f362dd7545044d5c 100644 (file)
@@ -50,8 +50,6 @@ struct replay_opts {
 
        int mainline;
 
-       char *committer_name;
-       char *committer_email;
        char *gpg_sign;
        enum commit_msg_cleanup_mode default_msg_cleanup;
        int explicit_cleanup;