summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorLibravatar Rohit Ashiwal <rohit.ashiwal265@gmail.com>2019-11-01 19:30:00 +0530
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-11-02 15:36:23 +0900
commitcbd8db17acb77ea646c739bf96c31fe7484bc491 (patch)
tree3648b99f63cbb6aac5f5f89700f24dc7fa141d49 /sequencer.c
parentsequencer: allow callers of read_author_script() to ignore fields (diff)
downloadtgif-cbd8db17acb77ea646c739bf96c31fe7484bc491.tar.xz
rebase -i: support --committer-date-is-author-date
rebase am already has this flag to "lie" about the committer date by changing it to the author date. Let's add the same for interactive machinery. Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/sequencer.c b/sequencer.c
index b759c940f8..dfd7f2565f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -147,6 +147,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")
@@ -879,6 +880,17 @@ static char *get_author(const char *message)
return NULL;
}
+/* Returns a "date" string that needs to be free()'d by the caller */
+static char *read_author_date_or_null(void)
+{
+ char *date;
+
+ if (read_author_script(rebase_path_author_script(),
+ NULL, NULL, &date, 0))
+ return NULL;
+ return date;
+}
+
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 +950,24 @@ static int run_git_commit(struct repository *r,
cmd.git_cmd = 1;
+ if (opts->committer_date_is_author_date) {
+ int res = -1;
+ struct strbuf datebuf = STRBUF_INIT;
+ char *date = read_author_date_or_null();
+
+ if (!date)
+ return -1;
+
+ strbuf_addf(&datebuf, "@%s", date);
+ res = setenv("GIT_COMMITTER_DATE", datebuf.buf, 1);
+
+ strbuf_release(&datebuf);
+ free(date);
+
+ if (res)
+ return -1;
+ }
+
if (is_rebase_i(opts) && read_env_script(&cmd.env_array)) {
const char *gpg_opt = gpg_sign_opt_quoted(opts);
@@ -1331,7 +1361,6 @@ static int try_to_commit(struct repository *r,
if (parse_head(r, &current_head))
return -1;
-
if (flags & AMEND_MSG) {
const char *exclude_gpgsig[] = { "gpgsig", NULL };
const char *out_enc = get_commit_output_encoding();
@@ -1359,6 +1388,30 @@ static int try_to_commit(struct repository *r,
commit_list_insert(current_head, &parents);
}
+ if (opts->committer_date_is_author_date) {
+ int len = strlen(author);
+ struct ident_split ident;
+ struct strbuf date = STRBUF_INIT;
+
+ if (split_ident_line(&ident, author, len) < 0) {
+ res = error(_("malformed ident line"));
+ goto out;
+ }
+ if (!ident.date_begin) {
+ res = error(_("corrupted author without date information"));
+ goto out;
+ }
+
+ strbuf_addf(&date, "@%.*s %.*s",
+ (int)(ident.date_end - ident.date_begin), ident.date_begin,
+ (int)(ident.tz_end - ident.tz_begin), ident.tz_begin);
+ res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+ strbuf_release(&date);
+
+ if (res)
+ goto out;
+ }
+
if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
res = error(_("git write-tree failed to write a tree"));
goto out;
@@ -2480,6 +2533,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;
@@ -2562,6 +2620,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
if (opts->signoff)
write_file(rebase_path_signoff(), "--signoff\n");
+ 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", "");
@@ -3650,7 +3710,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;