diff options
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c index 968a2d4ef3..78d09f9252 100644 --- a/sequencer.c +++ b/sequencer.c @@ -149,6 +149,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete") * command-line. */ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") +static GIT_PATH_FUNC(rebase_path_cdate_is_adate, "rebase-merge/cdate_is_adate") static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head") static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose") static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet") @@ -302,6 +303,8 @@ 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++) @@ -872,6 +875,22 @@ static char *get_author(const char *message) return NULL; } +static const char *author_date_from_env_array(const struct argv_array *env) +{ + int i; + const char *date; + + for (i = 0; i < env->argc; i++) + if (skip_prefix(env->argv[i], + "GIT_AUTHOR_DATE=", &date)) + return date; + /* + * If GIT_AUTHOR_DATE is missing we should have already errored out when + * reading the script + */ + BUG("GIT_AUTHOR_DATE missing from author script"); +} + static const char staged_changes_advice[] = N_("you have staged changes in your working tree\n" "If these changes are meant to be squashed into the previous commit, run:\n" @@ -938,6 +957,10 @@ static int run_git_commit(struct repository *r, gpg_opt, gpg_opt); } + if (opts->committer_date_is_author_date) + argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s", + author_date_from_env_array(&cmd.env_array)); + argv_array_push(&cmd.args, "commit"); if (!(flags & VERIFY_MSG)) @@ -1315,6 +1338,7 @@ static int try_to_commit(struct repository *r, struct strbuf err = STRBUF_INIT; struct strbuf commit_msg = STRBUF_INIT; char *amend_author = NULL; + const char *committer = NULL; const char *hook_commit = NULL; enum commit_msg_cleanup_mode cleanup; int res = 0; @@ -1406,10 +1430,32 @@ static int try_to_commit(struct repository *r, goto out; } - reset_ident_date(); + if (opts->committer_date_is_author_date) { + struct ident_split id; + struct strbuf date = STRBUF_INIT; + + if (split_ident_line(&id, author, (int)strlen(author)) < 0) { + res = error(_("invalid author identity '%s'"), author); + goto out; + } + if (!id.date_begin) { + res = error(_("corrupt author: missing date information")); + goto out; + } + strbuf_addf(&date, "@%.*s %.*s", + (int)(id.date_end - id.date_begin), id.date_begin, + (int)(id.tz_end - id.tz_begin), id.tz_begin); + committer = fmt_ident(opts->committer_name, + opts->committer_email, + WANT_COMMITTER_IDENT, date.buf, + IDENT_STRICT); + strbuf_release(&date); + } else { + reset_ident_date(); + } if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid, - author, NULL, opts->gpg_sign, extra)) { + author, committer, opts->gpg_sign, extra)) { res = error(_("failed to write commit object")); goto out; } @@ -2532,6 +2578,11 @@ static int read_populate_opts(struct replay_opts *opts) opts->signoff = 1; } + if (file_exists(rebase_path_cdate_is_adate())) { + opts->allow_ff = 0; + opts->committer_date_is_author_date = 1; + } + if (file_exists(rebase_path_reschedule_failed_exec())) opts->reschedule_failed_exec = 1; @@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name, write_file(rebase_path_drop_redundant_commits(), "%s", ""); if (opts->keep_redundant_commits) write_file(rebase_path_keep_redundant_commits(), "%s", ""); + if (opts->committer_date_is_author_date) + write_file(rebase_path_cdate_is_adate(), "%s", ""); if (opts->reschedule_failed_exec) write_file(rebase_path_reschedule_failed_exec(), "%s", ""); @@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r, goto leave_merge; } + if (opts->committer_date_is_author_date) + argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s", + author_date_from_env_array(&cmd.env_array)); + cmd.git_cmd = 1; argv_array_push(&cmd.args, "merge"); argv_array_push(&cmd.args, "-s"); @@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r, setenv(GIT_REFLOG_ACTION, action_name(opts), 0); if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || - opts->record_origin || opts->edit)); + opts->record_origin || opts->edit || + opts->committer_date_is_author_date)); if (read_and_refresh_cache(r, opts)) return -1; @@ -4258,6 +4316,22 @@ 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_end); + + return 0; +} + int sequencer_continue(struct repository *r, struct replay_opts *opts) { struct todo_list todo_list = TODO_LIST_INIT; @@ -4269,6 +4343,9 @@ 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; @@ -5145,6 +5222,9 @@ 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; |