fixup ra/rebase-i-more-options
cover fixup ra/rebase-i-more-options
From: Phillip Wood <[email protected]>
The tests for ra/rebase-i-more-options were not as comprehensive as they could have been and some of the tests that we did have didn't do a good job of testing what they purported to. This series cleans up the tests and fixes a couple of bugs (thanks to Jonathan Nieder for reporting one of them). The bug fix reworks the code to try and make it clearer.
I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches. These are based on top of 4d924528d8 ("Revert "Merge branch 'ra/rebase-i-more-options'"", 2020-01-12) there are some conflicts when merging into pu. I had a quick look at the conflicts and they appeared to be relatively straight forward to resolve. If that impression is wrong let me know and I can rebase onto master or try doing the merge myself and pushing it to github.
Phillip Wood (6):
Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
t3433: remove loops from tests
t3433: only compare commit dates
rebase -i: fix --committer-date-is-author-date
Revert "sequencer: allow callers of read_author_script() to ignore
fields"
t3433: improve coverage
Documentation/git-rebase.txt | 27 +++- builtin/rebase.c | 49 ++++-- sequencer.c | 109 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 201 ++++++++++++++++++++++++ 7 files changed, 368 insertions(+), 25 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.sh
Signature · 1 line
2.26.0
PATCH 1/6 Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
From: Phillip Wood <[email protected]>
This reverts commit 4d924528d8bfe947abfc54ee9bd3892ab509c8cd.
This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
--- Documentation/git-rebase.txt | 27 ++++- builtin/rebase.c | 49 ++++++-- sequencer.c | 141 ++++++++++++++++++++++-- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 131 ++++++++++++++++++++++ 7 files changed, 327 insertions(+), 28 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.sh
Documentation/git-rebase.txt +21 -6
@@ -393,16 +393,31 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected. ++ +'am' backend: When applying a patch, ignore changes in whitespace in +context lines if necessary. ++ +'interactive' backend: Treat lines with only whitespace changes as +unchanged for the sake of a three-way merge. + --whitespace=<option>:: - These flag are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. + See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of recording the time the rebased commits are + created as the committer date, reuse the author date + as the committer date. This implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). +--reset-author-date:: + By default, the author date of the original commit is used + as the author date for the resulting commit. This option + tells Git to use the current timestamp instead and implies + `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.
@@ -539,10 +554,7 @@ INCOMPATIBLE OPTIONS The following options: - * --committer-date-is-author-date - * --ignore-date * --whitespace - * --ignore-whitespace * -C are incompatible with the following options:
@@ -565,6 +577,9 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --interactive * --preserve-merges and --signoff * --preserve-merges and --rebase-merges + * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +37 -12
100 lines not on this page · raw message
sequencer.c +133 -8
231 lines not on this page · raw message
sequencer.h +2 -0
@@ -43,6 +43,8 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date; +int ignore_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -2
@@ -61,8 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3433-rebase-options-compatibility.sh new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.26.0
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
Quoted 596 lines
--- Documentation/git-rebase.txt | 27 ++++- builtin/rebase.c | 49 ++++++-- sequencer.c | 141 ++++++++++++++++++++++-- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 131 ++++++++++++++++++++++ 7 files changed, 327 insertions(+), 28 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.shDocumentation/git-rebase.txt +21
-6@@ -393,16 +393,31 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected. ++ +'am' backend: When applying a patch, ignore changes in whitespace in +context lines if necessary. ++ +'interactive' backend: Treat lines with only whitespace changes as +unchanged for the sake of a three-way merge. + --whitespace=<option>:: - These flag are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. + See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of recording the time the rebased commits are + created as the committer date, reuse the author date + as the committer date. This implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). +--reset-author-date:: + By default, the author date of the original commit is used + as the author date for the resulting commit. This option + tells Git to use the current timestamp instead and implies + `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.@@ -539,10 +554,7 @@ INCOMPATIBLE OPTIONS The following options: - * --committer-date-is-author-date - * --ignore-date * --whitespace - * --ignore-whitespace * -C are incompatible with the following options:@@ -565,6 +577,9 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --interactive * --preserve-merges and --signoff * --preserve-merges and --rebase-merges + * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +37
-12@@ -79,8 +79,11 @@ struct rebase_options {int allow_rerere_autoupdate;int keep_empty;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -99,6 +102,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -112,10 +116,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.allow_empty_message = opts->allow_empty_message; replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf); + +strbuf_release (&strategy_buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto);@@ -517,6 +531,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -970,6 +986,12 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1437,16 +1459,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,@@ -1719,11 +1742,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) state_dir_base, cmd_live_rebase, buf.buf); } +if (options.committer_date_is_author_date || + options.ignore_date) + options.flags |=REBASE_FORCE ; +for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) options.flags |=REBASE_FORCE ;else if (skip_prefix (option,"-C" , &p)) {sequencer.c +133
-8@@ -147,6 +147,8 @@ 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") +staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -823,9 +825,19 @@ int read_author_script(const char *path, char **name, char **email, char **date,error (_ ("missing 'GIT_AUTHOR_DATE'" ));if (date_i <0 || email_i <0 || date_i <0 || err) goto finish; - *name = kv.items[name_i].util; - *email = kv.items[email_i].util; - *date = kv.items[date_i].util; + +if (name) + *name = kv.items[name_i].util; +else +free (kv.items[name_i].util); +if (email) + *email = kv.items[email_i].util; +else +free (kv.items[email_i].util); +if (date) + *date = kv.items[date_i].util; +else +free (kv.items[date_i].util); retval =0 ; finish:string_list_clear (&kv, !!retval);@@ -868,6 +880,47 @@ 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; +} + +/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author); +struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line" )); +return NULL ; + } + len = ident.mail_end - ident.name_begin +1 ; + +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} + +static void push_dates (struct child_process *child,int change_committer_date) +{ +time_t now =time (NULL ); +struct strbuf date =STRBUF_INIT ; + +strbuf_addf (&date,"@%" PRIuMAX, (uintmax_t )now); +argv_array_pushf (&child->env_array,"GIT_AUTHOR_DATE=%s" , date.buf); +if (change_committer_date) +argv_array_pushf (&child->env_array,"GIT_COMMITTER_DATE=%s" , date.buf); +strbuf_release (&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"@@ -927,6 +980,25 @@ 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" , + opts->ignore_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);@@ -942,6 +1014,8 @@ static int run_git_commit(struct repository *r,argv_array_push (&cmd.args,"--amend" );if (opts->gpg_sign)argv_array_pushf (&cmd.args,"-S%s" , opts->gpg_sign); +if (opts->ignore_date) +push_dates (&cmd, opts->committer_date_is_author_date);if (defmsg)argv_array_pushl (&cmd.args,"-F" , defmsg,NULL );else if (!(flags &EDIT_MSG ))@@ -1310,14 +1384,13 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;if (parse_head (r, ¤t_head))return -1 ; -if (flags &AMEND_MSG ) {const char *exclude_gpgsig[] = {"gpgsig" ,NULL };const char *out_enc =get_commit_output_encoding ();@@ -1332,7 +1405,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));@@ -1345,6 +1418,31 @@ 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" , + opts->ignore_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;@@ -1404,6 +1502,15 @@ static int try_to_commit(struct repository *r,reset_ident_date (); +if (opts->ignore_date) { + author =ignore_author_date (author); +if (!author) { + res =-1 ; + goto out; + } +free (author_to_free); + author_to_free = (char *)author; + }if (commit_tree_extended (msg->buf, msg->len, &tree, parents, oid, author, opts->gpg_sign, extra)) { res =error (_ ("failed to write commit object" ));@@ -1424,7 +1531,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }@@ -2492,6 +2599,16 @@ 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_ignore_date ())) { + opts->allow_ff =0 ; + opts->ignore_date =1 ; + } +if (file_exists (rebase_path_reschedule_failed_exec ())) opts->reschedule_failed_exec =1 ;@@ -2574,6 +2691,10 @@ 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->ignore_date) +write_file (rebase_path_ignore_date (),"%s" ,"" );if (opts->reschedule_failed_exec)write_file (rebase_path_reschedule_failed_exec (),"%s" ,"" );@@ -3514,6 +3635,8 @@ static int do_merge(struct repository *r,argv_array_push (&cmd.args,git_path_merge_msg (r));if (opts->gpg_sign)argv_array_push (&cmd.args, opts->gpg_sign); +if (opts->ignore_date) +push_dates (&cmd, opts->committer_date_is_author_date);/* Add the tips to be merged */ for (j = to_merge; j; j = j->next)@@ -3786,7 +3909,9 @@ 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 || + opts->ignore_date));if (read_and_refresh_cache (r, opts))return -1 ;sequencer.h +2
-0@@ -43,6 +43,8 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date; +int ignore_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-2@@ -61,8 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3433-rebase-options-compatibility.sh new file +131
-1@@ -0,0 +1,131 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && + + git checkout --orphan master && + git rm --cached foo && + rm foo && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with am backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase main side && + git rebase --abort && + git rebase --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace works with interactive backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--committer-date-is-author-date works with am backend' ' + git commit --amend && + git rebase --committer-date-is-author-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + git show HEAD --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with interactive backend' ' + git commit --amend && + git rebase -i --committer-date-is-author-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + git show HEAD --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + git rev-list HEAD >rev_list && + while read HASH + do + git show $HASH --pretty="format:%ai" >authortime + git show $HASH --pretty="format:%ci" >committertime + test_cmp authortime committertime + done <rev_list +' + +# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with am backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works with interactive backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date -i HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works with rebase -r' ' + git checkout side && + git merge --no-ff commit3 && + git rebase -r --root --ignore-date && + git rev-list HEAD >rev_list && + while read HASH + do + git show $HASH --pretty="format:%ai" >authortime + grep "+0000" authortime + done <rev_list +' + +test_done --2.26.0
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Hi Elijah
Quoted 4 lines · Elijah Newren
Quoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 4 lines
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
I wasn't sure what to do for the best, this seemed to be reasonable (originally I just based the patches on top of ra/rebase-i-more-options but then they would be a pain to merge into pu because of the revert) but if Junio has other ideas I'm happy to re-roll
Thanks for taking a look at this series
Phillip
Quoted 596 lines
Quoted 596 lines
--- Documentation/git-rebase.txt | 27 ++++- builtin/rebase.c | 49 ++++++-- sequencer.c | 141 ++++++++++++++++++++++-- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 131 ++++++++++++++++++++++ 7 files changed, 327 insertions(+), 28 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.shDocumentation/git-rebase.txt +21
-6@@ -393,16 +393,31 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected. ++ +'am' backend: When applying a patch, ignore changes in whitespace in +context lines if necessary. ++ +'interactive' backend: Treat lines with only whitespace changes as +unchanged for the sake of a three-way merge. + --whitespace=<option>:: - These flag are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. + See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of recording the time the rebased commits are + created as the committer date, reuse the author date + as the committer date. This implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). +--reset-author-date:: + By default, the author date of the original commit is used + as the author date for the resulting commit. This option + tells Git to use the current timestamp instead and implies + `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.@@ -539,10 +554,7 @@ INCOMPATIBLE OPTIONS The following options: - * --committer-date-is-author-date - * --ignore-date * --whitespace - * --ignore-whitespace * -C are incompatible with the following options:@@ -565,6 +577,9 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --interactive * --preserve-merges and --signoff * --preserve-merges and --rebase-merges + * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +37
-12@@ -79,8 +79,11 @@ struct rebase_options {int allow_rerere_autoupdate;int keep_empty;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -99,6 +102,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -112,10 +116,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.allow_empty_message = opts->allow_empty_message; replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf); + +strbuf_release (&strategy_buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto);@@ -517,6 +531,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -970,6 +986,12 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1437,16 +1459,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,@@ -1719,11 +1742,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) state_dir_base, cmd_live_rebase, buf.buf); } +if (options.committer_date_is_author_date || + options.ignore_date) + options.flags |=REBASE_FORCE ; +for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) options.flags |=REBASE_FORCE ;else if (skip_prefix (option,"-C" , &p)) {sequencer.c +133
-8@@ -147,6 +147,8 @@ 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") +staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -823,9 +825,19 @@ int read_author_script(const char *path, char **name, char **email, char **date,error (_ ("missing 'GIT_AUTHOR_DATE'" ));if (date_i <0 || email_i <0 || date_i <0 || err) goto finish; - *name = kv.items[name_i].util; - *email = kv.items[email_i].util; - *date = kv.items[date_i].util; + +if (name) + *name = kv.items[name_i].util; +else +free (kv.items[name_i].util); +if (email) + *email = kv.items[email_i].util; +else +free (kv.items[email_i].util); +if (date) + *date = kv.items[date_i].util; +else +free (kv.items[date_i].util); retval =0 ; finish:string_list_clear (&kv, !!retval);@@ -868,6 +880,47 @@ 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; +} + +/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author); +struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line" )); +return NULL ; + } + len = ident.mail_end - ident.name_begin +1 ; + +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} + +static void push_dates (struct child_process *child,int change_committer_date) +{ +time_t now =time (NULL ); +struct strbuf date =STRBUF_INIT ; + +strbuf_addf (&date,"@%" PRIuMAX, (uintmax_t )now); +argv_array_pushf (&child->env_array,"GIT_AUTHOR_DATE=%s" , date.buf); +if (change_committer_date) +argv_array_pushf (&child->env_array,"GIT_COMMITTER_DATE=%s" , date.buf); +strbuf_release (&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"@@ -927,6 +980,25 @@ 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" , + opts->ignore_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);@@ -942,6 +1014,8 @@ static int run_git_commit(struct repository *r,argv_array_push (&cmd.args,"--amend" );if (opts->gpg_sign)argv_array_pushf (&cmd.args,"-S%s" , opts->gpg_sign); +if (opts->ignore_date) +push_dates (&cmd, opts->committer_date_is_author_date);if (defmsg)argv_array_pushl (&cmd.args,"-F" , defmsg,NULL );else if (!(flags &EDIT_MSG ))@@ -1310,14 +1384,13 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;if (parse_head (r, ¤t_head))return -1 ; -if (flags &AMEND_MSG ) {const char *exclude_gpgsig[] = {"gpgsig" ,NULL };const char *out_enc =get_commit_output_encoding ();@@ -1332,7 +1405,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));@@ -1345,6 +1418,31 @@ 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" , + opts->ignore_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;@@ -1404,6 +1502,15 @@ static int try_to_commit(struct repository *r,reset_ident_date (); +if (opts->ignore_date) { + author =ignore_author_date (author); +if (!author) { + res =-1 ; + goto out; + } +free (author_to_free); + author_to_free = (char *)author; + }if (commit_tree_extended (msg->buf, msg->len, &tree, parents, oid, author, opts->gpg_sign, extra)) { res =error (_ ("failed to write commit object" ));@@ -1424,7 +1531,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }@@ -2492,6 +2599,16 @@ 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_ignore_date ())) { + opts->allow_ff =0 ; + opts->ignore_date =1 ; + } +if (file_exists (rebase_path_reschedule_failed_exec ())) opts->reschedule_failed_exec =1 ;@@ -2574,6 +2691,10 @@ 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->ignore_date) +write_file (rebase_path_ignore_date (),"%s" ,"" );if (opts->reschedule_failed_exec)write_file (rebase_path_reschedule_failed_exec (),"%s" ,"" );@@ -3514,6 +3635,8 @@ static int do_merge(struct repository *r,argv_array_push (&cmd.args,git_path_merge_msg (r));if (opts->gpg_sign)argv_array_push (&cmd.args, opts->gpg_sign); +if (opts->ignore_date) +push_dates (&cmd, opts->committer_date_is_author_date);/* Add the tips to be merged */ for (j = to_merge; j; j = j->next)@@ -3786,7 +3909,9 @@ 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 || + opts->ignore_date));if (read_and_refresh_cache (r, opts))return -1 ;sequencer.h +2
-0@@ -43,6 +43,8 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date; +int ignore_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-2@@ -61,8 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3433-rebase-options-compatibility.sh new file +131
-1@@ -0,0 +1,131 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && + + git checkout --orphan master && + git rm --cached foo && + rm foo && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with am backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase main side && + git rebase --abort && + git rebase --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace works with interactive backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--committer-date-is-author-date works with am backend' ' + git commit --amend && + git rebase --committer-date-is-author-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + git show HEAD --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with interactive backend' ' + git commit --amend && + git rebase -i --committer-date-is-author-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + git show HEAD --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + git rev-list HEAD >rev_list && + while read HASH + do + git show $HASH --pretty="format:%ai" >authortime + git show $HASH --pretty="format:%ci" >committertime + test_cmp authortime committertime + done <rev_list +' + +# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with am backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works with interactive backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date -i HEAD^ && + git show HEAD --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works with rebase -r' ' + git checkout side && + git merge --no-ff commit3 && + git rebase -r --root --ignore-date && + git rev-list HEAD >rev_list && + while read HASH + do + git show $HASH --pretty="format:%ai" >authortime + grep "+0000" authortime + done <rev_list +' + +test_done --2.26.0
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
In reply to Elijah NewrenQuoted 4 lines · Elijah Newren
Quoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 4 lines
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
Nah, there isn't much to become unhappy about.
I however suspect that the alternative would certainly be much nicer and easier to understand, which is to rebuild the 7-patch series c58ae96fc4..d82dfa7f5b but bugs already fixed, instead of doing this patch to take us back to a known buggy state and then fix the result with 5 more patches. Is that what you meant?
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Quoted 15 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren
Quoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 4 lines
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
Quoted 7 lines
Nah, there isn't much to become unhappy about.
I however suspect that the alternative would certainly be much nicer and easier to understand, which is to rebuild the 7-patch series
c58ae96fc4..d82dfa7f5bbut bugs already fixed, instead of doing this patch to take us back to a known buggy state and then fix the result with 5 more patches. Is that what you meant?
After looking at the conflict resolution while merging the result of applying these patches on top of the older codebase, I would have to say that the approach """I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches.""" may not have been particularly a brilliant idea, not because the conflicts arising from an older codebase are unpleasant to resolve (they seem to be reasonably contained), but because it resurrects other unwanted cruft we have cleaned up since then, and worse yet, it does so without triggering conflicts. For example, we'll end up seeing mentions of "'am' backend", which have all been updated to "'apply' backend", in the documentation, and patches [2-6/6] do not fix them.
[5/6] is an example of one more "unwanted" thing the reversion resurrects that needed to be fixed, I guess?
The result of applying all these patches and merging it to 'master' and/or 'pu' may be more or less right, as far as the new features added to the "rebase -i" by the series are concerned but there may be many small "unwanted cruft" we may be resurrecting with [1/6], so...
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Hi Phillip, Elijah & Junio,
Quoted 37 lines · Junio C Hamano
Quoted 15 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren
Quoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 4 lines
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
Quoted 7 lines
Nah, there isn't much to become unhappy about.
I however suspect that the alternative would certainly be much nicer and easier to understand, which is to rebuild the 7-patch series
c58ae96fc4..d82dfa7f5bbut bugs already fixed, instead of doing this patch to take us back to a known buggy state and then fix the result with 5 more patches. Is that what you meant?After looking at the conflict resolution while merging the result of applying these patches on top of the older codebase, I would have to say that the approach """I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches.""" may not have been particularly a brilliant idea, not because the conflicts arising from an older codebase are unpleasant to resolve (they seem to be reasonably contained), but because it resurrects other unwanted cruft we have cleaned up since then, and worse yet, it does so without triggering conflicts. For example, we'll end up seeing mentions of "'am' backend", which have all been updated to "'apply' backend", in the documentation, and patches [2-6/6] do not fix them.
Quoted 8 lines
[5/6] is an example of one more "unwanted" thing the reversion resurrects that needed to be fixed, I guess?
The result of applying all these patches and merging it to 'master' and/or 'pu' may be more or less right, as far as the new features added to the "rebase -i" by the series are concerned but there may be many small "unwanted cruft" we may be resurrecting with [1/6], so...
I agree that it would make for a much nicer read if the entire patch series was simply rebased on top of v2.26.0, with drops instead of reverts. I suspect that 4/6 will not even become a fixup, but that the resulting patch is really more of an Initial-patch-by: Rohit material with Phillip as the author on record.
As to the changes, I had a brief look over them, and I have nothing to add to Elijah's review except to stress how excited I am about the increased test coverage. From my perspective, this makes the patch series 10x better.
Thanks,
Dscho
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Hi All
Quoted 56 lines · Johannes Schindelin
Hi Phillip, Elijah & Junio,
Quoted 37 lines · Junio C Hamano
Quoted 15 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren
Quoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 4 lines
This reverts commit
4d924528d8bfe947abfc54ee9bd3892ab509c8cd.This is being reverted to enable some fixups for ra/rebase-i-more-options to be built on this commit.
This makes sense to me, but it will be only the second 'Revert "Revert..."' commit in all of git.git and I'm curious if Junio will be unhappy with it.
Quoted 7 lines
Nah, there isn't much to become unhappy about.
I however suspect that the alternative would certainly be much nicer and easier to understand, which is to rebuild the 7-patch series
c58ae96fc4..d82dfa7f5bbut bugs already fixed, instead of doing this patch to take us back to a known buggy state and then fix the result with 5 more patches. Is that what you meant?After looking at the conflict resolution while merging the result of applying these patches on top of the older codebase, I would have to say that the approach """I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches.""" may not have been particularly a brilliant idea, not because the conflicts arising from an older codebase are unpleasant to resolve (they seem to be reasonably contained), but because it resurrects other unwanted cruft we have cleaned up since then, and worse yet, it does so without triggering conflicts. For example, we'll end up seeing mentions of "'am' backend", which have all been updated to "'apply' backend", in the documentation, and patches [2-6/6] do not fix them.
Quoted 8 lines
[5/6] is an example of one more "unwanted" thing the reversion resurrects that needed to be fixed, I guess?
The result of applying all these patches and merging it to 'master' and/or 'pu' may be more or less right, as far as the new features added to the "rebase -i" by the series are concerned but there may be many small "unwanted cruft" we may be resurrecting with [1/6], so...
I agree that it would make for a much nicer read if the entire patch series was simply rebased on top of v2.26.0, with drops instead of reverts. I suspect that 4/6 will not even become a fixup, but that the resulting patch is really more of an
Initial-patch-by: Rohitmaterial with Phillip as the author on record.
Quoted 4 lines
As to the changes, I had a brief look over them, and I have nothing to add to Elijah's review except to stress how excited I am about the increased test coverage. From my perspective, this makes the patch series 10x better.
Thanks for all your feedback, I'll reroll as a new patch series based on master
Best Wishes
Phillip
Quoted 3 lines
Thanks,
Dscho
Re: [PATCH 1/6] Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
Quoted 6 lines · Phillip Wood
Quoted 6 lines
I agree that it would make for a much nicer read if the entire patch series was simply rebased on top of v2.26.0, with drops instead of reverts. I suspect that 4/6 will not even become a fixup, but that the resulting patch is really more of an
Initial-patch-by: Rohitmaterial with Phillip as the author on record.
Quoted 7 lines
Quoted 4 lines
As to the changes, I had a brief look over them, and I have nothing to add to Elijah's review except to stress how excited I am about the increased test coverage. From my perspective, this makes the patch series 10x better.
Thanks for all your feedback, I'll reroll as a new patch series based on master
Thanks, all.
PATCH 2/6 t3433: remove loops from tests
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Looping inside a test is asking for trouble as we only detect any failure on the last iteration. Instead get all the dates at once which is also more efficient. Note the previous code accidentally compared the diffs as well as the dates this is fixed as well.
--- t/t3433-rebase-options-compatibility.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
t/t3433-rebase-options-compatibility.sh +5 -13
@@ -90,13 +90,9 @@ test_expect_success '--committer-date-is-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && git rebase -r --root --committer-date-is-author-date && - git rev-list HEAD >rev_list && - while read HASH - do - git show $HASH --pretty="format:%ai" >authortime - git show $HASH --pretty="format:%ci" >committertime - test_cmp authortime committertime - done <rev_list + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime ' # Checking for +0000 in author time is enough since default
@@ -120,12 +116,8 @@ test_expect_success '--ignore-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && git rebase -r --root --ignore-date && - git rev-list HEAD >rev_list && - while read HASH - do - git show $HASH --pretty="format:%ai" >authortime - grep "+0000" authortime - done <rev_list + git log --pretty=%ai >authortime && + ! grep -v "+0000" authortime ' test_done
Signature · 1 line
2.26.0
Re: [PATCH 2/6] t3433: remove loops from tests
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Looping inside a test is asking for trouble as we only detect any failure on the last iteration. Instead get all the dates at once which is also more efficient. Note the previous code accidentally compared the diffs as well as the dates this is fixed as well.
Add a semicolon between "dates" and "this" in the last sentence?
Quoted 30 lines
Signed-off-by Phillip Wood <[email protected]>--- t/t3433-rebase-options-compatibility.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)t/t3433-rebase-options-compatibility.sh +3
-7@@ -90,13 +90,9 @@ test_expect_success '--committer-date-is-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && git rebase -r --root --committer-date-is-author-date && - git rev-list HEAD >rev_list && - while read HASH - do - git show $HASH --pretty="format:%ai" >authortime - git show $HASH --pretty="format:%ci" >committertime - test_cmp authortime committertime - done <rev_list + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime ' # Checking for +0000 in author time is enough since default@@ -120,12 +116,8 @@ test_expect_success '--ignore-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 &&
t/t3433-rebase-options-compatibility.sh test_expect_success '--ignore-date works with rebase -r' ' · line 121
Quoted 10 lines
t/t3433-rebase-options-compatibility.sh +2
-6git rebase -r --root --ignore-date && - git rev-list HEAD >rev_list && - while read HASH - do - git show $HASH --pretty="format:%ai" >authortime - grep "+0000" authortime - done <rev_list + git log --pretty=%ai >authortime && + ! grep -v "+0000" authortime '
The new form is much more readable (and more correct and efficient, as you point out). Thanks.
PATCH 3/6 t3433: only compare commit dates
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
git show shows the diff by default so these tests which are about checking dates were also comparing the diffs. Fix that by switching to git log -1
--- t/t3433-rebase-options-compatibility.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
t/t3433-rebase-options-compatibility.sh +6 -6
@@ -73,16 +73,16 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' test_expect_success '--committer-date-is-author-date works with am backend' ' git commit --amend && git rebase --committer-date-is-author-date HEAD^ && - git show HEAD --pretty="format:%ai" >authortime && - git show HEAD --pretty="format:%ci" >committertime && + git log -1 --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ci" >committertime && test_cmp authortime committertime ' test_expect_success '--committer-date-is-author-date works with interactive backend' ' git commit --amend && git rebase -i --committer-date-is-author-date HEAD^ && - git show HEAD --pretty="format:%ai" >authortime && - git show HEAD --pretty="format:%ci" >committertime && + git log -1 --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ci" >committertime && test_cmp authortime committertime '
@@ -101,14 +101,14 @@ test_expect_success '--committer-date-is-author-date works with rebase -r' ' test_expect_success '--ignore-date works with am backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && git rebase --ignore-date HEAD^ && - git show HEAD --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime ' test_expect_success '--ignore-date works with interactive backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && git rebase --ignore-date -i HEAD^ && - git show HEAD --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime '
Signature · 1 line
2.26.0
PATCH 4/6 rebase -i: fix --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Johanathan Nieder reported that rebase --committer-date-is-author-date failed with the error "invalid date format: @@2592000 +0000" when the backend was switched to use the sequencer [1]. This is because when we read the date from the author script file is already prefixed by '@' so we do not need to add one. This did not show up in our tests because once match_object_header_date() fails to match because of the extra '@' parse_date_basic() strips the prefix and a date with more than 8 digits is parsed as a number of seconds by match_digit().
While fixing this I also noticed that we were not setting GIT_COMMITTER_DATE in the environment when forking git merge. This was untested. The tests we did have used commits where the author date was the same as the current value $GIT_COMMITTER_DATE in the environment so they did not test that we were actually using the author date when creating the commit.
As we have already read GIT_AUTHOR_DATE into cmd.env_array we now use that rather than re-reading the author-script file. I've moved the code that handles opts->ignore date so that all the code setting the child environment is together and changed it so we no longer set GIT_COMMITTER_DATE twice when --ignore-date is combined with --committer-date-is-author-date.
[1] https://lore.kernel.org/git/<[email protected]>
--- sequencer.c | 68 ++++++++++--------------- t/t3433-rebase-options-compatibility.sh | 29 +++++++++-- 2 files changed, 52 insertions(+), 45 deletions(-)
sequencer.c +26 -42
@@ -880,17 +880,6 @@ 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; -} -/* Construct a free()able author string with current time as the author date */ static char *ignore_author_date (const char *author) {
@@ -909,16 +898,20 @@ static char *ignore_author_date(const char *author)return strbuf_detach (&new_author,NULL ); } -static void push_dates (struct child_process *child,int change_committer_date) +static const char *author_date_from_env_array (const struct argv_array *env) { -time_t now =time (NULL ); -struct strbuf date =STRBUF_INIT ; +int i; +const char *date; -strbuf_addf (&date,"@%" PRIuMAX, (uintmax_t )now); -argv_array_pushf (&child->env_array,"GIT_AUTHOR_DATE=%s" , date.buf); -if (change_committer_date) -argv_array_pushf (&child->env_array,"GIT_COMMITTER_DATE=%s" , date.buf); -strbuf_release (&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[] =
@@ -980,31 +973,19 @@ 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" , - opts->ignore_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);return error (_ (staged_changes_advice), gpg_opt, gpg_opt); } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );argv_array_push (&cmd.args,"commit" );
@@ -1014,8 +995,6 @@ static int run_git_commit(struct repository *r,argv_array_push (&cmd.args,"--amend" );if (opts->gpg_sign)argv_array_pushf (&cmd.args,"-S%s" , opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);if (defmsg)argv_array_pushl (&cmd.args,"-F" , defmsg,NULL );else if (!(flags &EDIT_MSG ))
@@ -3615,6 +3594,13 @@ static int do_merge(struct repository *r, ret =error (_ (staged_changes_advice), gpg_opt, gpg_opt); goto leave_merge; } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" ); cmd.git_cmd =1 ;argv_array_push (&cmd.args,"merge" );
@@ -3635,8 +3621,6 @@ static int do_merge(struct repository *r,argv_array_push (&cmd.args,git_path_merge_msg (r));if (opts->gpg_sign)argv_array_push (&cmd.args, opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);/* Add the tips to be merged */ for (j = to_merge; j; j = j->next)
t/t3433-rebase-options-compatibility.sh +26 -3
@@ -71,15 +71,15 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' ' test_expect_success '--committer-date-is-author-date works with am backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime && test_cmp authortime committertime ' test_expect_success '--committer-date-is-author-date works with interactive backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase -i --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime &&
@@ -88,13 +88,36 @@ test_expect_success '--committer-date-is-author-date works with interactive back test_expect_success '--committer-date-is-author-date works with rebase -r' ' git checkout side && - git merge --no-ff commit3 && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && git rebase -r --root --committer-date-is-author-date && git log --pretty="format:%ai" >authortime && git log --pretty="format:%ci" >committertime && test_cmp authortime committertime ' +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -i --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530.
Signature · 1 line
2.26.0
Re: [PATCH 4/6] rebase -i: fix --committer-date-is-author-date
Quoted 67 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Johanathan Nieder reported that
rebase --committer-date-is-author-datefailed with the error "invalid date format: @@2592000 +0000" when the backend was switched to use the sequencer [1]. This is because when we read the date from the author script file is already prefixed by '@' so we do not need to add one. This did not show up in our tests because oncematch_object_header_date()fails to match because of the extra '@'parse_date_basic()strips the prefix and a date with more than 8 digits is parsed as a number of seconds bymatch_digit().While fixing this I also noticed that we were not setting
GIT_COMMITTER_DATEin the environment when forkinggit merge. This was untested. The tests we did have used commits where the author date was the same as the current value $GIT_COMMITTER_DATE in the environment so they did not test that we were actually using the author date when creating the commit.As we have already read
GIT_AUTHOR_DATEinto cmd.env_array we now use that rather than re-reading the author-script file. I've moved the code that handlesopts->ignoredate so that all the code setting the child environment is together and changed it so we no longer setGIT_COMMITTER_DATEtwice when --ignore-date is combined with --committer-date-is-author-date.[1] https://lore.kernel.org/git/<[email protected]>
Signed-off-by Phillip Wood <[email protected]>--- sequencer.c | 68 ++++++++++--------------- t/t3433-rebase-options-compatibility.sh | 29 +++++++++-- 2 files changed, 52 insertions(+), 45 deletions(-)sequencer.c +3
-14@@ -880,17 +880,6 @@ 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; -} -/* Construct a free()able author string with current time as the author date */ static char *ignore_author_date (const char *author) {@@ -909,16 +898,20 @@ static char *ignore_author_date(const char *author)return strbuf_detach (&new_author,NULL ); } -static void push_dates (struct child_process *child,int change_committer_date) +static const char *author_date_from_env_array (const struct argv_array *env) { -time_t now =time (NULL ); -struct strbuf date =STRBUF_INIT ; +int i; +const char *date;
sequencer.c static char *ignore_author_date(const char *author) · line 909
Quoted 10 lines
sequencer.c +4
-5-strbuf_addf (&date,"@%" PRIuMAX, (uintmax_t )now); -argv_array_pushf (&child->env_array,"GIT_AUTHOR_DATE=%s" , date.buf); -if (change_committer_date) -argv_array_pushf (&child->env_array,"GIT_COMMITTER_DATE=%s" , date.buf); -strbuf_release (&date); +for (i =0 ; i < env->argc; i++) +if (skip_prefix (env->argv[i], +"GIT_AUTHOR_DATE=" , &date)) +return date;
Is there any risk that GIT_AUTHOR_DATE=<somedate> will appear twice in @child->env_array ? If there is, should we read through the whole list to make sure we take the last one?
Quoted 142 lines
sequencer.c +19
-23+/* +* 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[] =@@ -980,31 +973,19 @@ 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" , - opts->ignore_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);return error (_ (staged_changes_advice), gpg_opt, gpg_opt); } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );argv_array_push (&cmd.args,"commit" );@@ -1014,8 +995,6 @@ static int run_git_commit(struct repository *r,argv_array_push (&cmd.args,"--amend" );if (opts->gpg_sign)argv_array_pushf (&cmd.args,"-S%s" , opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);if (defmsg)argv_array_pushl (&cmd.args,"-F" , defmsg,NULL );else if (!(flags &EDIT_MSG ))@@ -3615,6 +3594,13 @@ static int do_merge(struct repository *r, ret =error (_ (staged_changes_advice), gpg_opt, gpg_opt); goto leave_merge; } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" ); cmd.git_cmd =1 ;argv_array_push (&cmd.args,"merge" );@@ -3635,8 +3621,6 @@ static int do_merge(struct repository *r,argv_array_push (&cmd.args,git_path_merge_msg (r));if (opts->gpg_sign)argv_array_push (&cmd.args, opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);/* Add the tips to be merged */ for (j = to_merge; j; j = j->next)t/t3433-rebase-options-compatibility.sh +26
-4@@ -71,15 +71,15 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' ' test_expect_success '--committer-date-is-author-date works with am backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime && test_cmp authortime committertime ' test_expect_success '--committer-date-is-author-date works with interactive backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase -i --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime &&@@ -88,13 +88,36 @@ test_expect_success '--committer-date-is-author-date works with interactive back test_expect_success '--committer-date-is-author-date works with rebase -r' ' git checkout side && - git merge --no-ff commit3 && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && git rebase -r --root --committer-date-is-author-date && git log --pretty="format:%ai" >authortime && git log --pretty="format:%ci" >committertime && test_cmp authortime committertime ' +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -i --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530. --2.26.0
Re: [PATCH 4/6] rebase -i: fix --committer-date-is-author-date
Hi Elijah
Quoted 69 lines · Elijah Newren
Quoted 68 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Johanathan Nieder reported that
rebase --committer-date-is-author-datefailed with the error "invalid date format: @@2592000 +0000" when the backend was switched to use the sequencer [1]. This is because when we read the date from the author script file is already prefixed by '@' so we do not need to add one. This did not show up in our tests because oncematch_object_header_date()fails to match because of the extra '@'parse_date_basic()strips the prefix and a date with more than 8 digits is parsed as a number of seconds bymatch_digit().While fixing this I also noticed that we were not setting
GIT_COMMITTER_DATEin the environment when forkinggit merge. This was untested. The tests we did have used commits where the author date was the same as the current value $GIT_COMMITTER_DATE in the environment so they did not test that we were actually using the author date when creating the commit.As we have already read
GIT_AUTHOR_DATEinto cmd.env_array we now use that rather than re-reading the author-script file. I've moved the code that handlesopts->ignoredate so that all the code setting the child environment is together and changed it so we no longer setGIT_COMMITTER_DATEtwice when --ignore-date is combined with --committer-date-is-author-date.[1] https://lore.kernel.org/git/<[email protected]>
Signed-off-by Phillip Wood <[email protected]>--- sequencer.c | 68 ++++++++++--------------- t/t3433-rebase-options-compatibility.sh | 29 +++++++++-- 2 files changed, 52 insertions(+), 45 deletions(-)sequencer.c +3
-14@@ -880,17 +880,6 @@ 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; -} -/* Construct a free()able author string with current time as the author date */ static char *ignore_author_date (const char *author) {@@ -909,16 +898,20 @@ static char *ignore_author_date(const char *author)return strbuf_detach (&new_author,NULL ); } -static void push_dates (struct child_process *child,int change_committer_date) +static const char *author_date_from_env_array (const struct argv_array *env) { -time_t now =time (NULL ); -struct strbuf date =STRBUF_INIT ; +int i; +const char *date;
Quoted 13 lines
sequencer.c static char *ignore_author_date(const char *author) · line 909
Quoted 9 lines
sequencer.c +4
-5-strbuf_addf (&date,"@%" PRIuMAX, (uintmax_t )now); -argv_array_pushf (&child->env_array,"GIT_AUTHOR_DATE=%s" , date.buf); -if (change_committer_date) -argv_array_pushf (&child->env_array,"GIT_COMMITTER_DATE=%s" , date.buf); -strbuf_release (&date); +for (i =0 ; i < env->argc; i++) +if (skip_prefix (env->argv[i], +"GIT_AUTHOR_DATE=" , &date)) +return date;Is there any risk that GIT_AUTHOR_DATE=<somedate> will appear twice in @child->env_array ? If there is, should we read through the whole list to make sure we take the last one?
read_author_script() errors out if GIT_AUTHOR_DATE is missing or given more than once
Best Wishes
Phillip
Quoted 143 lines
Quoted 143 lines
sequencer.c +19
-23+/* +* 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[] =@@ -980,31 +973,19 @@ 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" , - opts->ignore_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);return error (_ (staged_changes_advice), gpg_opt, gpg_opt); } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );argv_array_push (&cmd.args,"commit" );@@ -1014,8 +995,6 @@ static int run_git_commit(struct repository *r,argv_array_push (&cmd.args,"--amend" );if (opts->gpg_sign)argv_array_pushf (&cmd.args,"-S%s" , opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);if (defmsg)argv_array_pushl (&cmd.args,"-F" , defmsg,NULL );else if (!(flags &EDIT_MSG ))@@ -3615,6 +3594,13 @@ static int do_merge(struct repository *r, ret =error (_ (staged_changes_advice), gpg_opt, gpg_opt); goto leave_merge; } +if (opts->committer_date_is_author_date) +argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" : +author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" ); cmd.git_cmd =1 ;argv_array_push (&cmd.args,"merge" );@@ -3635,8 +3621,6 @@ static int do_merge(struct repository *r,argv_array_push (&cmd.args,git_path_merge_msg (r));if (opts->gpg_sign)argv_array_push (&cmd.args, opts->gpg_sign); -if (opts->ignore_date) -push_dates (&cmd, opts->committer_date_is_author_date);/* Add the tips to be merged */ for (j = to_merge; j; j = j->next)t/t3433-rebase-options-compatibility.sh +26
-4@@ -71,15 +71,15 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' ' test_expect_success '--committer-date-is-author-date works with am backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime && test_cmp authortime committertime ' test_expect_success '--committer-date-is-author-date works with interactive backend' ' - git commit --amend && + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase -i --committer-date-is-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && git log -1 --pretty="format:%ci" >committertime &&@@ -88,13 +88,36 @@ test_expect_success '--committer-date-is-author-date works with interactive back test_expect_success '--committer-date-is-author-date works with rebase -r' ' git checkout side && - git merge --no-ff commit3 && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && git rebase -r --root --committer-date-is-author-date && git log --pretty="format:%ai" >authortime && git log --pretty="format:%ci" >committertime && test_cmp authortime committertime ' +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -i --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530. --2.26.0
PATCH 5/6 Revert "sequencer: allow callers of read_author_script() to ignore fields"
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
This reverts commit c068bcc59b4f16322a77b6a47b53d44b05c51fec.
This functionality is no longer used as since the last commit we always want all of the fields returned.
--- sequencer.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
sequencer.c +3 -13
@@ -825,19 +825,9 @@ int read_author_script(const char *path, char **name, char **email, char **date,error (_ ("missing 'GIT_AUTHOR_DATE'" ));if (date_i <0 || email_i <0 || date_i <0 || err) goto finish; - -if (name) - *name = kv.items[name_i].util; -else -free (kv.items[name_i].util); -if (email) - *email = kv.items[email_i].util; -else -free (kv.items[email_i].util); -if (date) - *date = kv.items[date_i].util; -else -free (kv.items[date_i].util); + *name = kv.items[name_i].util; + *email = kv.items[email_i].util; + *date = kv.items[date_i].util; retval =0 ; finish:string_list_clear (&kv, !!retval);
Signature · 1 line
2.26.0
Re: [PATCH 5/6] Revert "sequencer: allow callers of read_author_script() to ignore fields"
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
This reverts commit
c068bcc59b4f16322a77b6a47b53d44b05c51fec.This functionality is no longer used as since the last commit we always want all of the fields returned.
That's a little hard to parse. Maybe s/used as since/used; since/ ?
Quoted 36 lines
Signed-off-by Phillip Wood <[email protected]>--- sequencer.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)sequencer.c +3
-14@@ -825,19 +825,9 @@ int read_author_script(const char *path, char **name, char **email, char **date,error (_ ("missing 'GIT_AUTHOR_DATE'" ));if (date_i <0 || email_i <0 || date_i <0 || err) goto finish; - -if (name) - *name = kv.items[name_i].util; -else -free (kv.items[name_i].util); -if (email) - *email = kv.items[email_i].util; -else -free (kv.items[email_i].util); -if (date) - *date = kv.items[date_i].util; -else -free (kv.items[date_i].util); + *name = kv.items[name_i].util; + *email = kv.items[email_i].util; + *date = kv.items[date_i].util; retval =0 ; finish:string_list_clear (&kv, !!retval); --2.26.0
PATCH 6/6 t3433: improve coverage
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Add tests to check --ignore-whitespace and --ignore-date are remembered when running rebase --continue and to check --committer-date-is-author-date with --ignore-date gives the expected result.
--- t/t3433-rebase-options-compatibility.sh | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
t/t3433-rebase-options-compatibility.sh +55 -0
@@ -7,6 +7,8 @@ test_description='tests to ensure compatibility between am and interactive backe . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" export GIT_AUTHOR_DATE
@@ -70,6 +72,22 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' test_cmp expect file ' +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" && + export FAKE_LINES && + git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file +' + test_expect_success '--committer-date-is-author-date works with am backend' ' GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ &&
@@ -135,6 +153,16 @@ test_expect_success '--ignore-date works with interactive backend' ' grep "+0000" authortime ' +test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -i \ + --onto commit2^^ commit2^ commit2 && + echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +' + test_expect_success '--ignore-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 &&
@@ -143,4 +171,31 @@ test_expect_success '--ignore-date works with rebase -r' ' ! grep -v "+0000" authortime ' +test_expect_success '--ignore-date with --committer-date-is-author-date works' ' + test_must_fail git rebase -i --committer-date-is-author-date \ + --ignore-date --onto commit2^^ commit2^ commit3 && + git checkout --theirs foo && + git add foo && + git rebase --continue && + git log -2 --pretty=%ai >authortime && + git log -2 --pretty=%ci >committertime && + test_cmp authortime committertime && + ! grep -v "+0000" authortime +' + +test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' + GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ + git rebase -i --strategy=resolve --ignore-date \ + --committer-date-is-author-date side side && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime && + grep "+0000" authortime + ' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done
Signature · 1 line
2.26.0
Re: [PATCH 6/6] t3433: improve coverage
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Add tests to check --ignore-whitespace and --ignore-date are remembered when running
rebase --continueand to check --committer-date-is-author-date with --ignore-date gives the expected result.
Thanks for adding these.
Quoted 4 lines
Signed-off-by Phillip Wood <[email protected]>--- t/t3433-rebase-options-compatibility.sh | 55 +++++++++++++++++++++++++
t3433 is taken by t3433-rebase-across-mode-change.sh in upstream. When you revert the reversion of Rohit's changes, perhaps you need to rename his t3433 to some other file?
Also, the name "rebase-options-compatibility" suggest to me that it's just checking whether certain options can be used together. Perhaps the --ignore-whitespace and --ignore-date tests you add should go somewhere else?
Quoted 39 lines
1 file changed, 55 insertions(+)t/t3433-rebase-options-compatibility.sh +18
-0@@ -7,6 +7,8 @@ test_description='tests to ensure compatibility between am and interactive backe . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" export GIT_AUTHOR_DATE@@ -70,6 +72,22 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' test_cmp expect file ' +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" && + export FAKE_LINES && + git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file +' + test_expect_success '--committer-date-is-author-date works with am backend' ' GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ &&
t/t3433-rebase-options-compatibility.sh test_expect_success '--ignore-date works with interactive backend' ' · line 158
Quoted 6 lines
t/t3433-rebase-options-compatibility.sh +3
-0@@ -135,6 +153,16 @@ test_expect_success '--ignore-date works with interactive backend' ' grep "+0000" authortime ' +test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -i \ + --onto commit2^^ commit2^ commit2 &&
I don't see any todo list here; is there a reason you are using -i instead of say -m? (Similar question applies for the subsequent tests you add below too?)
Quoted 45 lines
t/t3433-rebase-options-compatibility.sh +34
-1+ echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +' + test_expect_success '--ignore-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 &&@@ -143,4 +171,31 @@ test_expect_success '--ignore-date works with rebase -r' ' ! grep -v "+0000" authortime ' +test_expect_success '--ignore-date with --committer-date-is-author-date works' ' + test_must_fail git rebase -i --committer-date-is-author-date \ + --ignore-date --onto commit2^^ commit2^ commit3 && + git checkout --theirs foo && + git add foo && + git rebase --continue && + git log -2 --pretty=%ai >authortime && + git log -2 --pretty=%ci >committertime && + test_cmp authortime committertime && + ! grep -v "+0000" authortime +' + +test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' + GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ + git rebase -i --strategy=resolve --ignore-date \ + --committer-date-is-author-date side side && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime && + grep "+0000" authortime + ' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done --2.26.0
Re: [PATCH 6/6] t3433: improve coverage
Hi Elijah
Quoted 12 lines · Elijah Newren
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Add tests to check --ignore-whitespace and --ignore-date are remembered when running
rebase --continueand to check --committer-date-is-author-date with --ignore-date gives the expected result.Thanks for adding these.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Signed-off-by Phillip Wood <[email protected]>--- t/t3433-rebase-options-compatibility.sh | 55 +++++++++++++++++++++++++t3433 is taken by
t3433-rebase-across-mode-change.shin upstream. When you revert the reversion of Rohit's changes, perhaps you need to rename his t3433 to some other file?
Thanks for point that out I'll rename it
Quoted 4 lines
Also, the name "rebase-options-compatibility" suggest to me that it's just checking whether certain options can be used together. Perhaps the --ignore-whitespace and --ignore-date tests you add should go somewhere else?
I think this file is so named because it tests that the merge backend is compatible with the apply backend for the new options (i.e. they both give the same results) - I'll try and think of a better name
Quoted 42 lines
Quoted 42 lines
1 file changed, 55 insertions(+)t/t3433-rebase-options-compatibility.sh +18
-0@@ -7,6 +7,8 @@ test_description='tests to ensure compatibility between am and interactive backe . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" export GIT_AUTHOR_DATE@@ -70,6 +72,22 @@ test_expect_success '--ignore-whitespace works with interactive backend' ' test_cmp expect file ' +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" && + export FAKE_LINES && + git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file +' + test_expect_success '--committer-date-is-author-date works with am backend' ' GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && git rebase --committer-date-is-author-date HEAD^ &&@@ -135,6 +153,16 @@ test_expect_success '--ignore-date works with interactive backend' ' grep "+0000" authortime '
Quoted 7 lines
t/t3433-rebase-options-compatibility.sh test_expect_success '--ignore-date works with interactive backend' ' · line 158
Quoted 3 lines
t/t3433-rebase-options-compatibility.sh +3
-0+test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -i \ + --onto commit2^^ commit2^ commit2 &&I don't see any todo list here; is there a reason you are using -i instead of say -m? (Similar question applies for the subsequent tests you add below too?)
Habit. (also these were originally based on an older commit and I wasn't sure if that had your 'rebase -m' changes in it.) I'll update them to use -m
Best Wishes
Phillip
Quoted 45 lines
Quoted 45 lines
t/t3433-rebase-options-compatibility.sh +34
-1+ echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +' + test_expect_success '--ignore-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 &&@@ -143,4 +171,31 @@ test_expect_success '--ignore-date works with rebase -r' ' ! grep -v "+0000" authortime ' +test_expect_success '--ignore-date with --committer-date-is-author-date works' ' + test_must_fail git rebase -i --committer-date-is-author-date \ + --ignore-date --onto commit2^^ commit2^ commit3 && + git checkout --theirs foo && + git add foo && + git rebase --continue && + git log -2 --pretty=%ai >authortime && + git log -2 --pretty=%ci >committertime && + test_cmp authortime committertime && + ! grep -v "+0000" authortime +' + +test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' + GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ + git rebase -i --strategy=resolve --ignore-date \ + --committer-date-is-author-date side side && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime && + grep "+0000" authortime + ' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done --2.26.0
Hi Phillip,
Quoted 36 lines · Phillip Wood
From: Phillip Wood <[email protected]>
The tests for ra/rebase-i-more-options were not as comprehensive as they could have been and some of the tests that we did have didn't do a good job of testing what they purported to. This series cleans up the tests and fixes a couple of bugs (thanks to Jonathan Nieder for reporting one of them). The bug fix reworks the code to try and make it clearer.
I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches. These are based on top of
4d924528d8("Revert "Merge branch 'ra/rebase-i-more-options'"", 2020-01-12) there are some conflicts when merging into pu. I had a quick look at the conflicts and they appeared to be relatively straight forward to resolve. If that impression is wrong let me know and I can rebase onto master or try doing the merge myself and pushing it to github.Phillip Wood (6):
Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
t3433: remove loops from tests
t3433: only compare commit dates
rebase -i: fix --committer-date-is-author-date
Revert "sequencer: allow callers ofread_author_script()to ignore
fields"
t3433: improve coverageDocumentation/git-rebase.txt | 27 +++- builtin/rebase.c | 49 ++++-- sequencer.c | 109 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 201 ++++++++++++++++++++++++ 7 files changed, 368 insertions(+), 25 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.sh
Quoted 2 lines
--
2.26.0
Thanks for working on this! I took a look over the series and noted a few minor issues and questions, but it mostly looked good to me.
Elijah
Quoted 39 lines · Elijah Newren
Hi Phillip,
Quoted 36 lines · Phillip Wood
From: Phillip Wood <[email protected]>
The tests for ra/rebase-i-more-options were not as comprehensive as they could have been and some of the tests that we did have didn't do a good job of testing what they purported to. This series cleans up the tests and fixes a couple of bugs (thanks to Jonathan Nieder for reporting one of them). The bug fix reworks the code to try and make it clearer.
I've opted to add some cleanup commits on top of Rohit's work rather than reworking his patches. These are based on top of
4d924528d8("Revert "Merge branch 'ra/rebase-i-more-options'"", 2020-01-12) there are some conflicts when merging into pu. I had a quick look at the conflicts and they appeared to be relatively straight forward to resolve. If that impression is wrong let me know and I can rebase onto master or try doing the merge myself and pushing it to github.Phillip Wood (6):
Revert "Revert "Merge branch 'ra/rebase-i-more-options'""
t3433: remove loops from tests
t3433: only compare commit dates
rebase -i: fix --committer-date-is-author-date
Revert "sequencer: allow callers ofread_author_script()to ignore
fields"
t3433: improve coverageDocumentation/git-rebase.txt | 27 +++- builtin/rebase.c | 49 ++++-- sequencer.c | 109 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3433-rebase-options-compatibility.sh | 201 ++++++++++++++++++++++++ 7 files changed, 368 insertions(+), 25 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.sh
Quoted 5 lines
Quoted 2 lines
--
2.26.0Thanks for working on this! I took a look over the series and noted a few minor issues and questions, but it mostly looked good to me.
Thanks for looking at them and for your suggestions. I think I've got reasonable test coverage now - lets see if Stolee's coverage script agrees
Best Wishes
Phillip
Quoted 2 lines
Elijah
Quoted 6 lines · Phillip Wood
The tests for ra/rebase-i-more-options were not as comprehensive as they could have been and some of the tests that we did have didn't do a good job of testing what they purported to. This series cleans up the tests and fixes a couple of bugs (thanks to Jonathan Nieder for reporting one of them). The bug fix reworks the code to try and make it clearer.
As t3433 is already taken, I've queued a SQUASH??? commit at the tip of the topic to move it to t3436 while queuing (which is another fallout that needs fixing while we resurrect an outdated series).
Thanks.
v2 cover cleanup ra/rebase-i-more-options
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
I've rebased Rohit's patches on master and reworked them with my fixups from v1. I've renamed the test file that was causing a problem (as you'll see I wasn't feeling very inspired when I came up with the name) and changed some tests from using rebase -i to rebase -m as suggested by Elijah. I've updated the last patch to test both --reset-author and --ignore-author.
There's a range-diff below between ra/rebase-i-more-options and these patches though I'm not sure how useful it is in practice.
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date
Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date
Documentation/git-rebase.txt | 26 ++- builtin/rebase.c | 46 ++++-- sequencer.c | 111 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 209 +++++++++++++++++++++++++ 6 files changed, 371 insertions(+), 25 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
1: ba51d2fb24 ! 1: 5ef315240a rebase -i: add --ignore-whitespace flag
@@ Metadata
## Commit message ##
rebase -i: add --ignore-whitespace flag
- There are two backends available for rebasing, viz, the am and the
- interactive. Naturally, there shall be some features that are
- implemented in one but not in the other. One such flag is
- --ignore-whitespace which indicates merge mechanism to treat lines
- with only whitespace changes as unchanged. Wire the interactive
- rebase to also understand the --ignore-whitespace flag by
- translating it to -Xignore-space-change.
+ Rebase is implemented with two different backends - 'apply' and 'merge'
+ each of which support a different set of options. In particuar the apply
+ backend supports a number of options implemented by 'git am' that are
+ not available to the merge backend. As part of an on going effort to
+ remove the apply backend this patch adds support for the
+ --ignore-whitespace option to the merge backend. This option treats
+ lines with only whitespace changes as unchanged and is implemented in
+ the merge backend by translating it to -Xignore-space-change.
- Signed-off-by: Junio C Hamano <[email protected]>
+ Signed-off-by: Phillip Wood <[email protected]>
## Documentation/git-rebase.txt ##
-@@ Documentation/git-rebase.txt: If either <upstream> or --root is given on the command line, then the
- default is --no-fork-point, otherwise the default is --fork-point.
+@@ Documentation/git-rebase.txt: your branch contains commits which were dropped, this option can be used
+ with --keep-base in order to drop those commits from your branch.
--ignore-whitespace::
+ Behaves differently depending on which backend is selected.
++
-+'am' backend: When applying a patch, ignore changes in whitespace in -+context lines if necessary.
++apply backend: When applying a patch, ignore changes in whitespace in ++context lines.
++
-+'interactive' backend: Treat lines with only whitespace changes as -+unchanged for the sake of a three-way merge.
++merge backend: Treat lines with only whitespace changes as unchanged ++when merging.
+
--whitespace=<option>::
-- These flag are passed to the 'git apply' program
+- These flags are passed to the 'git apply' program
+ This flag is passed to the 'git apply' program
(see linkgit:git-apply[1]) that applies the patch.
+ Implies --apply.
+
- See also INCOMPATIBLE OPTIONS below.
@@ Documentation/git-rebase.txt: The following options:
+ * --apply
* --committer-date-is-author-date
* --ignore-date
- * --whitespace
- * --ignore-whitespace
+ * --whitespace
* -C
- are incompatible with the following options:
@@ Documentation/git-rebase.txt: In addition, the following pairs of options are incompatible:
- * --preserve-merges and --interactive
* --preserve-merges and --signoff
* --preserve-merges and --rebase-merges
+ * --preserve-merges and --empty=
+ * --preserve-merges and --ignore-whitespace
- * --rebase-merges and --strategy
- * --rebase-merges and --strategy-option
+ * --keep-base and --onto
+ * --keep-base and --root
## builtin/rebase.c ##
@@ builtin/rebase.c: struct rebase_options {
+ int signoff;
int allow_rerere_autoupdate;
- int keep_empty;
int autosquash;
+ int ignore_whitespace;
char *gpg_sign_opt;
@@ builtin/rebase.c: static struct replay_opts get_replay_opts(const struct rebase_
+ if (strategy_buf.len)
+ parse_strategy_opts(&replay, strategy_buf.buf);
+ if (opts->squash_onto) {
+ oidcpy(&replay.squash_onto, opts->squash_onto);
+ replay.have_squash_onto = 1;
+ }
+
+ strbuf_release(&strategy_buf);
return replay;
}
@@ builtin/rebase.c: int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
- argc = parse_options(argc, argv, NULL, options,
+ argc = parse_options(argc, argv, prefix, options,
builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
+ opts.strategy_opts = xstrdup_or_null(opts.strategy_opts);
@@ t/t3422-rebase-incompatible-options.sh: test_rebase_am_only () {
test_rebase_am_only -C4
- ## t/t3433-rebase-options-compatibility.sh (new) ##
+ ## t/t3436-rebase-more-options.sh (new) ##
@@
+#!/bin/sh
+#
@@ t/t3433-rebase-options-compatibility.sh (new)
+
+. ./test-lib.sh
+
++. "$TEST_DIRECTORY"/lib-rebase.sh
++
+# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour.
@@ t/t3433-rebase-options-compatibility.sh (new)
+ git tag main
+'
+
-+test_expect_success '--ignore-whitespace works with am backend' ' ++test_expect_success '--ignore-whitespace works with apply backend' '
+ cat >expect <<-\EOF &&
+ line 1
+ new line 2
+ line 3
+ EOF
-+ test_must_fail git rebase main side &&
++ test_must_fail git rebase --apply main side &&
+ git rebase --abort &&
-+ git rebase --ignore-whitespace main side &&
++ git rebase --apply --ignore-whitespace main side &&
+ test_cmp expect file
+'
+
-+test_expect_success '--ignore-whitespace works with interactive backend' ' ++test_expect_success '--ignore-whitespace works with merge backend' '
+ cat >expect <<-\EOF &&
+ line 1
+ new line 2
@@ t/t3433-rebase-options-compatibility.sh (new)
+ test_cmp expect file
+'
+
++test_expect_success '--ignore-whitespace is remembered when continuing' '
++ cat >expect <<-\EOF &&
++ line 1
++ new line 2
++ line 3
++ EOF
++ (
++ set_fake_editor &&
++ FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side
++ ) &&
++ git rebase --continue &&
++ test_cmp expect file
++'
++
++# This must be the last test in this file ++test_expect_success '$EDITOR and friends are unchanged' '
++ test_editor_unchanged
++'
++
+test_done
2: c068bcc59b < -: ---------- sequencer: allow callers of read_author_script() to ignore fields
3: cbd8db17ac ! 2: 55eb3a7efc rebase -i: support --committer-date-is-author-date
@@
## Metadata ##
-Author: Rohit Ashiwal <[email protected]>
+Author: Phillip Wood <[email protected]>
## Commit message ##
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.
+ As part of the on-going effort to retire the apply rebase backend teach
+ the merge backend how to handle --committer-date-is-author-date.
- Signed-off-by: Rohit Ashiwal <[email protected]>
- Signed-off-by: Junio C Hamano <[email protected]>
+ Original-patch-by: Rohit Ashiwal <[email protected]>
+ Signed-off-by: Phillip Wood <[email protected]>
## Documentation/git-rebase.txt ##
-@@ Documentation/git-rebase.txt: unchanged for the sake of a three-way merge.
+@@ Documentation/git-rebase.txt: when merging.
See also INCOMPATIBLE OPTIONS below.
--committer-date-is-author-date::
-+ Instead of recording the time the rebased commits are
-+ created as the committer date, reuse the author date
-+ as the committer date. This implies --force-rebase.
++ Instead of using the current time as the committer date, use
++ the author date of the commit being rebased as the committer
++ date. This option implies --force-rebase.
+
--ignore-date::
- These flags are passed to 'git am' to easily change the dates
@@ Documentation/git-rebase.txt: unchanged for the sake of a three-way merge.
See also INCOMPATIBLE OPTIONS below.
@@ Documentation/git-rebase.txt: INCOMPATIBLE OPTIONS
-
The following options:
+ * --apply
- * --committer-date-is-author-date
* --ignore-date
* --whitespace
* -C
@@ Documentation/git-rebase.txt: In addition, the following pairs of options are incompatible:
- * --preserve-merges and --signoff
* --preserve-merges and --rebase-merges
+ * --preserve-merges and --empty=
* --preserve-merges and --ignore-whitespace
+ * --preserve-merges and --committer-date-is-author-date
- * --rebase-merges and --strategy
- * --rebase-merges and --strategy-option
+ * --keep-base and --onto
+ * --keep-base and --root
## builtin/rebase.c ##
@@ builtin/rebase.c: struct rebase_options {
int allow_empty_message;
int rebase_merges, rebase_cousins;
@@ builtin/rebase.c: static struct replay_opts get_replay_opts(const struct rebase_options *opts)
- replay.allow_empty_message = opts->allow_empty_message;
+ replay.quiet = !(opts->flags & REBASE_NO_QUIET);
replay.verbose = opts->flags & REBASE_VERBOSE;
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
+ replay.committer_date_is_author_date =
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
N_("passed to 'git am'"), PARSE_OPT_NOARG),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
- state_dir_base, cmd_live_rebase, buf.buf);
+ options.autosquash) {
+ allow_preemptive_ff = 0;
}
-
+ if (options.committer_date_is_author_date)
+ options.flags |= REBASE_FORCE;
-+
+
for (i = 0; i < options.git_am_opts.argc; i++) {
const char *option = options.git_am_opts.argv[i], *p;
- if (!strcmp(option, "--committer-date-is-author-date") ||
- !strcmp(option, "--ignore-date") ||
+ if (!strcmp(option, "--ignore-date") ||
!strcmp(option, "--whitespace=fix") ||
!strcmp(option, "--whitespace=strip"))
- options.flags |= REBASE_FORCE;
+ allow_preemptive_ff = 0;
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
@@ sequencer.c: 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)
++static const char *author_date_from_env_array(const struct argv_array *env)
+{
-+ char *date;
++ int i;
++ const char *date;
+
-+ if (read_author_script(rebase_path_author_script(),
-+ NULL, NULL, &date, 0))
-+ return NULL;
-+ return 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"
@@ sequencer.c: static int run_git_commit(struct repository *r,
+ gpg_opt, gpg_opt);
+ }
- 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 (opts->committer_date_is_author_date)
++ argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
++ author_date_from_env_array(&cmd.env_array));
+
- if (is_rebase_i(opts) && read_env_script(&cmd.env_array)) {
- const char *gpg_opt = gpg_sign_opt_quoted(opts);
+ argv_array_push(&cmd.args, "commit");
+ if (!(flags & VERIFY_MSG))
@@ sequencer.c: static int try_to_commit(struct repository *r,
if (parse_head(r, ¤t_head))
return -1;
-
if (flags & AMEND_MSG) {
- const char *exclude_gpgsig[] = { "gpgsig", NULL };
+ const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
const char *out_enc = get_commit_output_encoding();
@@ sequencer.c: static int try_to_commit(struct repository *r,
commit_list_insert(current_head, &parents);
@@ sequencer.c: static int try_to_commit(struct repository *r,
+ struct strbuf date = STRBUF_INIT;
+
+ if (split_ident_line(&ident, author, len) < 0) {
-+ res = error(_("malformed ident line"));
++ res = error(_("malformed ident line '%s'"), author);
+ goto out;
+ }
+ if (!ident.date_begin) {
@@ sequencer.c: static int read_populate_opts(struct replay_opts *opts)
opts->reschedule_failed_exec = 1;
@@ sequencer.c: 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");
+ 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", "");
+@@ sequencer.c: 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");
@@ sequencer.c: static int pick_commits(struct repository *r,
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
if (opts->allow_ff)
@@ t/t3422-rebase-incompatible-options.sh: test_rebase_am_only () {
test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
- ## t/t3433-rebase-options-compatibility.sh ##
-@@ t/t3433-rebase-options-compatibility.sh: test_description='tests to ensure compatibility between am and interactive backe
+ ## t/t3436-rebase-more-options.sh ##
+@@ t/t3436-rebase-more-options.sh: test_description='tests to ensure compatibility between am and interactive backe
- . ./test-lib.sh
+ . "$TEST_DIRECTORY"/lib-rebase.sh
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+
# This is a special case in which both am and interactive backends
# provide the same output. It was done intentionally because
# both the backends fall short of optimal behaviour.
-@@ t/t3433-rebase-options-compatibility.sh: test_expect_success 'setup' '
+@@ t/t3436-rebase-more-options.sh: test_expect_success 'setup' '
EOF
git commit -am "update file" &&
git tag side &&
@@ t/t3433-rebase-options-compatibility.sh: test_expect_success 'setup' '
sed -e "s/^|//" >file <<-\EOF &&
|line 1
| line 2
-@@ t/t3433-rebase-options-compatibility.sh: test_expect_success '--ignore-whitespace works with interactive backend' '
+@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-whitespace is remembered when continuing' '
test_cmp expect file
'
-+test_expect_success '--committer-date-is-author-date works with am backend' '
-+ git commit --amend &&
-+ git rebase --committer-date-is-author-date HEAD^ &&
-+ git show HEAD --pretty="format:%ai" >authortime &&
-+ git show HEAD --pretty="format:%ci" >committertime &&
++test_expect_success '--committer-date-is-author-date works with apply backend' '
++ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
++ git rebase --apply --committer-date-is-author-date HEAD^ &&
++ git log -1 --pretty="format:%ai" >authortime &&
++ git log -1 --pretty="format:%ci" >committertime &&
+ test_cmp authortime committertime
+'
+
-+test_expect_success '--committer-date-is-author-date works with interactive backend' '
-+ git commit --amend &&
-+ git rebase -i --committer-date-is-author-date HEAD^ &&
-+ git show HEAD --pretty="format:%ai" >authortime &&
-+ git show HEAD --pretty="format:%ci" >committertime &&
++test_expect_success '--committer-date-is-author-date works with merge backend' '
++ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
++ git rebase -m --committer-date-is-author-date HEAD^ &&
++ git log -1 --pretty="format:%ai" >authortime &&
++ git log -1 --pretty="format:%ci" >committertime &&
+ test_cmp authortime committertime
+'
+
+test_expect_success '--committer-date-is-author-date works with rebase -r' '
+ git checkout side &&
-+ git merge --no-ff commit3 &&
++ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+ git rebase -r --root --committer-date-is-author-date &&
-+ git rev-list HEAD >rev_list &&
-+ while read HASH
-+ do
-+ git show $HASH --pretty="format:%ai" >authortime
-+ git show $HASH --pretty="format:%ci" >committertime
-+ test_cmp authortime committertime
-+ done <rev_list
++ git log --pretty="format:%ai" >authortime &&
++ git log --pretty="format:%ci" >committertime &&
++ test_cmp authortime committertime
+'
+
- test_done
++test_expect_success '--committer-date-is-author-date works when forking merge' '
++ git checkout side &&
++ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
++ git rebase -r --root --strategy=resolve --committer-date-is-author-date &&
++ git log --pretty="format:%ai" >authortime &&
++ git log --pretty="format:%ci" >committertime &&
++ test_cmp authortime committertime
++
++'
++
++test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
++ git checkout commit2 &&
++ GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
++ git log -1 --format=%at HEAD >expect &&
++ test_must_fail git rebase -m --committer-date-is-author-date \
++ --onto HEAD^^ HEAD^ &&
++ echo resolved > foo &&
++ git add foo &&
++ git rebase --continue &&
++ git log -1 --format=%ct HEAD >actual &&
++ test_cmp expect actual
++'
++
+ # This must be the last test in this file
+ test_expect_success '$EDITOR and friends are unchanged' '
+ test_editor_unchanged4: 0185c683c9 ! 3: 19352fdc22 sequencer: rename amend_author to author_to_rename
@@ Metadata
Author: Rohit Ashiwal <[email protected]>
## Commit message ##
- sequencer: rename amend_author to author_to_rename
+ sequencer: rename amend_author to author_to_free
The purpose of amend_author was to free() the malloc()'d string
- obtained from get_author() while amending a commit. But we can
+ obtained from get_author() when amending a commit. But we can
also use the variable to free() the author at our convenience. Rename it to convey this meaning.
- Signed-off-by: Junio C Hamano <[email protected]>
## sequencer.c ##
@@ sequencer.c: static int try_to_commit(struct repository *r,
5: 08187b4cba ! 4: 5e971abb74 rebase -i: support --ignore-date
@@
## Metadata ##
-Author: Rohit Ashiwal <[email protected]>
+Author: Phillip Wood <[email protected]>
## Commit message ##
rebase -i: support --ignore-date
- rebase am already has this flag to "lie" about the author date
- by changing it to the committer (current) date. Let's add the same
- for interactive machinery.
+ As part of the on-going effort to retire the apply rebase backend
+ teach the merge backend how to handle --ignore-date. We take care to
+ handle the combination of --ignore-date and
+ --committer-date-is-author-date in the same way as the apply backend.
- Signed-off-by: Rohit Ashiwal <[email protected]>
- Signed-off-by: Junio C Hamano <[email protected]>
+ Original-patch-by: Rohit Ashiwal <[email protected]>
+ Signed-off-by: Phillip Wood <[email protected]>
## Documentation/git-rebase.txt ##
@@ Documentation/git-rebase.txt: See also INCOMPATIBLE OPTIONS below.
- as the committer date. This implies --force-rebase.
+ date. This option implies --force-rebase.
--ignore-date::
- This flag is passed to 'git am' to change the author date
- of each rebased commit (see linkgit:git-am[1]).
-+ Instead of using the given author date, reset it to the
-+ current time. This implies --force-rebase.
++ Instead of using the author date of the original commit, use
++ the current time as the author date of the rebased commit. This
++ option implies `--force-rebase`.
+
See also INCOMPATIBLE OPTIONS below.
@@ Documentation/git-rebase.txt: INCOMPATIBLE OPTIONS
-
The following options:
+ * --apply
- * --ignore-date
* --whitespace
* -C
@@ Documentation/git-rebase.txt: In addition, the following pairs of options are incompatible:
- * --preserve-merges and --rebase-merges
+ * --preserve-merges and --empty=
* --preserve-merges and --ignore-whitespace
* --preserve-merges and --committer-date-is-author-date
+ * --preserve-merges and --ignore-date
- * --rebase-merges and --strategy
- * --rebase-merges and --strategy-option
+ * --keep-base and --onto
+ * --keep-base and --root
## builtin/rebase.c ##
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
N_("passed to 'git apply'"), 0),
OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
- state_dir_base, cmd_live_rebase, buf.buf);
+ options.autosquash) {
+ allow_preemptive_ff = 0;
}
-
- if (options.committer_date_is_author_date)
-+ if (options.committer_date_is_author_date ||
-+ options.ignore_date)
++ if (options.committer_date_is_author_date || options.ignore_date)
options.flags |= REBASE_FORCE;
for (i = 0; i < options.git_am_opts.argc; i++) {
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
- !strcmp(option, "--whitespace=fix") ||
+ if (!strcmp(option, "--whitespace=fix") ||
!strcmp(option, "--whitespace=strip"))
- options.flags |= REBASE_FORCE;
+ allow_preemptive_ff = 0;
else if (skip_prefix(option, "-C", &p)) {
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs
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")
-@@ sequencer.c: static char *read_author_date_or_null(void)
- return date;
+@@ sequencer.c: static const char *author_date_from_env_array(const struct argv_array *env)
+ BUG("GIT_AUTHOR_DATE missing from author script");
}
+/* Construct a free()able author string with current time as the author date */
@@ sequencer.c: static char *read_author_date_or_null(void)
+ struct strbuf new_author = STRBUF_INIT;
+
+ if (split_ident_line(&ident, author, len) < 0) {
-+ error(_("malformed ident line"));
++ error(_("malformed ident line '%s'"), author);
+ return NULL;
+ }
+ len = ident.mail_end - ident.name_begin + 1;
@@ sequencer.c: static char *read_author_date_or_null(void)
+ datestamp(&new_author);
+ return strbuf_detach(&new_author, NULL);
+}
-+
-+static void push_dates(struct child_process *child, int change_committer_date)
-+{
-+ time_t now = time(NULL);
-+ struct strbuf date = STRBUF_INIT;
-+
-+ strbuf_addf(&date, "@%"PRIuMAX, (uintmax_t)now);
-+ argv_array_pushf(&child->env_array, "GIT_AUTHOR_DATE=%s", date.buf);
-+ if (change_committer_date)
-+ argv_array_pushf(&child->env_array, "GIT_COMMITTER_DATE=%s", date.buf);
-+ strbuf_release(&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"
@@ sequencer.c: static int run_git_commit(struct repository *r,
- return -1;
- strbuf_addf(&datebuf, "@%s", date);
-- res = setenv("GIT_COMMITTER_DATE", datebuf.buf, 1);
-+ res = setenv("GIT_COMMITTER_DATE",
-+ opts->ignore_date ? "" : datebuf.buf, 1);
-
- strbuf_release(&datebuf);
- free(date);
-@@ sequencer.c: static int run_git_commit(struct repository *r,
- argv_array_push(&cmd.args, "--amend");
- if (opts->gpg_sign)
- argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
+ if (opts->committer_date_is_author_date)
+ argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
++ opts->ignore_date ?
++ "" :
+ author_date_from_env_array(&cmd.env_array));
+ if (opts->ignore_date)
-+ push_dates(&cmd, opts->committer_date_is_author_date);
- if (defmsg)
- argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
- else if (!(flags & EDIT_MSG))
++ argv_array_push(&cmd.env_array, "GIT_AUTHOR_DATE=");
+
+ argv_array_push(&cmd.args, "commit");
+
@@ sequencer.c: static int try_to_commit(struct repository *r,
strbuf_addf(&date, "@%.*s %.*s",
(int)(ident.date_end - ident.date_begin), ident.date_begin,
@@ sequencer.c: static int read_populate_opts(struct replay_opts *opts)
opts->reschedule_failed_exec = 1;
@@ sequencer.c: int write_basic_state(struct replay_opts *opts, const char *head_name,
- write_file(rebase_path_signoff(), "--signoff\n");
+ 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->ignore_date)
@@ sequencer.c: int write_basic_state(struct replay_opts *opts, const char *head_na
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
@@ sequencer.c: static int do_merge(struct repository *r,
- argv_array_push(&cmd.args, git_path_merge_msg(r));
- if (opts->gpg_sign)
- argv_array_push(&cmd.args, opts->gpg_sign);
+
+ if (opts->committer_date_is_author_date)
+ argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
++ opts->ignore_date ?
++ "" :
+ author_date_from_env_array(&cmd.env_array));
+ if (opts->ignore_date)
-+ push_dates(&cmd, opts->committer_date_is_author_date);
++ argv_array_push(&cmd.env_array, "GIT_AUTHOR_DATE=");
- /* Add the tips to be merged */
- for (j = to_merge; j; j = j->next)
+ cmd.git_cmd = 1;
+ argv_array_push(&cmd.args, "merge");
@@ sequencer.c: static int pick_commits(struct repository *r,
if (opts->allow_ff)
assert(!(opts->signoff || opts->no_commit ||
@@ sequencer.h: struct replay_opts {
int mainline;
- ## t/t3433-rebase-options-compatibility.sh ##
-@@ t/t3433-rebase-options-compatibility.sh: test_expect_success '--committer-date-is-author-date works with rebase -r' '
- done <rev_list
+ ## t/t3436-rebase-more-options.sh ##
+@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-date works when committing confl
+ test_cmp expect actual
'
+# Checking for +0000 in author time is enough since default
+# timezone is UTC, but the timezone used while committing
+# sets to +0530.
-+test_expect_success '--ignore-date works with am backend' '
++test_expect_success '--ignore-date works with apply backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
-+ git rebase --ignore-date HEAD^ &&
-+ git show HEAD --pretty="format:%ai" >authortime &&
++ git rebase --apply --ignore-date HEAD^ &&
++ git log -1 --pretty="format:%ai" >authortime &&
+ grep "+0000" authortime
+'
+
-+test_expect_success '--ignore-date works with interactive backend' '
++test_expect_success '--ignore-date works with merge backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
-+ git rebase --ignore-date -i HEAD^ &&
-+ git show HEAD --pretty="format:%ai" >authortime &&
++ git rebase --ignore-date -m HEAD^ &&
++ git log -1 --pretty="format:%ai" >authortime &&
+ grep "+0000" authortime
+'
+
++test_expect_success '--ignore-date works after conflict resolution' '
++ test_must_fail git rebase --ignore-date -m \
++ --onto commit2^^ commit2^ commit2 &&
++ echo resolved >foo &&
++ git add foo &&
++ git rebase --continue &&
++ git log --pretty=%ai >authortime &&
++ grep +0000 authortime
++'
++
+test_expect_success '--ignore-date works with rebase -r' '
+ git checkout side &&
+ git merge --no-ff commit3 &&
+ git rebase -r --root --ignore-date &&
-+ git rev-list HEAD >rev_list &&
-+ while read HASH
-+ do
-+ git show $HASH --pretty="format:%ai" >authortime
-+ grep "+0000" authortime
-+ done <rev_list
++ git log --pretty=%ai >authortime &&
++ ! grep -v "+0000" authortime
+'
+
- test_done
++test_expect_success '--ignore-date with --committer-date-is-author-date works' '
++ test_must_fail git rebase -m --committer-date-is-author-date \
++ --ignore-date --onto commit2^^ commit2^ commit3 &&
++ git checkout --theirs foo &&
++ git add foo &&
++ git rebase --continue &&
++ git log -2 --pretty=%ai >authortime &&
++ git log -2 --pretty=%ci >committertime &&
++ test_cmp authortime committertime &&
++ ! grep -v "+0000" authortime
++'
++
++test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
++ GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
++ git rebase -i --strategy=resolve --ignore-date \
++ --committer-date-is-author-date side side &&
++ git log -1 --pretty=%ai >authortime &&
++ git log -1 --pretty=%ci >committertime &&
++ test_cmp authortime committertime &&
++ grep "+0000" authortime
++ '
++
+ # This must be the last test in this file
+ test_expect_success '$EDITOR and friends are unchanged' '
+ test_editor_unchanged
6: fe28ad8520 < -: ---------- rebase: add --reset-author-date
7: d82dfa7f5b < -: ---------- rebase -i: finishing touches to --reset-author-date
-: ---------- > 5: 43a097c583 rebase: add --reset-author-dateSignature · 1 line
2.26.2
PATCH v2 1/5 rebase -i: add --ignore-whitespace flag
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 12 +++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +10 -2
@@ -422,8 +422,16 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected. ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +
@@ -572,7 +580,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C
@@ -598,6 +605,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +15 -4
@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;
@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;
@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }
@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;
@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
t/t3436-rebase-more-options.sh new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v2 1/5] rebase -i: add --ignore-whitespace flag
Sorry for taking so long to get back to you, and thanks for pushing this forward.
Quoted 27 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
Signed-off-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 12 +++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.shDocumentation/git-rebase.txt +0
-0
Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 425
Quoted 4 lines
Documentation/git-rebase.txt +1
-0@@ -422,8 +422,16 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected.
I still don't like this wording; it defers answering the question, implies that the difference is intentional, and most importantly provides no context about *intended* behavior. I tried to communicate this to Rohit multiple times, but he seemed to fixate on and highlight the differences in a way that made them sound like they were by design, rather than highlighting the intent we want to move towards and mentioning that this patch gets us most the way there.
As far as I can tell, the --ignore-whitespace and -Xignore-space-change were always meant to do the same thing: ignore differences in whitespace when doing so can avoid conflicts.
In case anyone isn't sure about my assertion that these were always meant to do the same thing:
* apply aliases --ignore-whitespace and --ignore-space-change; they
meant the same thing
* commit f008cef4ab ("Merge branch 'jc/apply-ignore-whitespace'",
2014-06-03) says that apply's --ignore-space-change wasn't behaving consistently with diff's --ignore-space-change
* diff's --ignore-space-change goes through xdiff's XDL opts, much
like merge-recursive does.
Further, the original commit that introduced these xdiff options to merge-recursive, 4e5dd044c6 ("merge-recursive: options to ignore whitespace changes", 2010-08-26), it is clear that:
* he only cared about ignore-space-at-eol and implemented
ignore-space-change at the same time only for completeness
* it wouldn't matter to his usecase if whitespace-only changes were
stripped, thus he wouldn't have spotted the bug it has
* the wording also suggests these options were picked to match
options of the same name elsewhere in git
I would rather we said something like:
Ignore whitespace differences when trying to reconcile
differences. Currently, each backend implements an approximation of this behavior:
Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 428
Quoted 3 lines
Documentation/git-rebase.txt +3
-0++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines.
Maybe add something like:
(Unfortunately, this means that if the "old" lines being replaced
by the patch differ only in whitespace from the existing file, you will get a merge conflict instead of a successful patch application.)
Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 431
Quoted 3 lines
Documentation/git-rebase.txt +3
-0++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging.
Maybe add something like:
(Unfortunately, this means that any patch hunks that were intended
to modify whitespace and nothing else will be dropped, even if the other side had no changes that conflicted.)
Quoted 207 lines
Documentation/git-rebase.txt +3
-2+ --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +@@ -572,7 +580,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C@@ -598,6 +605,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +15
-4@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +86
-1@@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_done --
Quoted 1 line
2.26.2
The rest looks good to me.
Re: [PATCH v2 1/5] rebase -i: add --ignore-whitespace flag
Quoted 2 lines · Elijah Newren
Sorry for taking so long to get back to you, and thanks for pushing this forward.
Thanks for taking a look at this series
Quoted 81 lines · Phillip Wood
Quoted 29 lines
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 12 +++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.shDocumentation/git-rebase.txt +0
-0Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 425
Quoted 4 lines
Documentation/git-rebase.txt +1
-0@@ -422,8 +422,16 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Behaves differently depending on which backend is selected.I still don't like this wording; it defers answering the question, implies that the difference is intentional, and most importantly provides no context about *intended* behavior. I tried to communicate this to Rohit multiple times, but he seemed to fixate on and highlight the differences in a way that made them sound like they were by design, rather than highlighting the intent we want to move towards and mentioning that this patch gets us most the way there.
As far as I can tell, the --ignore-whitespace and -Xignore-space-change were always meant to do the same thing: ignore differences in whitespace when doing so can avoid conflicts.
In case anyone isn't sure about my assertion that these were always meant to do the same thing:
* apply aliases --ignore-whitespace and --ignore-space-change; they
meant the same thing
* commitf008cef4ab("Merge branch 'jc/apply-ignore-whitespace'",
2014-06-03) says that apply's --ignore-space-change wasn't behaving consistently with diff's --ignore-space-change
* diff's --ignore-space-change goes through xdiff's XDL opts, much
like merge-recursive does.
Further, the original commit that introduced these xdiff options to merge-recursive,4e5dd044c6("merge-recursive: options to ignore whitespace changes", 2010-08-26), it is clear that:
* he only cared about ignore-space-at-eol and implemented
ignore-space-change at the same time only for completeness
* it wouldn't matter to his usecase if whitespace-only changes were
stripped, thus he wouldn't have spotted the bug it has
* the wording also suggests these options were picked to match
options of the same name elsewhere in gitI would rather we said something like:
Ignore whitespace differences when trying to reconcile
differences. Currently, each backend implements an approximation of this behavior:Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 428
Quoted 3 lines
Documentation/git-rebase.txt +3
-0++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines.Maybe add something like:
(Unfortunately, this means that if the "old" lines being replaced
by the patch differ only in whitespace from the existing file, you will get a merge conflict instead of a successful patch application.)
Quoted 8 lines
Documentation/git-rebase.txt your branch contains commits which were dropped, this option can be used · line 431
Quoted 3 lines
Documentation/git-rebase.txt +3
-0++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging.Maybe add something like:
(Unfortunately, this means that any patch hunks that were intended
to modify whitespace and nothing else will be dropped, even if the other side had no changes that conflicted.)
Thanks for the suggestions, I'll incorporate them into the re-roll.
Best Wishes
Phillip
Quoted 211 lines
Quoted 207 lines
Documentation/git-rebase.txt +3
-2+ --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +@@ -572,7 +580,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C@@ -598,6 +605,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +15
-4@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +86
-1@@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_done --Quoted 1 line
2.26.2
The rest looks good to me.
PATCH v2 2/5 rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 60 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 11 deletions(-)
Documentation/git-rebase.txt +7 -3
@@ -438,9 +438,13 @@ when merging. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.
@@ -578,7 +582,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C
@@ -606,6 +609,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +11 -5
@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;
sequencer.c +58 -2
114 lines not on this page · raw message
sequencer.h +1 -0
@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +56 -0
76 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v2 2/5] rebase -i: support --committer-date-is-author-date
Hi Phillip,
Thank you for continuing this work.
Le 29/04/2020 à 12:25, Phillip Wood a écrit :
Quoted 40 lines
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 60 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 11 deletions(-)-%<-
sequencer.c +7
-0@@ -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")@@ -872,6 +873,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++)
sequencer.c static char *get_author(const char *message) · line 891
Quoted 10 lines
sequencer.c +10
-0+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" ); +} +
Since GIT_AUTHOR_DATE' is set in read_env_script(), why not set GIT_COMMITTER_DATE' in this function too, instead of looping in the env array just after setting it to get the value back?
Quoted 15 lines
sequencer.c +4
-0static 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 +955,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 ))
sequencer.c static int try_to_commit(struct repository *r, · line 1324
Quoted 4 lines
sequencer.c +0
-1@@ -1321,7 +1342,6 @@ static int try_to_commit(struct repository *r,if (parse_head (r, ¤t_head))return -1 ; -
Nit: don't remove this empty line?
sequencer.c static int try_to_commit(struct repository *r, · line 1347
Quoted 3 lines
sequencer.c +0
-0if (flags &AMEND_MSG ) {const char *exclude_gpgsig[] = {"gpgsig" ,"gpgsig-sha256" ,NULL };const char *out_enc =get_commit_output_encoding ();
Cheers,
Alban
Re: [PATCH v2 2/5] rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodQuoted 346 lines · Phillip Wood
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 60 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 11 deletions(-)Documentation/git-rebase.txt +7
-3@@ -438,9 +438,13 @@ when merging. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.@@ -578,7 +582,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C@@ -606,6 +609,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +11
-5@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;sequencer.c +58
-2@@ -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")@@ -872,6 +873,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 +955,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 ))@@ -1321,7 +1342,6 @@ static int try_to_commit(struct repository *r,if (parse_head (r, ¤t_head))return -1 ; -if (flags &AMEND_MSG ) {const char *exclude_gpgsig[] = {"gpgsig" ,"gpgsig-sha256" ,NULL };const char *out_enc =get_commit_output_encoding ();@@ -1349,6 +1369,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 '%s'" ), author); + 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;@@ -2532,6 +2576,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 +2671,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 +3593,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 +3874,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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +56
-1@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -28,8 +31,13 @@ test_expect_success 'setup' ' EOF git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + git rm --cached foo && + rm foo && sed -e "s/^|//" >file <<-\EOF && |line 1 | line 2@@ -78,6 +86,54 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' test_cmp expect file ' +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + git log -1 --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty="format:%ai" >authortime && + git log --pretty="format:%ci" >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged --
Quoted 1 line
2.26.2
Does this implementation rely on the run_git_commit() path, i.e. is it another place we'll need to fix up to avoid forking a subprocess, or does it work with the try_to_commit() codepath as well?
PATCH v2 3/5 sequencer: rename amend_author to author_to_free
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.
--- sequencer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;
@@ -1356,7 +1356,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));
@@ -1472,7 +1472,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }
Signature · 1 line
2.26.2
PATCH v2 4/5 rebase -i: support --ignore-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 49 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
@@ -443,8 +443,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.
@@ -582,7 +583,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C
@@ -610,6 +610,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +8 -5
@@ -90,6 +90,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -129,6 +130,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1008,6 +1010,8 @@ static int run_am(struct rebase_options *opts)argv_array_push (&am.args,"--ignore-whitespace" );if (opts->committer_date_is_author_date)argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1515,8 +1519,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, +"ignore author date and use current date" ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
@@ -1809,13 +1813,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {
sequencer.c +47 -2
105 lines not on this page · raw message
sequencer.h +1 -0
@@ -46,6 +46,7 @@ struct replay_opts {int quiet;int reschedule_failed_exec;int committer_date_is_author_date; +int ignore_date;int mainline;
t/t3436-rebase-more-options.sh +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v2 4/5] rebase -i: support --ignore-date
Hi Phillip,
Le 29/04/2020 à 12:25, Phillip Wood a écrit :
Quoted 36 lines
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 49 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)-%<-
sequencer.c +2
-0@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")*/ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -889,6 +890,24 @@ static const char *author_date_from_env_array(const struct argv_array *env)BUG ("GIT_AUTHOR_DATE missing from author script" ); } +/* Construct a free()able author string with current time as the author date */
sequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 903
Quoted 10 lines
sequencer.c +10
-0+static char *ignore_author_date (const char *author) +{ +int len =strlen (author); +struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line '%s'" ), author); +return NULL ; + }
Nit: add an empty line here?
Quoted 11 lines
sequencer.c +7
-0+ len = ident.mail_end - ident.name_begin +1 ; + +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} +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"
sequencer.c static int run_git_commit(struct repository *r, · line 984
Quoted 9 lines
sequencer.c +4
-0@@ -957,7 +976,11 @@ static int run_git_commit(struct repository *r,if (opts->committer_date_is_author_date)argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" :author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );
Perhaps this could be done in read_env_script(), too, instead of fixing up what this function did right after calling it, twice? Something like this:
---- snip ----
index 339dbf4a59..3a7a80bab7 100644
sequencer.c +0 -0
@@ -840,11 +840,12 @@ int read_author_script(const char *path, char
**name, char **email, char **date,
}
/*
- * Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a
- * file with shell quoting into struct argv_array. Returns -1 on
- * error, 0 otherwise.
+ * Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE from a
+ * file with shell quoting into struct argv_array, and set
+ * GIT_COMMITTER_DATE if needed. Returns -1 on error, 0 otherwise. */
-static int read_env_script(struct argv_array *env)
+static int read_env_script(struct replay_opts *opts,
+ struct argv_array *env)
{
char *name, *email, *date;@@ -854,7 +855,17 @@ static int read_env_script(struct argv_array *env)
argv_array_pushf(env, "GIT_AUTHOR_NAME=%s", name);
argv_array_pushf(env, "GIT_AUTHOR_EMAIL=%s", email);- argv_array_pushf(env, "GIT_AUTHOR_DATE=%s", date);
+
+ if (opts->ignore_date) {
+ argv_array_push(env, "GIT_AUTHOR_DATE=");
+ argv_array_push(env, "GIT_COMMITTER_DATE=");
+ } else {
+ argv_array_pushf(env, "GIT_AUTHOR_DATE=%s", date);
+
+ if (opts->committer_date_is_author_date)
+ argv_array_pushf(env, "GIT_COMMITTER_DATE=%s",
date);
+ }
+
free(name);
free(email);
free(date);---- snap ----
Quoted 15 lines
sequencer.c +2
-1argv_array_push (&cmd.args,"commit" );@@ -1386,7 +1409,8 @@ static int try_to_commit(struct repository *r,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 ); + res =setenv ("GIT_COMMITTER_DATE" , + opts->ignore_date ?"" : date.buf,1 );strbuf_release (&date);if (res)@@ -1452,6 +1476,15 @@ static int try_to_commit(struct repository *r,reset_ident_date ();
sequencer.c static int try_to_commit(struct repository *r, · line 1487
Quoted 10 lines
sequencer.c +9
-0+if (opts->ignore_date) { + author =ignore_author_date (author); +if (!author) { + res =-1 ; + goto out; + } +free (author_to_free); + author_to_free = (char *)author; + }
Nit: add an empty line here?
Cheers,
Alban
Re: [PATCH v2 4/5] rebase -i: support --ignore-date
Hi Alban
Thanks for looking at this series
Quoted 38 lines · Alban Gruin
Hi Phillip,
Le 29/04/2020 à 12:25, Phillip Wood a écrit :
Quoted 35 lines
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 49 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)-%<-
sequencer.c +1
-0@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")*/ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -889,6 +890,24 @@ static const char *author_date_from_env_array(const struct argv_array *env)BUG ("GIT_AUTHOR_DATE missing from author script" ); }
Quoted 13 lines
sequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 903
Quoted 11 lines
sequencer.c +11
-0+/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author); +struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line '%s'" ), author); +return NULL ; + }Nit: add an empty line here?
and delete the one below?
Quoted 12 lines
Quoted 12 lines
sequencer.c +7
-0+ len = ident.mail_end - ident.name_begin +1 ; + +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} +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"@@ -957,7 +976,11 @@ static int run_git_commit(struct repository *r,
Quoted 12 lines
sequencer.c static int run_git_commit(struct repository *r, · line 984
Quoted 8 lines
sequencer.c +4
-0if (opts->committer_date_is_author_date)argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" :author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );Perhaps this could be done in
read_env_script(), too, instead of fixing up what this function did right after calling it, twice? Something like this:
Long term I'd like to stop writing the author-script file unless we're stopping for a conflict resolution or edit so I'm reluctant to add more functionality to it at the moment. Also I tend to view read_env_script() it as loading the author details from a file rather than setting up the environment for the commit.
Quoted 60 lines
---- snip ----
index339dbf4a59..3a7a80bab7100644sequencer.c +16
-5@@ -840,11 +840,12 @@ int read_author_script(const char *path, char **name, char **email, char **date, }/* -* Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a -* file with shell quoting into struct argv_array. Returns -1 on -* error, 0 otherwise. +* Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE from a +* file with shell quoting into struct argv_array, and set +* GIT_COMMITTER_DATE if needed. Returns -1 on error, 0 otherwise. */ -static int read_env_script (struct argv_array *env) +static int read_env_script (struct replay_opts *opts, +struct argv_array *env) {char *name, *email, *date;@@ -854,7 +855,17 @@ static int read_env_script(struct argv_array *env)argv_array_pushf (env,"GIT_AUTHOR_NAME=%s" , name);argv_array_pushf (env,"GIT_AUTHOR_EMAIL=%s" , email); -argv_array_pushf (env,"GIT_AUTHOR_DATE=%s" , date); + +if (opts->ignore_date) { +argv_array_push (env,"GIT_AUTHOR_DATE=" ); +argv_array_push (env,"GIT_COMMITTER_DATE=" ); + }else { +argv_array_pushf (env,"GIT_AUTHOR_DATE=%s" , date); + +if (opts->committer_date_is_author_date) +argv_array_pushf (env,"GIT_COMMITTER_DATE=%s" , date); + } +free (name);free (email);free(date);---- snap ----
Quoted 16 lines
sequencer.c +2
-1argv_array_push (&cmd.args,"commit" );@@ -1386,7 +1409,8 @@ static int try_to_commit(struct repository *r,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 ); + res =setenv ("GIT_COMMITTER_DATE" , + opts->ignore_date ?"" : date.buf,1 );strbuf_release (&date);if (res)@@ -1452,6 +1476,15 @@ static int try_to_commit(struct repository *r,reset_ident_date ();
Quoted 11 lines
sequencer.c static int try_to_commit(struct repository *r, · line 1487
Quoted 9 lines
sequencer.c +9
-0+if (opts->ignore_date) { + author =ignore_author_date (author); +if (!author) { + res =-1 ; + goto out; + } +free (author_to_free); + author_to_free = (char *)author; + }Nit: add an empty line here?
Yes that would fit the style in the rest of the function
Best Wishes
Phillip
Quoted 4 lines
Cheers,
Alban
Re: [PATCH v2 4/5] rebase -i: support --ignore-date
Quoted 14 lines · Phillip Wood
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2
-0@@ -957,7 +976,11 @@ static int run_git_commit(struct repository *r, if (opts->committer_date_is_author_date) argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s", + opts->ignore_date ? + "" :Quoted 8 lines
Review static int run_git_commit(struct repository *r, · line 983
Quoted 4 lines
(quoted diff) +2
-0author_date_from_env_array(&cmd.env_array)); + if (opts->ignore_date) + argv_array_push(&cmd.env_array, "GIT_AUTHOR_DATE=");Perhaps this could be done in
read_env_script(), too, instead of fixing up what this function did right after calling it, twice? Something like this:
Quoted 5 lines
Long term I'd like to stop writing the author-script file unless we're stopping for a conflict resolution or edit so I'm reluctant to add more functionality to it at the moment. Also I tend to view
read_env_script()it as loading the author details from a file rather than setting up the environment for the commit.
Yeah, the author-script, once the program halts and returns the control to the human-user sitting on the terminal, can be peeked at, and it should record what the program learned from the commit; it smells like a premature optimization to rewrite it to what the program plans to use to replay the commit and lose the information taken from the original.
Re: [PATCH v2 4/5] rebase -i: support --ignore-date
In reply to Phillip WoodQuoted 305 lines · Phillip Wood
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 49 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)Documentation/git-rebase.txt +4
-3@@ -443,8 +443,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.@@ -582,7 +583,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C@@ -610,6 +610,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +8
-5@@ -90,6 +90,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -129,6 +130,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;@@ -1008,6 +1010,8 @@ static int run_am(struct rebase_options *opts)argv_array_push (&am.args,"--ignore-whitespace" );if (opts->committer_date_is_author_date)argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1515,8 +1519,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, +"ignore author date and use current date" ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,@@ -1809,13 +1813,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {sequencer.c +47
-2@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")*/ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -889,6 +890,24 @@ static const char *author_date_from_env_array(const struct argv_array *env)BUG ("GIT_AUTHOR_DATE missing from author script" ); } +/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author); +struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line '%s'" ), author); +return NULL ; + } + len = ident.mail_end - ident.name_begin +1 ; + +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} +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"@@ -957,7 +976,11 @@ static int run_git_commit(struct repository *r,if (opts->committer_date_is_author_date)argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" :author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" );argv_array_push (&cmd.args,"commit" );@@ -1386,7 +1409,8 @@ static int try_to_commit(struct repository *r,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 ); + res =setenv ("GIT_COMMITTER_DATE" , + opts->ignore_date ?"" : date.buf,1 );strbuf_release (&date);if (res)@@ -1452,6 +1476,15 @@ static int try_to_commit(struct repository *r,reset_ident_date (); +if (opts->ignore_date) { + author =ignore_author_date (author); +if (!author) { + res =-1 ; + goto out; + } +free (author_to_free); + author_to_free = (char *)author; + }if (commit_tree_extended (msg->buf, msg->len, &tree, parents, oid, author, opts->gpg_sign, extra)) { res =error (_ ("failed to write commit object" ));@@ -2581,6 +2614,11 @@ static int read_populate_opts(struct replay_opts *opts) opts->committer_date_is_author_date =1 ; } +if (file_exists (rebase_path_ignore_date ())) { + opts->allow_ff =0 ; + opts->ignore_date =1 ; + } +if (file_exists (rebase_path_reschedule_failed_exec ())) opts->reschedule_failed_exec =1 ;@@ -2673,6 +2711,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,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->ignore_date) +write_file (rebase_path_ignore_date (),"%s" ,"" );if (opts->reschedule_failed_exec)write_file (rebase_path_reschedule_failed_exec (),"%s" ,"" );@@ -3595,7 +3635,11 @@ static int do_merge(struct repository *r,if (opts->committer_date_is_author_date)argv_array_pushf (&cmd.env_array,"GIT_COMMITTER_DATE=%s" , + opts->ignore_date ? +"" :author_date_from_env_array (&cmd.env_array)); +if (opts->ignore_date) +argv_array_push (&cmd.env_array,"GIT_AUTHOR_DATE=" ); cmd.git_cmd =1 ;argv_array_push (&cmd.args,"merge" );@@ -3875,7 +3919,8 @@ static int pick_commits(struct repository *r,if (opts->allow_ff)assert (!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit || - opts->committer_date_is_author_date)); + opts->committer_date_is_author_date || + opts->ignore_date));if (read_and_refresh_cache (r, opts))return -1 ;sequencer.h +1
-0@@ -46,6 +46,7 @@ struct replay_opts {int quiet;int reschedule_failed_exec;int committer_date_is_author_date; +int ignore_date;int mainline;t/t3436-rebase-more-options.sh +57
-1@@ -134,6 +134,63 @@ test_expect_success '--committer-date-is-author-date works when committing confl test_cmp expect actual ' +# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with apply backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works with merge backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date -m HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + grep "+0000" authortime +' + +test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -m \ + --onto commit2^^ commit2^ commit2 && + echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +' + +test_expect_success '--ignore-date works with rebase -r' ' + git checkout side && + git merge --no-ff commit3 && + git rebase -r --root --ignore-date && + git log --pretty=%ai >authortime && + ! grep -v "+0000" authortime +' + +test_expect_success '--ignore-date with --committer-date-is-author-date works' ' + test_must_fail git rebase -m --committer-date-is-author-date \ + --ignore-date --onto commit2^^ commit2^ commit3 && + git checkout --theirs foo && + git add foo && + git rebase --continue && + git log -2 --pretty=%ai >authortime && + git log -2 --pretty=%ci >committertime && + test_cmp authortime committertime && + ! grep -v "+0000" authortime +' + +test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' + GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ + git rebase -i --strategy=resolve --ignore-date \ + --committer-date-is-author-date side side && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime && + grep "+0000" authortime + ' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged --
Quoted 1 line
2.26.2
Same question here as for patch 2 -- does it rely on us forking a "git commit" subprocess which reads from the environment variable, or does our try_to_commit() (which I'd rather we used in all cases) also work with the environment variable?
Didn't notice any other problems or questions while reading over the patch.
PATCH v2 5/5 rebase: add --reset-author-date
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
--- Documentation/git-rebase.txt | 1 + builtin/rebase.c | 6 ++++-- t/t3436-rebase-more-options.sh | 34 ++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
@@ -443,6 +443,7 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: +--reset-author-date:: Instead of using the author date of the original commit, use the current time as the author date of the rebased commit. This option implies `--force-rebase`.
builtin/rebase.c +4 -2
@@ -1519,8 +1519,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, -"ignore author date and use current date" ), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
t/t3436-rebase-more-options.sh +22 -12
@@ -137,22 +137,22 @@ test_expect_success '--committer-date-is-author-date works when committing confl # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530. -test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works with merge backend' ' +test_expect_success '--reset-author-date works with merge backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --ignore-date -m HEAD^ && + git rebase --reset-author-date -m HEAD^ && git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works after conflict resolution' ' - test_must_fail git rebase --ignore-date -m \ +test_expect_success '--reset-author-date works after conflict resolution' ' + test_must_fail git rebase --reset-author-date -m \ --onto commit2^^ commit2^ commit2 && echo resolved >foo && git add foo &&
@@ -161,17 +161,17 @@ test_expect_success '--ignore-date works after conflict resolution' ' grep +0000 authortime ' -test_expect_success '--ignore-date works with rebase -r' ' +test_expect_success '--reset-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && - git rebase -r --root --ignore-date && + git rebase -r --root --reset-author-date && git log --pretty=%ai >authortime && ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date with --committer-date-is-author-date works' ' +test_expect_success '--reset-author-date with --committer-date-is-author-date works' ' test_must_fail git rebase -m --committer-date-is-author-date \ - --ignore-date --onto commit2^^ commit2^ commit3 && + --reset-author-date --onto commit2^^ commit2^ commit3 && git checkout --theirs foo && git add foo && git rebase --continue &&
@@ -181,16 +181,26 @@ test_expect_success '--ignore-date with --committer-date-is-author-date works' ' ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' +test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' ' GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ - git rebase -i --strategy=resolve --ignore-date \ + git rebase -i --strategy=resolve --reset-author-date \ --committer-date-is-author-date side side && git log -1 --pretty=%ai >authortime && git log -1 --pretty=%ci >committertime && test_cmp authortime committertime && grep "+0000" authortime ' +test_expect_success '--ignore-date is an alias for --reset-author-date' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && + git rebase -m --ignore-date HEAD^ && + git log -2 --pretty="format:%ai" >authortime && + grep "+0000" authortime >output && + test_line_count = 2 output +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged
Signature · 1 line
2.26.2
Re: [PATCH v2 0/5] cleanup ra/rebase-i-more-options
In reply to Phillip WoodQuoted 3 lines · Phillip Wood
From: Phillip Wood <[email protected]>
I've rebased Rohit's patches on master and reworked them with my
OK, it took a bit of time for me to figure it out, but this does cleanly apply on top of 048abe17 (Sync with 2.26.2, 2020-04-19).
Queued, but haven't taken any deep look at it.
Thanks.
Re: [PATCH v2 0/5] cleanup ra/rebase-i-more-options
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Quoted 8 lines
Quoted 1 line
I've rebased Rohit's patches on master and reworked them with my
OK, it took a bit of time for me to figure it out, but this does cleanly apply on top of
048abe17(Sync with 2.26.2, 2020-04-19).Queued, but haven't taken any deep look at it.
Thanks.
Sorry for the long delay in reviewing. I looked through all five patches; I had the same simple question about patches 2 & 4, and had some comments about the wording of the documentation in patch 1, but all small stuff. I didn't notice anything outside of those few small comments.
v3 cover cleanup ra/rebase-i-more-options
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Thanks for the feedback on v2, I've updated the documentation as suggested by Elijah and made the style fixes suggested by Alban but I've not changed read_author_script() for the reasons explained in
https://lore.kernel.org/git/[email protected]
These patches are based on 9fadedd637 ("Merge branch 'ds/default-pack-use-sparse-to-true'", 2020-03-29)
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date
Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date
Documentation/git-rebase.txt | 33 +++- builtin/rebase.c | 46 ++++-- sequencer.c | 111 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 209 +++++++++++++++++++++++++ 6 files changed, 379 insertions(+), 24 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Range-diff against v2:
1: 5ef315240a ! 1: df8c4ed2e9 rebase -i: add --ignore-whitespace flag
@@ Documentation/git-rebase.txt: your branch contains commits which were dropped, t
with --keep-base in order to drop those commits from your branch.
--ignore-whitespace::
-+ Behaves differently depending on which backend is selected.
++ Ignore whitespace differences when trying to reconcile
++differences. Currently, each backend implements an approximation of ++this behavior:
++
+apply backend: When applying a patch, ignore changes in whitespace in
-+context lines.
++context lines. Unfortunately, this means that if the "old" lines being ++replaced by the patch differ only in whitespace from the existing ++file, you will get a merge conflict instead of a successful patch ++application.
++
+merge backend: Treat lines with only whitespace changes as unchanged
-+when merging.
++when merging. Unfortunately, this means that any patch hunks that were ++intended to modify whitespace and nothing else will be dropped, even ++if the other side had no changes that conflicted.
+
--whitespace=<option>::
- These flags are passed to the 'git apply' program
2: 55eb3a7efc ! 2: df44a0bde6 rebase -i: support --committer-date-is-author-date
@@ Commit message
## Documentation/git-rebase.txt ##
-@@ Documentation/git-rebase.txt: when merging.
+@@ Documentation/git-rebase.txt: if the other side had no changes that conflicted.
See also INCOMPATIBLE OPTIONS below.
--committer-date-is-author-date::
@@ sequencer.c: static int run_git_commit(struct repository *r,
if (!(flags & VERIFY_MSG))
@@ sequencer.c: static int try_to_commit(struct repository *r,
-
- if (parse_head(r, ¤t_head))
- return -1;
--
- if (flags & AMEND_MSG) {
- const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
- const char *out_enc = get_commit_output_encoding();
-@@ sequencer.c: static int try_to_commit(struct repository *r,
commit_list_insert(current_head, &parents);
}
3: 19352fdc22 = 3: fa3d4856b4 sequencer: rename amend_author to author_to_free
4: 5e971abb74 ! 4: 96657233d4 rebase -i: support --ignore-date
@@ sequencer.c: static const char *author_date_from_env_array(const struct argv_arr
+ error(_("malformed ident line '%s'"), author);
+ return NULL;
+ }
++
+ len = ident.mail_end - ident.name_begin + 1;
-+
+ strbuf_addf(&new_author, "%.*s ", len, ident.name_begin);
+ datestamp(&new_author);
+ return strbuf_detach(&new_author, NULL);
@@ sequencer.c: static int try_to_commit(struct repository *r,
+ free(author_to_free);
+ author_to_free = (char *)author;
+ }
++
if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
oid, author, opts->gpg_sign, extra)) {
res = error(_("failed to write commit object"));5: 43a097c583 = 5: 828155baba rebase: add --reset-author-date
Signature · 1 line
2.26.2
PATCH v3 1/5 rebase -i: add --ignore-whitespace flag
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 19 +++++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +
@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +15 -4
@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;
@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;
@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }
@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;
@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
t/t3436-rebase-more-options.sh new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v3 2/5 rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 59 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +7 -3
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +11 -5
@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;
sequencer.c +58 -1
107 lines not on this page · raw message
sequencer.h +1 -0
@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +56 -0
76 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v3 3/5 sequencer: rename amend_author to author_to_free
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.
--- sequencer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;
@@ -1357,7 +1357,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));
@@ -1473,7 +1473,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }
Signature · 1 line
2.26.2
PATCH v3 4/5 rebase -i: support --ignore-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 50 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +8 -5
@@ -90,6 +90,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -129,6 +130,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1008,6 +1010,8 @@ static int run_am(struct rebase_options *opts)argv_array_push (&am.args,"--ignore-whitespace" );if (opts->committer_date_is_author_date)argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1515,8 +1519,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, +"ignore author date and use current date" ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
@@ -1809,13 +1813,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {
sequencer.c +48 -2
106 lines not on this page · raw message
sequencer.h +1 -0
@@ -46,6 +46,7 @@ struct replay_opts {int quiet;int reschedule_failed_exec;int committer_date_is_author_date; +int ignore_date;int mainline;
t/t3436-rebase-more-options.sh +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Phillip,
t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 143
Quoted 7 lines · Phillip Wood
t/t3436-rebase-more-options.sh +7
-0+# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with apply backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime &&
Those --pretty="format:%ai" won't print the newline character in my test environment.
It looks like it won't print the newline if stdout isn't a tty.
git log -1 --pretty=%ai
doesn't have that issue.
I think there're some grep out there considers file doesn't end with newline as non-text files.
Quoted 9 lines
t/t3436-rebase-more-options.sh +9
-0+ grep "+0000" authortime +' + +test_expect_success '--ignore-date works with merge backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date -m HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + grep "+0000" authortime +'
t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 162
Quoted 10 lines
t/t3436-rebase-more-options.sh +10
-0+ +test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -m \ + --onto commit2^^ commit2^ commit2 && + echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +'
From the test's name, I guess git-rebase is supposed to continue respect --ignore-date after conflict resolution.
But the content of authortime read:
2020-05-23 12:13:58 +0000 1999-04-02 08:03:20 +0530 1999-04-02 08:03:20 +0530
It's still pass "grep +0000 authortime" because of first line, I'm not sure if I missed anything.
Signature · 1 line
Danh
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Danh
Quoted 15 lines · Đoàn Trần Công Danh
Hi Phillip,
t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 143
Quoted 7 lines · Phillip Wood
t/t3436-rebase-more-options.sh +7
-0+# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with apply backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime &&Those --pretty="format:%ai" won't print the newline character in my test environment.
It looks like it won't print the newline if stdout isn't a tty.
Quoted 6 lines
git log -1 --pretty=%aidoesn't have that issue.
I think there're some grep out there considers file doesn't end with newline as non-text files.
Yes it would be better to print the newline, thanks
Quoted 23 lines
Quoted 9 lines
t/t3436-rebase-more-options.sh +9
-0+ grep "+0000" authortime +' + +test_expect_success '--ignore-date works with merge backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --ignore-date -m HEAD^ && + git log -1 --pretty="format:%ai" >authortime && + grep "+0000" authortime +'t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 162
Quoted 10 lines
t/t3436-rebase-more-options.sh +10
-0+ +test_expect_success '--ignore-date works after conflict resolution' ' + test_must_fail git rebase --ignore-date -m \ + --onto commit2^^ commit2^ commit2 && + echo resolved >foo && + git add foo && + git rebase --continue && + git log --pretty=%ai >authortime && + grep +0000 authortime +'From the test's name, I guess git-rebase is supposed to continue
respect --ignore-date after conflict resolution.
Quoted 8 lines
But the content of authortime read:
2020-05-23 12:13:58 +0000 1999-04-02 08:03:20 +0530 1999-04-02 08:03:20 +0530It's still pass "grep +0000 authortime" because of first line, I'm not sure if I missed anything.
It's only rebasing one commit - the log command is missing -1. I've checked the log invocations in the other tests and I think they're all OK.
Junio - are you happy to fix this up (assuming there are no other issues) or do you want a re-roll?
Thanks
Phillip
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Phillip
Quoted 17 lines · Phillip Wood
Quoted 17 lines · Phillip Wood
t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 143
Quoted 7 lines
t/t3436-rebase-more-options.sh +7
-0+# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with apply backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime &&Those --pretty="format:%ai" won't print the newline character in my test environment.
It looks like it won't print the newline if stdout isn't a tty.git log -1 --pretty=%aidoesn't have that issue.
Quoted 7 lines
Quoted 2 lines
I think there're some grep out there considers file doesn't end with newline as non-text files.
Yes it would be better to print the newline, thanks
Junio - are you happy to fix this up (assuming there are no other issues) or do you want a re-roll?
There're 11 invocation of git-log with "--pretty=format", in 2/5 and 4/5
I think it's worth to have a re-roll to avoid mistake.
Signature · 1 line
Danh
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Danh
Quoted 25 lines · Đoàn Trần Công Danh
Hi Phillip
Quoted 22 lines · Phillip Wood
Quoted 13 lines · Phillip Wood
t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 143
Quoted 7 lines
t/t3436-rebase-more-options.sh +7
-0+# Checking for +0000 in author time is enough since default +# timezone is UTC, but the timezone used while committing +# sets to +0530. +test_expect_success '--ignore-date works with apply backend' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git log -1 --pretty="format:%ai" >authortime &&Those --pretty="format:%ai" won't print the newline character in my test environment.
It looks like it won't print the newline if stdout isn't a tty.Quoted 6 lines
git log -1 --pretty=%aidoesn't have that issue.
I think there're some grep out there considers file doesn't end with newline as non-text files.
Yes it would be better to print the newline, thanks
Quoted 7 lines
Quoted 2 lines
Junio - are you happy to fix this up (assuming there are no other issues) or do you want a re-roll?
There're 11 invocation of git-log with "--pretty=format", in 2/5 and 4/5
I think it's worth to have a re-roll to avoid mistake.
The part of my reply you've cut said "I've checked the log invocations in the other tests and I think they're all OK." So it is just the one that you pointed out that needs to be fixed up (the others without -1 are all checking the result of rebase --root). I'm happy to re-roll if Junio wants - lets wait and see what he says.
Best Wishes
Phillip
Phillip
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Phillip,
Quoted 6 lines · Phillip Wood
The part of my reply you've cut said "I've checked the log invocations in the other tests and I think they're all OK." So it is just the one that you pointed out that needs to be fixed up (the others without -1 are all checking the result of rebase --root). I'm happy to re-roll if Junio wants - lets wait and see what he says.
Ah, I was thinking "they're all OK" meant that part can be left as-is, and the only part need to change is the --pretty=format.
Sorry for the noise, (and my bad in reading).
Signature · 1 line
Danh
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
Hi Danh
Quoted 10 lines · Đoàn Trần Công Danh
Hi Phillip,
Quoted 6 lines · Phillip Wood
The part of my reply you've cut said "I've checked the log invocations in the other tests and I think they're all OK." So it is just the one that you pointed out that needs to be fixed up (the others without -1 are all checking the result of rebase --root). I'm happy to re-roll if Junio wants - lets wait and see what he says.
Quoted 4 lines
Ah, I was thinking "they're all OK" meant that part can be left as-is, and the only part need to change is the --pretty=format.
Sorry for the noise, (and my bad in reading).
Looking at the patches again I think I misunderstood what you were saying - I had not twigged that I needed to remove the 'format:' from all the git log invocations. I'll send a reroll later.
Sorry for the confusion
Phillip
Re: [PATCH v3 4/5] rebase -i: support --ignore-date
In reply to Đoàn Trần Công DanhQuoted 5 lines · Đoàn Trần Công Danh
Quoted 5 lines
Quoted 2 lines
I think there're some grep out there considers file doesn't end with newline as non-text files.
Yes it would be better to print the newline, thanks
Quoted 7 lines
Quoted 2 lines
Junio - are you happy to fix this up (assuming there are no other issues) or do you want a re-roll?
There're 11 invocation of git-log with "--pretty=format", in 2/5 and 4/5
I think it's worth to have a re-roll to avoid mistake.
It would be appropriate to send "[PATCH v3 6/5] fixup! ..." if the fix needs to be made only to a single step. It would be the least error-prone approach.
Thanks.
PATCH v3 5/5 rebase: add --reset-author-date
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
--- Documentation/git-rebase.txt | 1 + builtin/rebase.c | 6 ++++-- t/t3436-rebase-more-options.sh | 34 ++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: +--reset-author-date:: Instead of using the author date of the original commit, use the current time as the author date of the rebased commit. This option implies `--force-rebase`.
builtin/rebase.c +4 -2
@@ -1519,8 +1519,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, -"ignore author date and use current date" ), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
t/t3436-rebase-more-options.sh +22 -12
@@ -137,22 +137,22 @@ test_expect_success '--committer-date-is-author-date works when committing confl # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530. -test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works with merge backend' ' +test_expect_success '--reset-author-date works with merge backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --ignore-date -m HEAD^ && + git rebase --reset-author-date -m HEAD^ && git log -1 --pretty="format:%ai" >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works after conflict resolution' ' - test_must_fail git rebase --ignore-date -m \ +test_expect_success '--reset-author-date works after conflict resolution' ' + test_must_fail git rebase --reset-author-date -m \ --onto commit2^^ commit2^ commit2 && echo resolved >foo && git add foo &&
@@ -161,17 +161,17 @@ test_expect_success '--ignore-date works after conflict resolution' ' grep +0000 authortime ' -test_expect_success '--ignore-date works with rebase -r' ' +test_expect_success '--reset-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && - git rebase -r --root --ignore-date && + git rebase -r --root --reset-author-date && git log --pretty=%ai >authortime && ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date with --committer-date-is-author-date works' ' +test_expect_success '--reset-author-date with --committer-date-is-author-date works' ' test_must_fail git rebase -m --committer-date-is-author-date \ - --ignore-date --onto commit2^^ commit2^ commit3 && + --reset-author-date --onto commit2^^ commit2^ commit3 && git checkout --theirs foo && git add foo && git rebase --continue &&
@@ -181,16 +181,26 @@ test_expect_success '--ignore-date with --committer-date-is-author-date works' ' ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' +test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' ' GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ - git rebase -i --strategy=resolve --ignore-date \ + git rebase -i --strategy=resolve --reset-author-date \ --committer-date-is-author-date side side && git log -1 --pretty=%ai >authortime && git log -1 --pretty=%ci >committertime && test_cmp authortime committertime && grep "+0000" authortime ' +test_expect_success '--ignore-date is an alias for --reset-author-date' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && + git rebase -m --ignore-date HEAD^ && + git log -2 --pretty="format:%ai" >authortime && + grep "+0000" authortime >output && + test_line_count = 2 output +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged
Signature · 1 line
2.26.2
Re: [PATCH v3 0/5] cleanup ra/rebase-i-more-options
In reply to Phillip WoodQuoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Thanks for the feedback on v2, I've updated the documentation as suggested by Elijah and made the style fixes suggested by Alban but I've not changed
read_author_script()for the reasons explained in
https://lore.kernel.org/git/[email protected]
All my questions were answered earlier; this round addressed my remaining feedback and I see no new issues.
Re: [PATCH v3 0/5] cleanup ra/rebase-i-more-options
Quoted 9 lines · Elijah Newren
Quoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Thanks for the feedback on v2, I've updated the documentation as suggested by Elijah and made the style fixes suggested by Alban but I've not changed
read_author_script()for the reasons explained in
https://lore.kernel.org/git/[email protected]
Quoted 4 lines
All my questions were answered earlier; this round addressed my remaining feedback and I see no new issues.
Reviewed-by Elijah Newren <[email protected]>
Thanks Elijah
Re: [PATCH v3 0/5] cleanup ra/rebase-i-more-options
In reply to Phillip WoodHi Phillip,
Quoted 9 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Thanks for the feedback on v2, I've updated the documentation as suggested by Elijah and made the style fixes suggested by Alban but I've not changed
read_author_script()for the reasons explained in
https://lore.kernel.org/git/[email protected]These patches are based on
9fadedd637("Merge branch 'ds/default-pack-use-sparse-to-true'", 2020-03-29)
Thank you for working on these patches! TBH what I was looking to most in that GSoC project was the ability to combine --interactive with Sverre's --whitespace=fix option, but it never came even close to that. So I had planned to help this patch series as much as I can.
Turns out that I do not really have any time to help this patch series, therefore I am very happy to see Danh and Elijah jump in and review the patch series, and that makes me think that between the three of you, it is in good hands now.
Thanks,
Dscho
Quoted 95 lines
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-dateRohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: renameamend_authortoauthor_to_free
rebase: add --reset-author-dateDocumentation/git-rebase.txt | 33 +++- builtin/rebase.c | 46 ++++-- sequencer.c | 111 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 209 +++++++++++++++++++++++++ 6 files changed, 379 insertions(+), 24 deletions(-) create mode 100755 t/t3436-rebase-more-options.shRange-diff against v2:
1:5ef315240a! 1:df8c4ed2e9rebase -i: add --ignore-whitespace flag
@@Documentation/git-rebase.txt: your branch contains commits which were dropped, t
with--keep-basein order to drop those commits from your branch.--ignore-whitespace::
-+ Behaves differently depending on which backend is selected.
++ Ignore whitespace differences when trying to reconcile
++differences. Currently, each backend implements an approximation of ++this behavior:
++
+apply backend: When applying a patch, ignore changes in whitespace in
-+context lines.
++context lines. Unfortunately, this means that if the "old" lines being ++replaced by the patch differ only in whitespace from the existing ++file, you will get a merge conflict instead of a successful patch ++application.
++
+merge backend: Treat lines with only whitespace changes as unchanged
-+when merging.
++when merging. Unfortunately, this means that any patch hunks that were ++intended to modify whitespace and nothing else will be dropped, even ++if the other side had no changes that conflicted.
+
--whitespace=<option>::
- These flags are passed to the 'git apply' program
2:55eb3a7efc! 2:df44a0bde6rebase -i: support --committer-date-is-author-date
@@ Commit messageSigned-off-by Phillip Wood <[email protected]>##
Documentation/git-rebase.txt##
-@@Documentation/git-rebase.txt: when merging.
+@@Documentation/git-rebase.txt: if the other side had no changes that conflicted.
See also INCOMPATIBLE OPTIONS below.--committer-date-is-author-date::
@@sequencer.c: static int run_git_commit(struct repository *r,if (!(flags &
VERIFY_MSG))
@@sequencer.c: static int try_to_commit(struct repository *r,
-
- if (parse_head(r, ¤t_head))
- return -1;
--
- if (flags &AMEND_MSG) {
- const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
- const char*out_enc=get_commit_output_encoding();
-@@sequencer.c: static int try_to_commit(struct repository *r,
commit_list_insert(current_head, &parents);
}3: 19352fdc22 = 3: fa3d4856b4 sequencer: rename amend_author to author_to_free 4: 5e971abb74 ! 4: 96657233d4 rebase -i: support --ignore-date @@ sequencer.c: static const char *author_date_from_env_array(const struct argv_arr + error(_("malformed ident line '%s'"), author); + return NULL; + } ++ + len = ident.mail_end - ident.name_begin + 1; -+ + strbuf_addf(&new_author, "%.*s ", len, ident.name_begin); + datestamp(&new_author); + return strbuf_detach(&new_author, NULL); @@ sequencer.c: static int try_to_commit(struct repository *r, + free(author_to_free); + author_to_free = (char *)author; + } ++ if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid, author, opts->gpg_sign, extra)) { res = error(_("failed to write commit object"));5:
43a097c583= 5:828155babarebase: add --reset-author-date--
2.26.2
v4 cover cleanup ra/rebase-i-more-options
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Thanks to Danh for the review, I've updated the tests accordingly.
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date
Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date
Documentation/git-rebase.txt | 33 +++- builtin/rebase.c | 46 ++++-- sequencer.c | 111 ++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 209 +++++++++++++++++++++++++ 6 files changed, 379 insertions(+), 24 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Range-diff against v3:
1: df8c4ed2e9 = 1: df8c4ed2e9 rebase -i: add --ignore-whitespace flag
2: df44a0bde6 ! 2: ad21e5d8fb rebase -i: support --committer-date-is-author-date
@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-whitespace is reme
+test_expect_success '--committer-date-is-author-date works with apply backend' '
+ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+ git rebase --apply --committer-date-is-author-date HEAD^ &&
-+ git log -1 --pretty="format:%ai" >authortime &&
-+ git log -1 --pretty="format:%ci" >committertime &&
++ git log -1 --pretty=%ai >authortime &&
++ git log -1 --pretty=%ci >committertime &&
+ test_cmp authortime committertime
+'
+
+test_expect_success '--committer-date-is-author-date works with merge backend' '
+ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+ git rebase -m --committer-date-is-author-date HEAD^ &&
-+ git log -1 --pretty="format:%ai" >authortime &&
-+ git log -1 --pretty="format:%ci" >committertime &&
++ git log -1 --pretty=%ai >authortime &&
++ git log -1 --pretty=%ci >committertime &&
+ test_cmp authortime committertime
+'
+
+test_expect_success '--committer-date-is-author-date works with rebase -r' '
+ git checkout side &&
+ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+ git rebase -r --root --committer-date-is-author-date &&
-+ git log --pretty="format:%ai" >authortime &&
-+ git log --pretty="format:%ci" >committertime &&
++ git log --pretty=%ai >authortime &&
++ git log --pretty=%ci >committertime &&
+ test_cmp authortime committertime
+'
+
+test_expect_success '--committer-date-is-author-date works when forking merge' '
+ git checkout side &&
+ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+ git rebase -r --root --strategy=resolve --committer-date-is-author-date &&
-+ git log --pretty="format:%ai" >authortime &&
-+ git log --pretty="format:%ci" >committertime &&
++ git log --pretty=%ai >authortime &&
++ git log --pretty=%ci >committertime &&
+ test_cmp authortime committertime
+
+'
3: fa3d4856b4 = 3: af92e29cf9 sequencer: rename amend_author to author_to_free
4: 96657233d4 ! 4: 4399dc19b6 rebase -i: support --ignore-date
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
+test_expect_success '--ignore-date works with apply backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
+ git rebase --apply --ignore-date HEAD^ &&
-+ git log -1 --pretty="format:%ai" >authortime &&
++ git log -1 --pretty=%ai >authortime &&
+ grep "+0000" authortime
+'
+
+test_expect_success '--ignore-date works with merge backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
+ git rebase --ignore-date -m HEAD^ &&
-+ git log -1 --pretty="format:%ai" >authortime &&
++ git log -1 --pretty=%ai >authortime &&
+ grep "+0000" authortime
+'
+
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
+ echo resolved >foo &&
+ git add foo &&
+ git rebase --continue &&
-+ git log --pretty=%ai >authortime &&
++ git log -1 --pretty=%ai >authortime &&
+ grep +0000 authortime
+'
+
5: 828155baba ! 5: a11db78eb4 rebase: add --reset-author-date
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
git commit --amend --date="$GIT_AUTHOR_DATE" &&
- git rebase --apply --ignore-date HEAD^ &&
+ git rebase --apply --reset-author-date HEAD^ &&
- git log -1 --pretty="format:%ai" >authortime &&
+ git log -1 --pretty=%ai >authortime &&
grep "+0000" authortime
'
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
git commit --amend --date="$GIT_AUTHOR_DATE" &&
- git rebase --ignore-date -m HEAD^ &&
+ git rebase --reset-author-date -m HEAD^ &&
- git log -1 --pretty="format:%ai" >authortime &&
+ git log -1 --pretty=%ai >authortime &&
grep "+0000" authortime
'Signature · 1 line
2.25.1.551.gd3318bf0d3.dirty
PATCH v4 1/5 rebase -i: add --ignore-whitespace flag
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 19 +++++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +
@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +15 -4
@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;
@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;
@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }
@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts); +if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;
@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
t/t3436-rebase-more-options.sh new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v4 1/5] rebase -i: add --ignore-whitespace flag
Hi Phillip,
sorry to be _so_ late in the game. (And sorry for sending this to you twice, I managed to skip all the Cc:s due to the Reply-To: header the first time round.)
Quoted 6 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to
As a non-native speaker, I am thrown off when reading "available to" instead of the grammatically correct (I believe) "available in". Likewise, "on going" instead of "ongoing" just disrupts my workflow.
Maybe these can be fixed?
Quoted 82 lines
remove the apply backend this patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
Signed-off-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 19 +++++- builtin/rebase.c | 19 ++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 86 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100755 t/t3436-rebase-more-options.shDocumentation/git-rebase.txt +17
-2@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +2
-0@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec;
builtin/rebase.c static struct replay_opts get_replay_opts(const struct rebase_options *opts) · line 137
Quoted 10 lines
builtin/rebase.c +6
-1replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);
Quite honestly, this is very, very ugly.
I would have expected this at a way earlier layer, namely in cmd__rebase(). Something along these lines:
-- snip --
builtin/rebase.c +12 -3
@@ -1289,6 +1289,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;
@@ -1318,9 +1319,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("passed to 'git am'" )),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL , N_("passed to 'git am'"), PARSE_OPT_NOARG),
@@ -1682,6 +1682,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); } +if (ignore_whitespace) { +if (options.type ==REBASE_APPLY ) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); +else +string_list_append (&stragey_options, +"--ignore-space-change" ); + } +if (strategy_options.nr) {int i;
-- snap --
Quoted 11 lines
builtin/rebase.c +1
-0if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }
builtin/rebase.c int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) · line 550
Quoted 4 lines
builtin/rebase.c +1
-0@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts);
I am not sure what this is about: opts.strategy_opts is of type char *, i.e. it is supposed to be already allocated.
Not that cmd_rebase__interactive() matters _all_ that much anymore, of
course: it is only used by the --preserve-merges backend, which will hopefully be retired soon.
Quoted 81 lines
builtin/rebase.c +5
-3+if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +31
-0@@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && +
t/t3436-rebase-more-options.sh line 41
Quoted 10 lines
t/t3436-rebase-more-options.sh new file +10
-0+ git checkout --orphan master && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +'
The file contents are repeated in an awfully repetitive manner. That not only makes things a bit hard to read, it also makes it all too easy to slip in bugs by mistake. How about something like this instead?
test_commit file && test_write_lines line1 Qline2 line3 >templ && q_to_tab <templ >file.t && git commit -m tab file.t && sed "s/Q/new /" <templ >file.t && git commit -m new file.t && git tag side && git checkout file -- && sed "s/Q/ /" <templ >file.t && git commit -m spaces file.t
... and then...
t/t3436-rebase-more-options.sh line 48
Quoted 7 lines
t/t3436-rebase-more-options.sh new file +7
-0+ +test_expect_success '--ignore-whitespace works with apply backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF
sed "s/Q/new /" <templ >expect
t/t3436-rebase-more-options.sh line 52
Quoted 4 lines
t/t3436-rebase-more-options.sh new file +4
-0+ test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + test_cmp expect file
Personally, I prefer to read the contents of expect directly before the test_cmp expect file.t
t/t3436-rebase-more-options.sh line 60
Quoted 8 lines
t/t3436-rebase-more-options.sh new file +8
-0+' + +test_expect_success '--ignore-whitespace works with merge backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF
Isn't this totally identical to the expect constructed earlier? And in any case, isn't this identical to git show main:file.t, which is what we _actually_ expect: for the file contents to be identical to the tagged main? I.e.
git diff --exit-code main
Quoted 8 lines
t/t3436-rebase-more-options.sh new file +8
-0+ test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF &&
t/t3436-rebase-more-options.sh line 78
Quoted 10 lines
t/t3436-rebase-more-options.sh new file +10
-0+ line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side + ) && + git rebase --continue && + test_cmp expect file
It is a bit funny to see these two invocations _specifically_ pulled out from the subshell, that's not how we do things in other test scripts:
instead, we run all the Git commands _inside_ the subshell, and all the verifications after the subshell.
I believe that with my suggestions, this test script will be a ton easier to read and to maintain. At least it will be a lot DRYer.
Ciao,
Dscho
Quoted 12 lines
t/t3436-rebase-more-options.sh new file +8
-1+' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_done --2.26.2
RE: [PATCH v4 1/5] rebase -i: add --ignore-whitespace flag
As a non-native speaker, I am thrown off when reading "available to"
instead of the grammatically correct (I believe) "available in". Likewise, "on going" instead of "ongoing" just disrupts my workflow.
Maybe these can be fixed?
[RK] There is a distinct difference between "available to" and "available in".
[RK] "service A is available to entity B" does not mean the same as "service A is available in entity B". The former indicates that service A is implemented within entity B, the latter indicates merely that entity B uses service A.
[RK] As a real world example consider "The internet banking service of Bank X is available to me", which makes complete sense. But "The internet banking service of Bank X is available in me" would be nonsense. I don't know what the OP intended but the difference between these is not purely grammatical, there is a difference in meaning which I must leave the OP to clarify.
[RK] As for the other issue, I too would suggest "ongoing".
[RK] Regards,
[RK] Richard.
Re: [PATCH v4 1/5] rebase -i: add --ignore-whitespace flag
In reply to Johannes SchindelinHi dscho
Thanks for taking a look at this
Quoted 15 lines · Johannes Schindelin
Hi Phillip,
sorry to be _so_ late in the game. (And sorry for sending this to you twice, I managed to skip all the Cc:s due to the Reply-To: header the first time round.)
Quoted 6 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particuar the apply backend supports a number of options implemented by 'git am' that are not available to the merge backend. As part of an on going effort to
Quoted 5 lines
As a non-native speaker, I am thrown off when reading "available to" instead of the grammatically correct (I believe) "available in". Likewise, "on going" instead of "ongoing" just disrupts my workflow.
Maybe these can be fixed?
Sure
Quoted 35 lines
Quoted 22 lines
builtin/rebase.c +2
-0@@ -86,6 +86,7 @@ struct rebase_options {int signoff;int allow_rerere_autoupdate;int autosquash; +int ignore_whitespace;char *gpg_sign_opt;int autostash;char *cmd;@@ -108,6 +109,7 @@ struct rebase_options {static struct replay_opts get_replay_opts (const struct rebase_options *opts) { +struct strbuf strategy_buf =STRBUF_INIT ;struct replay_opts replay =REPLAY_OPTS_INIT ; replay.action =REPLAY_INTERACTIVE_REBASE ;@@ -126,14 +128,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec;builtin/rebase.c static struct replay_opts get_replay_opts(const struct rebase_options *opts) · line 137
Quoted 10 lines
builtin/rebase.c +6
-1replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts) -parse_strategy_opts (&replay, opts->strategy_opts); +strbuf_addstr (&strategy_buf, opts->strategy_opts); +if (opts->ignore_whitespace) +strbuf_addstr (&strategy_buf," --ignore-space-change" ); +if (strategy_buf.len) +parse_strategy_opts (&replay, strategy_buf.buf);Quite honestly, this is very, very ugly.
Quoted 2 lines
I would have expected this at a way earlier layer, namely in
cmd__rebase(). Something along these lines:
Yes your version is definitely better, I'll update with that (I had left this patch mostly alone as unlike the later ones the original actually worked)
Quoted 164 lines
-- snip --
builtin/rebase.c +12
-4@@ -1289,6 +1289,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;@@ -1318,9 +1319,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("passed to 'git am'" )),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL , N_("passed to 'git am'"), PARSE_OPT_NOARG),@@ -1682,6 +1682,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); } +if (ignore_whitespace) { +if (options.type ==REBASE_APPLY ) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); +else +string_list_append (&stragey_options, +"--ignore-space-change" ); + } +if (strategy_options.nr) {int i; -- snap --Quoted 13 lines
builtin/rebase.c +1
-0if (opts->squash_onto) {oidcpy (&replay.squash_onto, opts->squash_onto); replay.have_squash_onto =1 ; } +strbuf_release (&strategy_buf);return replay; }builtin/rebase.c int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) · line 550
Quoted 4 lines
builtin/rebase.c +1
-0@@ -539,6 +547,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, builtin_rebase_interactive_usage,PARSE_OPT_KEEP_ARGV0 ); + opts.strategy_opts =xstrdup_or_null (opts.strategy_opts);I am not sure what this is about:
opts.strategy_optsis of typechar *, i.e. it is supposed to be already allocated.Not that
cmd_rebase__interactive()matters _all_ that much anymore, of
course: it is only used by the --preserve-merges backend, which will hopefully be retired soon.Quoted 81 lines
builtin/rebase.c +5
-3+if (!is_null_oid (&squash_onto)) opts.squash_onto = &squash_onto;@@ -991,6 +1001,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd =1 ;argv_array_push (&am.args,"am" ); +if (opts->ignore_whitespace) +argv_array_push (&am.args,"--ignore-whitespace" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1495,16 +1507,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &options.ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +31
-0@@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && +t/t3436-rebase-more-options.sh line 41
Quoted 10 lines
t/t3436-rebase-more-options.sh new file +10
-0+ git checkout --orphan master && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +'The file contents are repeated in an awfully repetitive manner. That not only makes things a bit hard to read, it also makes it all too easy to slip in bugs by mistake. How about something like this instead?
Quoted 14 lines
test_commit file && test_write_lines line1 Qline2 line3 >templ && q_to_tab <templ >file.t && git commit -m tab file.t && sed "s/Q/new /" <templ >file.t && git commit -m new file.t && git tag side && git checkout file -- && sed "s/Q/ /" <templ >file.t && git commit -m spaces file.t
I'm not totally convinced by this, I'd prefer to be able to read the contents rather than having to work out what sed is doing. What about
test_write_lines "line 1" " line 2" "line 3" >file &&
add and committest_write_lines "line 1" "new line 2" "line 3" >file && commit and tagtest_write_lines "line 1" " line 2" "line 3" >file && commit and tag
It does not get rid of the repetition but it does dispense with having the work out what sed and q_to_tab are doing
Quoted 12 lines
... and then...
t/t3436-rebase-more-options.sh line 48
Quoted 7 lines
t/t3436-rebase-more-options.sh new file +7
-0+ +test_expect_success '--ignore-whitespace works with apply backend' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOFsed "s/Q/new /" <templ >expect
Quoted 7 lines
t/t3436-rebase-more-options.sh line 52
Quoted 4 lines
t/t3436-rebase-more-options.sh new file +4
-0+ test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + test_cmp expect filePersonally, I prefer to read the contents of
expectdirectly before thetest_cmp expect file.t
I can move it but if we use sed you cannot see the contents
Quoted 5 lines
Quoted 5 lines
t/t3436-rebase-more-options.sh new file +5
-0+' + +test_expect_success '--ignore-whitespace works with merge backend' ' + cat >expect <<-\EOF && + line 1
Quoted 8 lines
t/t3436-rebase-more-options.sh line 60
Quoted 3 lines
t/t3436-rebase-more-options.sh new file +3
-0+ new line 2 + line 3 + EOFIsn't this totally identical to the
expectconstructed earlier? And in any case, isn't this identical togit show main:file.t, which is what we _actually_ expect: for the file contents to be identical to the taggedmain? I.e.
Well spotted I'll update (I think it's actually the same as side)
Quoted 17 lines
git diff --exit-code mainQuoted 15 lines
t/t3436-rebase-more-options.sh new file +15
-0+ test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side
Quoted 8 lines
t/t3436-rebase-more-options.sh line 78
Quoted 3 lines
t/t3436-rebase-more-options.sh new file +3
-0+ ) && + git rebase --continue && + test_cmp expect fileIt is a bit funny to see these two invocations _specifically_ pulled out from the subshell, that's not how we do things in other test scripts:
instead, we run all the Git commands _inside_ the subshell, and all the verifications after the subshell.
The idea was to only set the variable where it is used.
Best Wishes
Phillip
Quoted 18 lines
I believe that with my suggestions, this test script will be a ton easier to read and to maintain. At least it will be a lot DRYer.
Ciao,
DschoQuoted 12 lines
t/t3436-rebase-more-options.sh new file +8
-1+' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_done --2.26.2
Re: [PATCH v4 1/5] rebase -i: add --ignore-whitespace flag
Hi Phillip,
Quoted 84 lines · Phillip Wood
Quoted 58 lines · Johannes Schindelin
Quoted 40 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
[...]
t/t3436-rebase-more-options.sh new file +31
-0@@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + q_to_tab >file <<-\EOF && + line 1 + Qline 2 + line 3 + EOF + git add file && + git commit -m "add file" && + cat >file <<-\EOF && + line 1 + new line 2 + line 3 + EOF + git commit -am "update file" && + git tag side && +t/t3436-rebase-more-options.sh line 41
Quoted 10 lines
t/t3436-rebase-more-options.sh new file +10
-0+ git checkout --orphan master && + sed -e "s/^|//" >file <<-\EOF && + |line 1 + | line 2 + |line 3 + EOF + git add file && + git commit -m "add file" && + git tag main +'The file contents are repeated in an awfully repetitive manner. That not only makes things a bit hard to read, it also makes it all too easy to slip in bugs by mistake. How about something like this instead?
Quoted 14 lines
test_commit file && test_write_lines line1 Qline2 line3 >templ && q_to_tab <templ >file.t && git commit -m tab file.t && sed "s/Q/new /" <templ >file.t && git commit -m new file.t && git tag side && git checkout file -- && sed "s/Q/ /" <templ >file.t && git commit -m spaces file.tI'm not totally convinced by this, I'd prefer to be able to read the contents rather than having to work out what sed is doing. What about
test_write_lines"line 1" " line 2" "line 3" >file &&
add and committest_write_lines"line 1" "new line 2" "line 3" >file && commit and tagtest_write_lines"line 1" " line 2" "line 3" >file && commit and tag
Quoted 2 lines
It does not get rid of the repetition but it does dispense with having the work out what sed and
q_to_tabare doing
Sure. Your version is still tons easier to parse for a human being.
Quoted 26 lines
Quoted 17 lines
git diff --exit-code mainQuoted 15 lines
t/t3436-rebase-more-options.sh new file +15
-0+ test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + test_cmp expect file +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + cat >expect <<-\EOF && + line 1 + new line 2 + line 3 + EOF + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace main sideQuoted 8 lines
t/t3436-rebase-more-options.sh line 59
Quoted 3 lines
t/t3436-rebase-more-options.sh new file +3
-0+ ) && + git rebase --continue && + test_cmp expect fileIt is a bit funny to see these two invocations _specifically_ pulled out from the subshell, that's not how we do things in other test scripts:
instead, we run all the Git commands _inside_ the subshell, and all the verifications after the subshell.
Quoted 1 line
The idea was to only set the variable where it is used.
I understand that, but I think that it would be better to follow the existing pattern rather than introducing an inconsistent second one.
Thanks,
Dscho
PATCH v4 2/5 rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 59 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +7 -3
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +11 -5
@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;
sequencer.c +58 -1
107 lines not on this page · raw message
sequencer.h +1 -0
@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +56 -0
76 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v4 2/5] rebase -i: support --committer-date-is-author-date
Hi Phillip,
Quoted 4 lines · Phillip Wood
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
I forgot to mention this in my reply to the first patch in this series: it strikes me as a mis-characterization that the apply backend is about to be retired. What _is_ true is that the merge backend is the default backend, and what is even more true is that it is cumbersome if certain rebase options cannot be combined because they are only implemented by one of both rebase backends.
Quoted 70 lines
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 59 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 10 deletions(-)Documentation/git-rebase.txt +7
-3@@ -445,9 +445,13 @@ if the other side had no changes that conflicted. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +3
-0@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
builtin/rebase.c static int run_am(struct rebase_options *opts) · line 1010
Quoted 5 lines
builtin/rebase.c +2
-0@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );
As before, I would rather see this in cmd__rebase() rahn in run_am().
Quoted 78 lines
builtin/rebase.c +6
-5if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;sequencer.c +21
-0@@ -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")@@ -872,6 +873,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 +955,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 ))
sequencer.c static int try_to_commit(struct repository *r, · line 1374
Quoted 5 lines
sequencer.c +2
-0@@ -1349,6 +1370,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);
Given that len is used only once, is this local variable really necessary? You could just as well pass (int)strlen(author) in the split_ident_line() call below.
Quoted 7 lines
sequencer.c +7
-0+struct ident_split ident; +struct strbuf date =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { + res =error (_ ("malformed ident line '%s'" ), author); + goto out; + }
sequencer.c static int try_to_commit(struct repository *r, · line 1391
Quoted 10 lines
sequencer.c +10
-0+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);
It might be easier to read if it was written this way:
if (split_ident_line(...) < 0)
res = ...
else if (!ident.date_begin)
res = ...
else {
strbuf_addf(...)
res = ...
strbuf_release(&date);
}
if (res)
goto out;Quoted 103 lines
sequencer.c +18
-1+ +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;@@ -2532,6 +2577,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 +2672,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 +3594,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 +3875,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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +8
-0@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -28,8 +31,13 @@ test_expect_success 'setup' ' EOF git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + git rm --cached foo && + rm foo && sed -e "s/^|//" >file <<-\EOF && |line 1 | line 2
t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 94
Quoted 9 lines
t/t3436-rebase-more-options.sh +6
-0@@ -78,6 +86,54 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' test_cmp expect file ' +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime
This seems to be a repeated pattern. To dry it up, it would make sense to do this:
test_ctime_is_atime () {
git log -1 --pretty=%ai >authortime &&
git log -1 --pretty=%ci >committertime &&
test_cmp authortime committertime
}Ciao,
Dscho
Quoted 49 lines
t/t3436-rebase-more-options.sh +42
-1+' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + git log --pretty=%ai >authortime && + git log --pretty=%ci >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty=%ai >authortime && + git log --pretty=%ci >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged --2.26.2
Re: [PATCH v4 2/5] rebase -i: support --committer-date-is-author-date
Hi dscho
Quoted 9 lines · Johannes Schindelin
Hi Phillip,
Quoted 4 lines · Phillip Wood
From: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --committer-date-is-author-date.
Quoted 6 lines
I forgot to mention this in my reply to the first patch in this series: it strikes me as a mis-characterization that the
applybackend is about to be retired. What _is_ true is that themergebackend is the default backend, and what is even more true is that it is cumbersome if certainrebaseoptions cannot be combined because they are only implemented by one of both rebase backends.
I'm not trying to imply that the apply backend is about to be retired but it is the long term plan to get rid of it isn't it?
Quoted 34 lines
Quoted 34 lines
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 16 ++++--- sequencer.c | 59 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 10 deletions(-)builtin/rebase.c +3
-0@@ -89,6 +89,7 @@ struct rebase_options {int ignore_whitespace;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -126,6 +127,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
Quoted 8 lines
builtin/rebase.c static int run_am(struct rebase_options *opts) · line 1010
Quoted 6 lines
builtin/rebase.c +2
-0@@ -1003,6 +1006,8 @@ static int run_am(struct rebase_options *opts)if (opts->ignore_whitespace)argv_array_push (&am.args,"--ignore-whitespace" ); +if (opts->committer_date_is_author_date) +argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" );As before, I would rather see this in
cmd__rebase()rahn inrun_am().
Right I'll take a look at that
Quoted 81 lines
Quoted 81 lines
builtin/rebase.c +6
-5if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);@@ -1507,9 +1512,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),@@ -1804,11 +1809,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;sequencer.c +21
-0@@ -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")@@ -872,6 +873,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 +955,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 ))@@ -1349,6 +1370,30 @@ static int try_to_commit(struct repository *r,commit_list_insert (current_head, &parents); }
Quoted 6 lines
sequencer.c static int try_to_commit(struct repository *r, · line 1374
Quoted 2 lines
sequencer.c +2
-0+if (opts->committer_date_is_author_date) { +int len =strlen (author);Given that
lenis used only once, is this local variable really necessary? You could just as well pass(int)strlen(author)in thesplit_ident_line()call below.
I wonder if it makes the split_ident_line() line too long, I'll take a look.
Quoted 20 lines
Quoted 7 lines
sequencer.c +7
-0+struct ident_split ident; +struct strbuf date =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { + res =error (_ ("malformed ident line '%s'" ), author); + goto out; + }sequencer.c static int try_to_commit(struct repository *r, · line 1391
Quoted 10 lines
sequencer.c +10
-0+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);It might be easier to read if it was written this way:
Quoted 12 lines
if (split_ident_line(...) < 0)
res = ...
else if (!ident.date_begin)
res = ...
else {
strbuf_addf(...)
res = ...
strbuf_release(&date);
}
if (res)
goto out;I'm not sure. The current style of "if there's an error goto out" makes the control flow clear without having to reason ones way through a series of else ifs
Quoted 116 lines
Quoted 103 lines
sequencer.c +18
-1+ +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;@@ -2532,6 +2577,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 +2672,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 +3594,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 +3875,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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +8
-0@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -28,8 +31,13 @@ test_expect_success 'setup' ' EOF git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + git rm --cached foo && + rm foo && sed -e "s/^|//" >file <<-\EOF && |line 1 | line 2t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 94
Quoted 9 lines
t/t3436-rebase-more-options.sh +6
-0@@ -78,6 +86,54 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' test_cmp expect file ' +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertimeThis seems to be a repeated pattern. To dry it up, it would make sense to do this:
Quoted 5 lines
test_ctime_is_atime () {
git log -1 --pretty=%ai >authortime &&
git log -1 --pretty=%ci >committertime &&
test_cmp authortime committertime
}Good suggestion (though we need to parametrize the -1 so we can use it with the rebase --root cases)
Thanks
Phillip
Quoted 53 lines
Ciao,
DschoQuoted 49 lines
t/t3436-rebase-more-options.sh +42
-1+' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + git log -1 --pretty=%ai >authortime && + git log -1 --pretty=%ci >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + git log --pretty=%ai >authortime && + git log --pretty=%ci >committertime && + test_cmp authortime committertime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --strategy=resolve --committer-date-is-author-date && + git log --pretty=%ai >authortime && + git log --pretty=%ci >committertime && + test_cmp authortime committertime + +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + git log -1 --format=%at HEAD >expect && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo && + git add foo && + git rebase --continue && + git log -1 --format=%ct HEAD >actual && + test_cmp expect actual +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged --2.26.2
PATCH v4 3/5 sequencer: rename amend_author to author_to_free
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.
--- sequencer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;
@@ -1357,7 +1357,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));
@@ -1473,7 +1473,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }
Signature · 1 line
2.26.2
PATCH v4 4/5 rebase -i: support --ignore-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
As part of the on-going effort to retire the apply rebase backend teach the merge backend how to handle --ignore-date. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 50 +++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +8 -5
@@ -90,6 +90,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -129,6 +130,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1008,6 +1010,8 @@ static int run_am(struct rebase_options *opts)argv_array_push (&am.args,"--ignore-whitespace" );if (opts->committer_date_is_author_date)argv_array_push (&opts->git_am_opts,"--committer-date-is-author-date" ); +if (opts->ignore_date) +argv_array_push (&opts->git_am_opts,"--ignore-date" );if (opts->action && !strcmp ("continue" , opts->action)) {argv_array_push (&am.args,"--resolved" );argv_array_pushf (&am.args,"--resolvemsg=%s" , resolvemsg);
@@ -1515,8 +1519,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, +"ignore author date and use current date" ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
@@ -1809,13 +1813,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {
sequencer.c +48 -2
106 lines not on this page · raw message
sequencer.h +1 -0
@@ -46,6 +46,7 @@ struct replay_opts {int quiet;int reschedule_failed_exec;int committer_date_is_author_date; +int ignore_date;int mainline;
t/t3436-rebase-more-options.sh +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v4 5/5 rebase: add --reset-author-date
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
--- Documentation/git-rebase.txt | 1 + builtin/rebase.c | 6 ++++-- t/t3436-rebase-more-options.sh | 34 ++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: +--reset-author-date:: Instead of using the author date of the original commit, use the current time as the author date of the rebased commit. This option implies `--force-rebase`.
builtin/rebase.c +4 -2
@@ -1519,8 +1519,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, -"ignore author date and use current date" ), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
t/t3436-rebase-more-options.sh +22 -12
@@ -137,22 +137,22 @@ test_expect_success '--committer-date-is-author-date works when committing confl # Checking for +0000 in author time is enough since default # timezone is UTC, but the timezone used while committing # sets to +0530. -test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && git log -1 --pretty=%ai >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works with merge backend' ' +test_expect_success '--reset-author-date works with merge backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --ignore-date -m HEAD^ && + git rebase --reset-author-date -m HEAD^ && git log -1 --pretty=%ai >authortime && grep "+0000" authortime ' -test_expect_success '--ignore-date works after conflict resolution' ' - test_must_fail git rebase --ignore-date -m \ +test_expect_success '--reset-author-date works after conflict resolution' ' + test_must_fail git rebase --reset-author-date -m \ --onto commit2^^ commit2^ commit2 && echo resolved >foo && git add foo &&
@@ -161,17 +161,17 @@ test_expect_success '--ignore-date works after conflict resolution' ' grep +0000 authortime ' -test_expect_success '--ignore-date works with rebase -r' ' +test_expect_success '--reset-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && - git rebase -r --root --ignore-date && + git rebase -r --root --reset-author-date && git log --pretty=%ai >authortime && ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date with --committer-date-is-author-date works' ' +test_expect_success '--reset-author-date with --committer-date-is-author-date works' ' test_must_fail git rebase -m --committer-date-is-author-date \ - --ignore-date --onto commit2^^ commit2^ commit3 && + --reset-author-date --onto commit2^^ commit2^ commit3 && git checkout --theirs foo && git add foo && git rebase --continue &&
@@ -181,16 +181,26 @@ test_expect_success '--ignore-date with --committer-date-is-author-date works' ' ! grep -v "+0000" authortime ' -test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' +test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' ' GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ - git rebase -i --strategy=resolve --ignore-date \ + git rebase -i --strategy=resolve --reset-author-date \ --committer-date-is-author-date side side && git log -1 --pretty=%ai >authortime && git log -1 --pretty=%ci >committertime && test_cmp authortime committertime && grep "+0000" authortime ' +test_expect_success '--ignore-date is an alias for --reset-author-date' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && + git rebase -m --ignore-date HEAD^ && + git log -2 --pretty="format:%ai" >authortime && + grep "+0000" authortime >output && + test_line_count = 2 output +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged
Signature · 1 line
2.26.2
[PATCH v4 6/5] fixup! rebase: add --reset-author-date
From: Phillip Wood <[email protected]>
Sorry I somehow forgot to commit this before sending the v4 patches, it fixes up the final patch
--- t/t3436-rebase-more-options.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t3436-rebase-more-options.sh +1 -1
@@ -196,7 +196,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git rebase --apply --ignore-date HEAD^ && git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && - git log -2 --pretty="format:%ai" >authortime && + git log -2 --pretty=%ai >authortime && grep "+0000" authortime >output && test_line_count = 2 output '
Signature · 1 line
2.26.2
Re: [PATCH v4 6/5] fixup! rebase: add --reset-author-date
Quoted 15 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Sorry I somehow forgot to commit this before sending the v4 patches, it fixes up the final patch
Signed-off-by Phillip Wood <[email protected]>--- t/t3436-rebase-more-options.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t3436-rebase-more-options.sh +0
-0
t/t3436-rebase-more-options.sh test_expect_success '--ignore-date is an alias for --reset-author-date' ' · line 202
Quoted 8 lines
t/t3436-rebase-more-options.sh +1
-1@@ -196,7 +196,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git rebase --apply --ignore-date HEAD^ && git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && - git log -2 --pretty="format:%ai" >authortime && + git log -2 --pretty=%ai >authortime && grep "+0000" authortime >output && test_line_count = 2 output '
This version addressed all of my concerns, LGTM.
Only the last
test_line_count = 2 output
puzzled me at first.
Since it's the only usage of test_line_count in this version Turn out, it's equivalence with:
-----------8<-----------
t/t3436-rebase-more-options.sh +1 -2
@@ -197,8 +197,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && git log -2 --pretty=%ai >authortime && - grep "+0000" authortime >output && - test_line_count = 2 output + ! grep -v "+0000" authortime ' # This must be the last test in this file
------>8------
This is the check used in t3436.15
Current version is good as is, anyway.
Signature · 1 line
Danh
Re: [PATCH v4 6/5] fixup! rebase: add --reset-author-date
Hi,
Quoted 40 lines · Đoàn Trần Công Danh
Quoted 15 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Sorry I somehow forgot to commit this before sending the v4 patches, it fixes up the final patch
Signed-off-by Phillip Wood <[email protected]>--- t/t3436-rebase-more-options.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t3436-rebase-more-options.sh +0
-0t/t3436-rebase-more-options.sh test_expect_success '--ignore-date is an alias for --reset-author-date' ' · line 202
Quoted 8 lines
t/t3436-rebase-more-options.sh +1
-1@@ -196,7 +196,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git rebase --apply --ignore-date HEAD^ && git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && - git log -2 --pretty="format:%ai" >authortime && + git log -2 --pretty=%ai >authortime && grep "+0000" authortime >output && test_line_count = 2 output 'This version addressed all of my concerns, LGTM.
Only the last
test_line_count= 2 outputpuzzled me at first.
Since it's the only usage oftest_line_countin this version Turn out, it's equivalence with:
-----------8<-----------t/t3436-rebase-more-options.sh +0
-0
t/t3436-rebase-more-options.sh test_expect_success '--ignore-date is an alias for --reset-author-date' '
Quoted 10 lines
t/t3436-rebase-more-options.sh +1
-3@@ -197,8 +197,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && git log -2 --pretty=%ai >authortime && - grep "+0000" authortime >output && - test_line_count = 2 output + ! grep -v "+0000" authortime ' # This must be the last test in this file ------>8------
Good suggestion!
I've read through all 5 patches, and rather than repeating much of what I said about 1/5 and 2/5 in 4/5, I'll just say it here that it applies there, too: less repetitions in the test script, and I'd prefer the layer where the apply vs merge options are set to be cmd__rebase() rather than run_am() (and get_replay_opts()).
All in all, it was a pleasant read.
Thanks,
Dscho
Re: [PATCH v4 6/5] fixup! rebase: add --reset-author-date
Hi dscho and Danh
Quoted 52 lines · Johannes Schindelin
Hi,
Quoted 48 lines · Đoàn Trần Công Danh
Quoted 15 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Sorry I somehow forgot to commit this before sending the v4 patches, it fixes up the final patch
Signed-off-by Phillip Wood <[email protected]>--- t/t3436-rebase-more-options.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t3436-rebase-more-options.sh +0
-0t/t3436-rebase-more-options.sh test_expect_success '--ignore-date is an alias for --reset-author-date' ' · line 202
Quoted 8 lines
t/t3436-rebase-more-options.sh +1
-1@@ -196,7 +196,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git rebase --apply --ignore-date HEAD^ && git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && - git log -2 --pretty="format:%ai" >authortime && + git log -2 --pretty=%ai >authortime && grep "+0000" authortime >output && test_line_count = 2 output 'This version addressed all of my concerns, LGTM.
Only the last
test_line_count= 2 outputpuzzled me at first.
Since it's the only usage oftest_line_countin this version Turn out, it's equivalence with:
-----------8<-----------t/t3436-rebase-more-options.sh +1
-2@@ -197,8 +197,7 @@ test_expect_success '--ignore-date is an alias for --reset-author-date' ' git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && git rebase -m --ignore-date HEAD^ && git log -2 --pretty=%ai >authortime && - grep "+0000" authortime >output && - test_line_count = 2 output + ! grep -v "+0000" authortime '
Quoted 4 lines
t/t3436-rebase-more-options.sh test_expect_success '--ignore-date is an alias for --reset-author-date' '
Quoted 2 lines
t/t3436-rebase-more-options.sh +0
-1# This must be the last test in this file ------>8------Good suggestion!
Yes thanks Danh I'll update with that
Quoted 3 lines
I've read through all 5 patches, and rather than repeating much of what I said about 1/5 and 2/5 in 4/5, I'll just say it here that it applies there, too: less repetitions in the test script,
I'll look at adding a helper for to do the checks
Quoted 3 lines
and I'd prefer the layer
where theapplyvsmergeoptions are set to becmd__rebase()rather thanrun_am()(andget_replay_opts()).
Yeah that would make it nicer.
Quoted 1 line
All in all, it was a pleasant read.
Thanks for your comments on this series
Phillip
Quoted 3 lines
Thanks,
Dscho
Re: [PATCH v4 0/5] cleanup ra/rebase-i-more-options
In reply to Phillip WoodQuoted 2 lines · Phillip Wood
-+ git log -1 --pretty="format:%ai" >authortime &&
++ git log -1 --pretty=%ai >authortime &&It probably wouldn't make too much of a difference in real life, but I think "--format=%ai" is how the above is customary written.
Some history.
The --pretty="format:<string with per-cent placeholder>" came first, with an explicit goal of giving us enough flexibility to mimick canned "pretty print" formats like --pretty=medium, --pretty=short, etc. (note: it was *not* part of the goal to actually replace the implementation of canned formats with hardcoded set of placeholder strings).
If you run "git log --pretty=medium -2", you'd observe that the topmost commit is shown immediately without any preceding blank line, then an extra blank line is shown, and then the second commit is shown, and after that, the output ends without any extra blank line. With respect to the "extra blank line", we call this "separator semantics"---an extra blank is given _between_ two items that are shown.
Like "git log --pretty=medium", the "format:<custom>" pretty print format uses the "separator semantics". There is no "extra LF" after showing the last item.
Of course, the "separator" behaviour was later found to be cumbersome if we wanted to mimick "--pretty=oneline". The payload of each item in the oneline output format lacks the terminating LF, so instead of an extra LF between two items, we want an extra LF after every item. This, in contrast to "separator" semantics, is called "terminator" semantics and --pretty="tformat:<custom>" was introduced to allow.
Later, when we introduced --format=<format>, we made it so that
(1) when <format> is equal to one of the canned format names,
"--format=<format>" is equivalent to "--<format>".
(2) otherwise, when <format> has placeholders, "--format=<format>" acts the same way as "--pretty=tformat:<format>".
as we found out that people are often using custom format that consists of only one line of payload, quite often as a way to extract a handful of "fields" from each commit object.
So given all of the above, the "let's grab the author-time in iso format and nothing else from each commit object" in the above excerpt from your test is the use case for which --format=%ai was designed.
v5 cover cleanup ra/rebase-i-more-options
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
I've updated the commit messages, option handling and tests as suggested by dscho. I've also changed the tests that used '--strategy=resolve' to use a real external merge strategy so they continue to test the same code path once Alban's patches to handle the resolve strategy without forking are merged
Thanks for the review
Phillip
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date
Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date
Documentation/git-rebase.txt | 33 ++++- builtin/rebase.c | 44 ++++-- sequencer.c | 112 ++++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 180 +++++++++++++++++++++++++ 6 files changed, 350 insertions(+), 23 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Range-diff against v4:
1: df8c4ed2e9 ! 1: 43ee10d4d5 rebase -i: add --ignore-whitespace flag
@@ Metadata
## Commit message ##
rebase -i: add --ignore-whitespace flag
- Rebase is implemented with two different backends - 'apply' and 'merge'
- each of which support a different set of options. In particuar the apply
- backend supports a number of options implemented by 'git am' that are
- not available to the merge backend. As part of an on going effort to
- remove the apply backend this patch adds support for the
+ Rebase is implemented with two different backends - 'apply' and
+ 'merge' each of which support a different set of options. In
+ particular the apply backend supports a number of options implemented
+ by 'git am' that are not implemented in the merge backend. This means
+ that the available options are different depending on which backend is
+ used which is confusing. This patch adds support for the
--ignore-whitespace option to the merge backend. This option treats
lines with only whitespace changes as unchanged and is implemented in
the merge backend by translating it to -Xignore-space-change.
@@ Documentation/git-rebase.txt: In addition, the following pairs of options are in
## builtin/rebase.c ##
-@@ builtin/rebase.c: struct rebase_options {
- int signoff;
- int allow_rerere_autoupdate;
- int autosquash;
-+ int ignore_whitespace;
- char *gpg_sign_opt;
- int autostash;
- char *cmd;
-@@ builtin/rebase.c: struct rebase_options {
-
- static struct replay_opts get_replay_opts(const struct rebase_options *opts)
- {
-+ struct strbuf strategy_buf = STRBUF_INIT;
- struct replay_opts replay = REPLAY_OPTS_INIT;
-
- replay.action = REPLAY_INTERACTIVE_REBASE;
@@ builtin/rebase.c: static struct replay_opts get_replay_opts(const struct rebase_options *opts)
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
replay.strategy = opts->strategy;
+
if (opts->strategy_opts)
-- parse_strategy_opts(&replay, opts->strategy_opts);
-+ strbuf_addstr(&strategy_buf, opts->strategy_opts);
-+ if (opts->ignore_whitespace)
-+ strbuf_addstr(&strategy_buf, " --ignore-space-change");
-+ if (strategy_buf.len)
-+ parse_strategy_opts(&replay, strategy_buf.buf);
-
- if (opts->squash_onto) {
- oidcpy(&replay.squash_onto, opts->squash_onto);
- replay.have_squash_onto = 1;
- }
-
-+ strbuf_release(&strategy_buf);
- return replay;
- }
-
-@@ builtin/rebase.c: int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
- argc = parse_options(argc, argv, prefix, options,
- builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
-
-+ opts.strategy_opts = xstrdup_or_null(opts.strategy_opts);
-+
- if (!is_null_oid(&squash_onto))
- opts.squash_onto = &squash_onto;
-
-@@ builtin/rebase.c: static int run_am(struct rebase_options *opts)
- am.git_cmd = 1;
- argv_array_push(&am.args, "am");
-
-+ if (opts->ignore_whitespace)
-+ argv_array_push(&am.args, "--ignore-whitespace");
- if (opts->action && !strcmp("continue", opts->action)) {
- argv_array_push(&am.args, "--resolved");
- argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+ parse_strategy_opts(&replay, opts->strategy_opts);
+
+@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
+ struct strbuf revisions = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ struct object_id merge_base;
++ int ignore_whitespace = 0;
+ enum action action = ACTION_NONE;
+ const char *gpg_sign = NULL;
+ struct string_list exec = STRING_LIST_INIT_NODUP;
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
OPT_BOOL(0, "signoff", &options.signoff,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
N_("passed to 'git am'"), PARSE_OPT_NOARG),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
N_("passed to 'git apply'"), 0),
-+ OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
++ OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
+ N_("ignore changes in whitespace")),
OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
N_("action"), N_("passed to 'git apply'"), 0),
OPT_BIT('f', "force-rebase", &options.flags,
+@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
+ imply_merge(&options, "--rebase-merges");
+ }
+
++ if (options.type == REBASE_APPLY) {
++ if (ignore_whitespace)
++ argv_array_push (&options.git_am_opts,
++ "--ignore-whitespace");
++ } else if (ignore_whitespace) {
++ string_list_append (&strategy_options,
++ "ignore-space-change");
++ }
++
+ if (strategy_options.nr) {
+ int i;
+
## t/t3422-rebase-incompatible-options.sh ##
@@ t/t3422-rebase-incompatible-options.sh: test_rebase_am_only () {
@@ t/t3436-rebase-more-options.sh (new)
+# both the backends fall short of optimal behaviour.
+test_expect_success 'setup' '
+ git checkout -b topic &&
-+ q_to_tab >file <<-\EOF &&
-+ line 1
-+ Qline 2
-+ line 3
-+ EOF
++ test_write_lines "line 1" " line 2" "line 3" >file &&
+ git add file &&
+ git commit -m "add file" &&
-+ cat >file <<-\EOF &&
-+ line 1
-+ new line 2
-+ line 3
-+ EOF
++
++ test_write_lines "line 1" "new line 2" "line 3" >file &&
+ git commit -am "update file" &&
+ git tag side &&
+
+ git checkout --orphan master &&
-+ sed -e "s/^|//" >file <<-\EOF &&
-+ |line 1
-+ | line 2
-+ |line 3
-+ EOF
-+ git add file &&
-+ git commit -m "add file" &&
++ test_write_lines "line 1" " line 2" "line 3" >file &&
++ git commit -am "add file" &&
+ git tag main
+'
+
+test_expect_success '--ignore-whitespace works with apply backend' '
-+ cat >expect <<-\EOF &&
-+ line 1
-+ new line 2
-+ line 3
-+ EOF
+ test_must_fail git rebase --apply main side &&
+ git rebase --abort &&
+ git rebase --apply --ignore-whitespace main side &&
-+ test_cmp expect file
++ git diff --exit-code side
+'
+
+test_expect_success '--ignore-whitespace works with merge backend' '
-+ cat >expect <<-\EOF &&
-+ line 1
-+ new line 2
-+ line 3
-+ EOF
+ test_must_fail git rebase --merge main side &&
+ git rebase --abort &&
+ git rebase --merge --ignore-whitespace main side &&
-+ test_cmp expect file
++ git diff --exit-code side
+'
+
+test_expect_success '--ignore-whitespace is remembered when continuing' '
-+ cat >expect <<-\EOF &&
-+ line 1
-+ new line 2
-+ line 3
-+ EOF
+ (
+ set_fake_editor &&
-+ FAKE_LINES="break 1" git rebase -i --ignore-whitespace main side
++ FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
++ main side &&
++ git rebase --continue
+ ) &&
-+ git rebase --continue &&
-+ test_cmp expect file
++ git diff --exit-code side
+'
+
+# This must be the last test in this file
2: ad21e5d8fb ! 2: a2b57df19c rebase -i: support --committer-date-is-author-date
@@ Metadata
## Commit message ##
rebase -i: support --committer-date-is-author-date
- As part of the on-going effort to retire the apply rebase backend teach
- the merge backend how to handle --committer-date-is-author-date.
+ Rebase is implemented with two different backends - 'apply' and
+ 'merge' each of which support a different set of options. In
+ particular the apply backend supports a number of options implemented
+ by 'git am' that are not implemented in the merge backend. This means
+ that the available options are different depending on which backend is
+ used which is confusing. This patch adds support for the
+ --committer-date-is-author-date option to the merge backend. This
+ option uses the author date of the commit that is being rewritten as
+ the committer date when the new commit is created.
Original-patch-by: Rohit Ashiwal <[email protected]>
Signed-off-by: Phillip Wood <[email protected]>
@@ Documentation/git-rebase.txt: In addition, the following pairs of options are in
## builtin/rebase.c ##
@@ builtin/rebase.c: struct rebase_options {
- int ignore_whitespace;
+ int autosquash;
char *gpg_sign_opt;
int autostash;
+ int committer_date_is_author_date;
@@ builtin/rebase.c: static struct replay_opts get_replay_opts(const struct rebase_
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
replay.strategy = opts->strategy;
-@@ builtin/rebase.c: static int run_am(struct rebase_options *opts)
-
- if (opts->ignore_whitespace)
- argv_array_push(&am.args, "--ignore-whitespace");
-+ if (opts->committer_date_is_author_date)
-+ argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date");
- if (opts->action && !strcmp("continue", opts->action)) {
- argv_array_push(&am.args, "--resolved");
- argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
OPT_BOOL(0, "signoff", &options.signoff,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
!strcmp(option, "--whitespace=fix") ||
!strcmp(option, "--whitespace=strip"))
allow_preemptive_ff = 0;
+@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
+ if (ignore_whitespace)
+ argv_array_push (&options.git_am_opts,
+ "--ignore-whitespace");
++ if (options.committer_date_is_author_date)
++ argv_array_push(&options.git_am_opts,
++ "--committer-date-is-author-date");
+ } else if (ignore_whitespace) {
+ string_list_append (&strategy_options,
+ "ignore-space-change");
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
@@ sequencer.c: static int try_to_commit(struct repository *r,
}
+ 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) {
++ if (split_ident_line(&ident, author, (int)strlen(author)) < 0) {
+ res = error(_("malformed ident line '%s'"), author);
+ goto out;
+ }
@@ sequencer.c: static int try_to_commit(struct repository *r,
+ }
+
+ 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);
++ (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);
+
@@ t/t3436-rebase-more-options.sh: test_description='tests to ensure compatibility
# provide the same output. It was done intentionally because
# both the backends fall short of optimal behaviour.
@@ t/t3436-rebase-more-options.sh: test_expect_success 'setup' '
- EOF
+ test_write_lines "line 1" "new line 2" "line 3" >file &&
git commit -am "update file" &&
git tag side &&
+ test_commit commit1 foo foo1 &&
+ test_commit commit2 foo foo2 &&
+ test_commit commit3 foo foo3 &&
git checkout --orphan master &&
-+ git rm --cached foo &&
+ rm foo &&
- sed -e "s/^|//" >file <<-\EOF &&
- |line 1
- | line 2
+ test_write_lines "line 1" " line 2" "line 3" >file &&
+ git commit -am "add file" &&
+- git tag main
++ git tag main &&
++
++ mkdir test-bin &&
++ write_script test-bin/git-merge-test <<-\EOF
++ exec git-merge-recursive "$@"
++ EOF
+ '
+
+ test_expect_success '--ignore-whitespace works with apply backend' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-whitespace is remembered when continuing' '
- test_cmp expect file
+ git diff --exit-code side
'
++test_ctime_is_atime () {
++ git log $1 --format=%ai >authortime &&
++ git log $1 --format=%ci >committertime &&
++ test_cmp authortime committertime
++}
++
+test_expect_success '--committer-date-is-author-date works with apply backend' '
+ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+ git rebase --apply --committer-date-is-author-date HEAD^ &&
-+ git log -1 --pretty=%ai >authortime &&
-+ git log -1 --pretty=%ci >committertime &&
-+ test_cmp authortime committertime
++ test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with merge backend' '
+ GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+ git rebase -m --committer-date-is-author-date HEAD^ &&
-+ git log -1 --pretty=%ai >authortime &&
-+ git log -1 --pretty=%ci >committertime &&
-+ test_cmp authortime committertime
++ test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with rebase -r' '
+ git checkout side &&
+ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+ git rebase -r --root --committer-date-is-author-date &&
-+ git log --pretty=%ai >authortime &&
-+ git log --pretty=%ci >committertime &&
-+ test_cmp authortime committertime
++ test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when forking merge' '
+ git checkout side &&
+ GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
-+ git rebase -r --root --strategy=resolve --committer-date-is-author-date &&
-+ git log --pretty=%ai >authortime &&
-+ git log --pretty=%ci >committertime &&
-+ test_cmp authortime committertime
-+
++ PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
++ --committer-date-is-author-date &&
++ test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
+ git checkout commit2 &&
+ GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
-+ git log -1 --format=%at HEAD >expect &&
+ test_must_fail git rebase -m --committer-date-is-author-date \
+ --onto HEAD^^ HEAD^ &&
+ echo resolved > foo &&
+ git add foo &&
+ git rebase --continue &&
-+ git log -1 --format=%ct HEAD >actual &&
-+ test_cmp expect actual
++ test_ctime_is_atime -1
+'
+
# This must be the last test in this file
3: af92e29cf9 = 3: 363a0140ad sequencer: rename amend_author to author_to_free
4: 4399dc19b6 ! 4: 46d9e108be rebase -i: support --ignore-date
@@ Metadata
## Commit message ##
rebase -i: support --ignore-date
- As part of the on-going effort to retire the apply rebase backend
- teach the merge backend how to handle --ignore-date. We take care to
- handle the combination of --ignore-date and
- --committer-date-is-author-date in the same way as the apply backend.
+ Rebase is implemented with two different backends - 'apply' and
+ 'merge' each of which support a different set of options. In
+ particular the apply backend supports a number of options implemented
+ by 'git am' that are not implemented in the merge backend. This means
+ that the available options are different depending on which backend is
+ used which is confusing. This patch adds support for the --ignore-date
+ option to the merge backend. This option uses the current time as the
+ author date rather than reusing the original author date when
+ rewriting commits. We take care to handle the combination of
+ --ignore-date and --committer-date-is-author-date in the same way as
+ the apply backend.
Original-patch-by: Rohit Ashiwal <[email protected]>
Signed-off-by: Phillip Wood <[email protected]>
@@ builtin/rebase.c: static struct replay_opts get_replay_opts(const struct rebase_
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
replay.strategy = opts->strategy;
-@@ builtin/rebase.c: static int run_am(struct rebase_options *opts)
- argv_array_push(&am.args, "--ignore-whitespace");
- if (opts->committer_date_is_author_date)
- argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date");
-+ if (opts->ignore_date)
-+ argv_array_push(&opts->git_am_opts, "--ignore-date");
- if (opts->action && !strcmp("continue", opts->action)) {
- argv_array_push(&am.args, "--resolved");
- argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "committer-date-is-author-date",
&options.committer_date_is_author_date,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
+ "ignore author date and use current date"),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
N_("passed to 'git apply'"), 0),
- OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
+ OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
options.autosquash) {
allow_preemptive_ff = 0;
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
!strcmp(option, "--whitespace=strip"))
allow_preemptive_ff = 0;
else if (skip_prefix(option, "-C", &p)) {
+@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
+ if (options.committer_date_is_author_date)
+ argv_array_push(&options.git_am_opts,
+ "--committer-date-is-author-date");
++ if (options.ignore_date)
++ argv_array_push(&options.git_am_opts, "--ignore-date");
+ } else if (ignore_whitespace) {
+ string_list_append (&strategy_options,
+ "ignore-space-change");
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
@@ sequencer.c: static int run_git_commit(struct repository *r,
argv_array_push(&cmd.args, "commit");
@@ sequencer.c: static int try_to_commit(struct repository *r,
- 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);
+ ident.date_begin,
+ (int)(ident.tz_end - ident.tz_begin),
+ ident.tz_begin);
- res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+ res = setenv("GIT_COMMITTER_DATE",
+ opts->ignore_date ? "" : date.buf, 1);
@@ sequencer.h: struct replay_opts {
## t/t3436-rebase-more-options.sh ##
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-date works when committing confl
- test_cmp expect actual
+ test_ctime_is_atime -1
'
-+# Checking for +0000 in author time is enough since default
-+# timezone is UTC, but the timezone used while committing
-+# sets to +0530.
++# Checking for +0000 in the author date is sufficient since the
++# default timezone is UTC but the timezone used while committing is
++# +0530. The inverted logic in the grep is necessary to check all the
++# author dates in the file.
++test_ctime_is_ignored () {
++ git log $1 --format=%ai >authortime &&
++ ! grep -v +0000 authortime
++}
++
+test_expect_success '--ignore-date works with apply backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
+ git rebase --apply --ignore-date HEAD^ &&
-+ git log -1 --pretty=%ai >authortime &&
-+ grep "+0000" authortime
++ test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works with merge backend' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
+ git rebase --ignore-date -m HEAD^ &&
-+ git log -1 --pretty=%ai >authortime &&
-+ grep "+0000" authortime
++ test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works after conflict resolution' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
+ echo resolved >foo &&
+ git add foo &&
+ git rebase --continue &&
-+ git log -1 --pretty=%ai >authortime &&
-+ grep +0000 authortime
++ test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works with rebase -r' '
+ git checkout side &&
+ git merge --no-ff commit3 &&
+ git rebase -r --root --ignore-date &&
-+ git log --pretty=%ai >authortime &&
-+ ! grep -v "+0000" authortime
++ test_ctime_is_ignored
+'
+
+test_expect_success '--ignore-date with --committer-date-is-author-date works' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
+ git checkout --theirs foo &&
+ git add foo &&
+ git rebase --continue &&
-+ git log -2 --pretty=%ai >authortime &&
-+ git log -2 --pretty=%ci >committertime &&
-+ test_cmp authortime committertime &&
-+ ! grep -v "+0000" authortime
++ test_ctime_is_atime -2 &&
++ test_ctime_is_ignored -2
+'
+
+test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+ GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
-+ git rebase -i --strategy=resolve --ignore-date \
-+ --committer-date-is-author-date side side &&
-+ git log -1 --pretty=%ai >authortime &&
-+ git log -1 --pretty=%ci >committertime &&
-+ test_cmp authortime committertime &&
-+ grep "+0000" authortime
++ PATH="./test-bin:$PATH" git rebase -i --strategy=test \
++ --ignore-date --committer-date-is-author-date \
++ side side &&
++ test_ctime_is_atime -1 &&
++ test_ctime_is_ignored -1
+ '
+
# This must be the last test in this file
5: a11db78eb4 ! 5: 26d5eefdcb rebase: add --reset-author-date
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
+ N_("synonym of --reset-author-date")),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
N_("passed to 'git apply'"), 0),
- OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
+ OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
## t/t3436-rebase-more-options.sh ##
-@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-date works when committing confl
- # Checking for +0000 in author time is enough since default
- # timezone is UTC, but the timezone used while committing
- # sets to +0530.
+@@ t/t3436-rebase-more-options.sh: test_ctime_is_ignored () {
+ ! grep -v +0000 authortime
+ }
+
-test_expect_success '--ignore-date works with apply backend' '
+test_expect_success '--reset-author-date works with apply backend' '
git commit --amend --date="$GIT_AUTHOR_DATE" &&
- git rebase --apply --ignore-date HEAD^ &&
+ git rebase --apply --reset-author-date HEAD^ &&
- git log -1 --pretty=%ai >authortime &&
- grep "+0000" authortime
+ test_ctime_is_ignored -1
'
-test_expect_success '--ignore-date works with merge backend' '
+test_expect_success '--reset-author-date works with merge backend' '
git commit --amend --date="$GIT_AUTHOR_DATE" &&
- git rebase --ignore-date -m HEAD^ &&
+ git rebase --reset-author-date -m HEAD^ &&
- git log -1 --pretty=%ai >authortime &&
- grep "+0000" authortime
+ test_ctime_is_ignored -1
'
-test_expect_success '--ignore-date works after conflict resolution' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
--onto commit2^^ commit2^ commit2 &&
echo resolved >foo &&
git add foo &&
-@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-date works after conflict resolution' '
- grep +0000 authortime
+ git rebase --continue &&
+ test_ctime_is_ignored -1
'
-test_expect_success '--ignore-date works with rebase -r' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-date works after c
git merge --no-ff commit3 &&
- git rebase -r --root --ignore-date &&
+ git rebase -r --root --reset-author-date &&
- git log --pretty=%ai >authortime &&
- ! grep -v "+0000" authortime
+ test_ctime_is_ignored
'
-test_expect_success '--ignore-date with --committer-date-is-author-date works' '
@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-date works after c
git checkout --theirs foo &&
git add foo &&
git rebase --continue &&
-@@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-date with --committer-date-is-author-date works' '
- ! grep -v "+0000" authortime
+ test_ctime_is_atime -2 &&
+ test_ctime_is_ignored -2
'
-test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
-- git rebase -i --strategy=resolve --ignore-date \
-+ git rebase -i --strategy=resolve --reset-author-date \
- --committer-date-is-author-date side side &&
- git log -1 --pretty=%ai >authortime &&
- git log -1 --pretty=%ci >committertime &&
- test_cmp authortime committertime &&
- grep "+0000" authortime
+ PATH="./test-bin:$PATH" git rebase -i --strategy=test \
+- --ignore-date --committer-date-is-author-date \
+- side side &&
++ --reset-author-date \
++ --committer-date-is-author-date side side &&
+ test_ctime_is_atime -1 &&
+ test_ctime_is_ignored -1
'
+test_expect_success '--ignore-date is an alias for --reset-author-date' '
+ git commit --amend --date="$GIT_AUTHOR_DATE" &&
+ git rebase --apply --ignore-date HEAD^ &&
+ git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
+ git rebase -m --ignore-date HEAD^ &&
-+ git log -2 --pretty="format:%ai" >authortime &&
-+ grep "+0000" authortime >output &&
-+ test_line_count = 2 output
++ test_ctime_is_ignored -2
+'
+
# This must be the last test in this fileSignature · 1 line
2.27.0
PATCH v5 1/5 rebase -i: add --ignore-whitespace flag
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 19 +++++++- builtin/rebase.c | 16 +++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 60 ++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +
@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +13 -3
@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts)parse_strategy_opts (&replay, opts->strategy_opts);
@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;
@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,
@@ -1850,6 +1851,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); } +if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +if (strategy_options.nr) {int i;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
t/t3436-rebase-more-options.sh new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
Quoted 109 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
Signed-off-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 19 +++++++- builtin/rebase.c | 16 +++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 60 ++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100755 t/t3436-rebase-more-options.shDocumentation/git-rebase.txt +17
-2@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +4
-3@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts)parse_strategy_opts (&replay, opts->strategy_opts);@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,@@ -1850,6 +1851,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); }
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1862
Quoted 10 lines
builtin/rebase.c +9
-0+if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +
Hm, I've just noticed this by now.
Would it's better if we rewrite it as:
if (ignore_whitespace) {
if (options.type == REBASE_APPLY)
argv_array_push(&options.git_am_opts,
"--ignore-whitespace");
else
string_list_append(&strategy_options,
"ignore-space-change");
}Ah, the incoming patches will add more conditions into the:
if (options.type == REBASE_APPLY)
I'm still not convinced, though.
Anyway, IIRC, --ignore-whitespace and --ignore-space-change has the same meaning, I think it's better to use the same option for both legs, no?
I can understand the decision to use --ignore-whitespace as keeping the pass-through behavior of old code, but I think future maintenance is more important than that.
I've tried changing ignore-whitespace to ignore-space-change and run make test
It looks good to me (aka nothing failed _in my machine_), 4/5 and 5/5 is not applied, though.
Quoted 84 lines
builtin/rebase.c +0
-0if (strategy_options.nr) {int i;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + test_write_lines "line 1" " line 2" "line 3" >file && + git add file && + git commit -m "add file" && + + test_write_lines "line 1" "new line 2" "line 3" >file && + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + test_write_lines "line 1" " line 2" "line 3" >file && + git commit -am "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace \ + main side && + git rebase --continue + ) && + git diff --exit-code side +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_doneSignature · 1 line
2.27.0
Signature · 1 line
Danh
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
Hi Danh
Quoted 133 lines · Đoàn Trần Công Danh
Quoted 109 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
Signed-off-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 19 +++++++- builtin/rebase.c | 16 +++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 60 ++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-)create mode 100755
t/t3436-rebase-more-options.shDocumentation/git-rebase.txt +17
-2@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +4
-3@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts)parse_strategy_opts (&replay, opts->strategy_opts);@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,@@ -1850,6 +1851,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); }builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1862
Quoted 10 lines
builtin/rebase.c +9
-0+if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +Hm, I've just noticed this by now.
Would it's better if we rewrite it as:if (ignore_whitespace) { if (options.type == REBASE_APPLY) argv_array_push(&options.git_am_opts, "--ignore-whitespace"); else string_list_append(&strategy_options, "ignore-space-change"); }
Quoted 5 lines
Ah, the incoming patches will add more conditions into the:
if (options.type == REBASE_APPLY)I'm still not convinced, though.
I wanted to keep the subsequent patches as simple as possible. Having to rewrite the if statement in the next patch just clutters it up and makes the real changes introduced by that patch less obvious
Quoted 7 lines
Anyway, IIRC, --ignore-whitespace and --ignore-space-change has the same meaning, I think it's better to use the same option for both legs, no?
I can understand the decision to use --ignore-whitespace as keeping the pass-through behavior of old code, but I think future maintenance is more important than that.
I'm not sure how it affects future maintenance. The two different options are for two different commands so I'm not sure it is worth the effort
Best Wishes
Phillip
Quoted 91 lines
I've tried changing ignore-whitespace to ignore-space-change and run make test
It looks good to me (aka nothing failed
_inmymachine_), 4/5 and 5/5 is not applied, though.Quoted 84 lines
builtin/rebase.c +0
-0if (strategy_options.nr) {int i;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + test_write_lines "line 1" " line 2" "line 3" >file && + git add file && + git commit -m "add file" && + + test_write_lines "line 1" "new line 2" "line 3" >file && + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + test_write_lines "line 1" " line 2" "line 3" >file && + git commit -am "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace \ + main side && + git rebase --continue + ) && + git diff --exit-code side +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_doneSignature · 1 line
2.27.0
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
Quoted 10 lines · Phillip Wood
Quoted 10 lines
Quoted 9 lines
+ if (options.type == REBASE_APPLY) {builtin/rebase.c +8
-0+if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +...
Quoted 3 lines
I wanted to keep the subsequent patches as simple as possible. Having to rewrite the if statement in the next patch just clutters it up and makes the real changes introduced by that patch less obvious
A set of different behaviour depending on .type is OK, but then at least the above should be more like this:
if (options.type == REBASE_APPLY) {
if (ignore_whitespace)
argv_array_push(...);
} else {
/* REBASE_MERGE and PRESERVE_MERGES */
if (ignore_whitespace)
string_list_append(...);
}or even
switch (options.type) {
case REBASE_APPLY:
...
break;
case REBASE_MERGE:
case REBASE_PRESERVE_MERGES:
...
break;
default:
BUG("unhandled rebase type %d", options.type);
}That would clarify the flow of the logic better.
Thanks.
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
In reply to Phillip WoodHi Phillip,
Quoted 24 lines · Phillip Wood
Quoted 24 lines
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1862
Quoted 9 lines
builtin/rebase.c +9
-0+if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +Hm, I've just noticed this by now.
Would it's better if we rewrite it as:if (ignore_whitespace) { if (options.type == REBASE_APPLY) argv_array_push(&options.git_am_opts, "--ignore-whitespace"); else string_list_append(&strategy_options, "ignore-space-change"); }Ah, the incoming patches will add more conditions into the:
Quoted 7 lines
Quoted 3 lines
if (options.type == REBASE_APPLY)I'm still not convinced, though.
I wanted to keep the subsequent patches as simple as possible. Having to rewrite the if statement in the next patch just clutters it up and makes the real changes introduced by that patch less obvious
I think the code suggested by Junio may be cleaner ;) I may write as:
if (ignore_whitespace) {
if (options.type == REBASE_APPLY)
argv_array_push(...)
else
string_list_append(...)
}
if (other_condition)
do_something_else(...)I don't know if it's cleaner or not.
I haven't tried applied it into real code.
Quoted 10 lines
Quoted 7 lines
Anyway, IIRC, --ignore-whitespace and --ignore-space-change has the same meaning, I think it's better to use the same option for both legs, no?
I can understand the decision to use --ignore-whitespace as keeping the pass-through behavior of old code, but I think future maintenance is more important than that.
I'm not sure how it affects future maintenance. The two different options are for two different commands so I'm not sure it is worth the effort
I vaguely remember I was thinking about same option text in both leg would make the code easier for reasoning. And we can unify the recommendation for both backend. We will never strip --ignore-whitespace from git-apply, but it would be easier to always
answer: "--ignore-space-change should be used to ignore space" when someone asks about it.
Typing this now makes me wonder if we should teach --ignore-space-change to git-rebase?
Thanks,
-- Danh
Quoted 93 lines
Best Wishes
Phillip
Quoted 88 lines
I've tried changing ignore-whitespace to ignore-space-change and run make test
It looks good to me (aka nothing failed
_inmymachine_), 4/5 and 5/5 is not applied, though.Quoted 81 lines
if (strategy_options.nr) { int i;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + test_write_lines "line 1" " line 2" "line 3" >file && + git add file && + git commit -m "add file" && + + test_write_lines "line 1" "new line 2" "line 3" >file && + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + test_write_lines "line 1" " line 2" "line 3" >file && + git commit -am "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace \ + main side && + git rebase --continue + ) && + git diff --exit-code side +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_doneSignature · 1 line
2.27.0
Signature · 1 line
Danh
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
Hi Danh
Quoted 29 lines · Đoàn Trần Công Danh
Hi Phillip,
Quoted 26 lines · Phillip Wood
Quoted 26 lines
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1862
Quoted 9 lines
builtin/rebase.c +9
-0+if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } +Hm, I've just noticed this by now.
Would it's better if we rewrite it as:if (ignore_whitespace) { if (options.type == REBASE_APPLY) argv_array_push(&options.git_am_opts, "--ignore-whitespace"); else string_list_append(&strategy_options, "ignore-space-change"); }Ah, the incoming patches will add more conditions into the:
if (options.type == REBASE_APPLY)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I'm still not convinced, though.
I wanted to keep the subsequent patches as simple as possible. Having to rewrite the if statement in the next patch just clutters it up and makes the real changes introduced by that patch less obvious
I think the code suggested by Junio may be cleaner ;)
Yes, I'll reroll with Junio's suggestion
Quoted 12 lines
I may write as:
if (ignore_whitespace) { if (options.type == REBASE_APPLY) argv_array_push(...) else string_list_append(...) } if (other_condition) do_something_else(...)
Quoted 1 line
I don't know if it's cleaner or not.
It leads to a lot of repetition of ' && options.type == REBASE_APPLY' as all the other conditions apart from --ignore-whitespace only need handling for the apply backend here.
Quoted 20 lines
I haven't tried applied it into real code.
Quoted 10 lines
Quoted 7 lines
Anyway, IIRC, --ignore-whitespace and --ignore-space-change has the same meaning, I think it's better to use the same option for both legs, no?
I can understand the decision to use --ignore-whitespace as keeping the pass-through behavior of old code, but I think future maintenance is more important than that.
I'm not sure how it affects future maintenance. The two different options are for two different commands so I'm not sure it is worth the effort
I vaguely remember I was thinking about same option text in both leg would make the code easier for reasoning. And we can unify the recommendation for both backend. We will never strip --ignore-whitespace from git-apply, but it would be easier to always
answer: "--ignore-space-change should be used to ignore space" when someone asks about it.
Quoted 2 lines
Typing this now makes me wonder if we should teach --ignore-space-change to git-rebase?
Possibly but not as part of this series which is about improving the merge backend rather than adding new options to rebase itself
Best Wishes
Phillip
Quoted 99 lines
Thanks,
-- Danh
Quoted 93 lines
Best Wishes
Phillip
Quoted 88 lines
I've tried changing ignore-whitespace to ignore-space-change and run make test
It looks good to me (aka nothing failed
_inmymachine_), 4/5 and 5/5 is not applied, though.Quoted 81 lines
if (strategy_options.nr) { int i;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4t/t3436-rebase-more-options.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh +# +# Copyright (c) 2019 Rohit Ashiwal +# + +test_description='tests to ensure compatibility between am and interactive backends' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +# This is a special case in which both am and interactive backends +# provide the same output. It was done intentionally because +# both the backends fall short of optimal behaviour. +test_expect_success 'setup' ' + git checkout -b topic && + test_write_lines "line 1" " line 2" "line 3" >file && + git add file && + git commit -m "add file" && + + test_write_lines "line 1" "new line 2" "line 3" >file && + git commit -am "update file" && + git tag side && + + git checkout --orphan master && + test_write_lines "line 1" " line 2" "line 3" >file && + git commit -am "add file" && + git tag main +' + +test_expect_success '--ignore-whitespace works with apply backend' ' + test_must_fail git rebase --apply main side && + git rebase --abort && + git rebase --apply --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace works with merge backend' ' + test_must_fail git rebase --merge main side && + git rebase --abort && + git rebase --merge --ignore-whitespace main side && + git diff --exit-code side +' + +test_expect_success '--ignore-whitespace is remembered when continuing' ' + ( + set_fake_editor && + FAKE_LINES="break 1" git rebase -i --ignore-whitespace \ + main side && + git rebase --continue + ) && + git diff --exit-code side +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_doneSignature · 1 line
2.27.0
Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
In reply to Phillip WoodQuoted 3 lines · Phillip Wood
... This option treats
lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
OK. Hiding the subtle difference is good.
Documentation/git-rebase.txt In addition, the following pairs of options are incompatible: · line 617
Quoted 7 lines
Documentation/git-rebase.txt +1
-0@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
Hmph...
builtin/rebase.c static struct replay_opts get_replay_opts(const struct rebase_options *opts) · line 131
Quoted 11 lines
builtin/rebase.c +1
-0@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts)parse_strategy_opts (&replay, opts->strategy_opts);
Usually I would complain about whitespace-only changes to places where there is no real change, but I am OK with this one. It does make sense to have a blank here.
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1861
Quoted 12 lines
builtin/rebase.c +8
-0@@ -1850,6 +1851,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); } +if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + }
I agree with the other reviewer that "when --ignore-whitespace is given, do these different things depending on the .type" is easier to follow. Also pay attention to the style. There is no SP between the name of the function and the opening '(' for its parameter list.
if (ignore_whitespace) {
if (options.type == REBASE_APPLY)
argv_array_push(&options.git_am_opts, "--ignore-whitespace");
else
string_list_append(&strategy_options, "ignore-space-change");
}t/t3422-rebase-incompatible-options.sh test_rebase_am_only () { · line 65
Quoted 11 lines
t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
OK.
Thanks.
PATCH v5 2/5 rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --committer-date-is-author-date option to the merge backend. This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.
--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 17 +++++--- sequencer.c | 60 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 58 ++++++++++++++++++++++++- 6 files changed, 136 insertions(+), 11 deletions(-)
Documentation/git-rebase.txt +7 -3
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +12 -5
@@ -88,6 +88,7 @@ struct rebase_options {int autosquash;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -124,6 +125,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1497,9 +1500,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1794,11 +1797,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;
@@ -1855,6 +1859,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (ignore_whitespace)argv_array_push (&options.git_am_opts,"--ignore-whitespace" ); +if (options.committer_date_is_author_date) +argv_array_push (&options.git_am_opts, +"--committer-date-is-author-date" ); }else if (ignore_whitespace) {string_list_append (&strategy_options,"ignore-space-change" );
sequencer.c +59 -1
108 lines not on this page · raw message
sequencer.h +1 -0
@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +57 -1
80 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v5 3/5 sequencer: rename amend_author to author_to_free
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.
--- sequencer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,struct commit_extra_header *extra =NULL ;struct strbuf err =STRBUF_INIT ;struct strbuf commit_msg =STRBUF_INIT ; -char *amend_author =NULL ; +char *author_to_free =NULL ;const char *hook_commit =NULL ;enum commit_msg_cleanup_mode cleanup;int res =0 ;
@@ -1357,7 +1357,7 @@ static int try_to_commit(struct repository *r,strbuf_addstr (msg, orig_message); hook_commit ="HEAD" ; } - author = amend_author =get_author (message); + author = author_to_free =get_author (message);unuse_commit_buffer (current_head, message);if (!author) { res =error (_ ("unable to parse commit author" ));
@@ -1474,7 +1474,7 @@ static int try_to_commit(struct repository *r,free_commit_extra_headers (extra);strbuf_release (&err);strbuf_release (&commit_msg); -free (amend_author); +free (author_to_free);return res; }
Signature · 1 line
2.27.0
PATCH v5 4/5 rebase -i: support --ignore-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 50 ++++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +8 -5
@@ -89,6 +89,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, +"ignore author date and use current date" ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {
@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (options.committer_date_is_author_date)argv_array_push (&options.git_am_opts,"--committer-date-is-author-date" ); +if (options.ignore_date) +argv_array_push (&options.git_am_opts,"--ignore-date" ); }else if (ignore_whitespace) {string_list_append (&strategy_options,"ignore-space-change" );
sequencer.c +48 -2
106 lines not on this page · raw message
sequencer.h +1 -0
@@ -46,6 +46,7 @@ struct replay_opts {int quiet;int reschedule_failed_exec;int committer_date_is_author_date; +int ignore_date;int mainline;
t/t3436-rebase-more-options.sh +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v5 4/5] rebase -i: support --ignore-date
Quoted 77 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 50 ++++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)Documentation/git-rebase.txt +4
-3@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +2
-0@@ -89,6 +89,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1509
Quoted 7 lines
builtin/rebase.c +2
-2@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , - N_("passed to 'git am'"), PARSE_OPT_NOARG), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, + "ignore author date and use current date"),
Nit: The options' description is subjected to l10n.
s/".*"/N_(&)/
Quoted 48 lines
builtin/rebase.c +4
-3OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (options.committer_date_is_author_date)argv_array_push (&options.git_am_opts,"--committer-date-is-author-date" ); +if (options.ignore_date) +argv_array_push (&options.git_am_opts,"--ignore-date" ); }else if (ignore_whitespace) {string_list_append (&strategy_options,"ignore-space-change" );sequencer.c +5
-0@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")*/ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -889,6 +890,24 @@ static const char *author_date_from_env_array(const struct argv_array *env)BUG ("GIT_AUTHOR_DATE missing from author script" ); } +/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author);
sequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 906
Quoted 10 lines
sequencer.c +10
-0+struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line '%s'" ), author); +return NULL ; + } + + len = ident.mail_end - ident.name_begin +1 ; +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin);
I wonder if we can do this instead:
strbuf_add(&new_author, ident.name_begin, len);
Quick skim through the code and nothing crashes when make test with:
CFLAGS="-fstack-clash-protection -D_FORTIFY_SOURCE=2"
I think it's OK to be changed.
Quoted 4 lines
sequencer.c +4
-0+datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} +
Signature · 1 line
Danh
Re: [PATCH v5 4/5] rebase -i: support --ignore-date
Hi Danh
Quoted 88 lines · Đoàn Trần Công Danh
Quoted 77 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.
Original-patch-by Rohit Ashiwal <[email protected]>Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-rebase.txt | 7 +++-- builtin/rebase.c | 13 +++++--- sequencer.c | 50 ++++++++++++++++++++++++++++-- sequencer.h | 1 + t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-)Documentation/git-rebase.txt +4
-3@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: - This flag is passed to 'git am' to change the author date - of each rebased commit (see linkgit:git-am[1]). + Instead of using the author date of the original commit, use + the current time as the author date of the rebased commit. This + option implies `--force-rebase`. + See also INCOMPATIBLE OPTIONS below.@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --ignore-date * --whitespace * -C@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace * --preserve-merges and --committer-date-is-author-date + * --preserve-merges and --ignore-date * --keep-base and --onto * --keep-base and --rootbuiltin/rebase.c +2
-0@@ -89,6 +89,7 @@ struct rebase_options {char *gpg_sign_opt;int autostash;int committer_date_is_author_date; +int ignore_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1509
Quoted 7 lines
builtin/rebase.c +2
-2@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL , - N_("passed to 'git am'"), PARSE_OPT_NOARG), +OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, + "ignore author date and use current date"),Nit: The options' description is subjected to l10n.
Quoted 1 line
s/".*"/N_(&)/
Well spotted, thanks
Quoted 61 lines
Quoted 48 lines
builtin/rebase.c +4
-3OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } -if (options.committer_date_is_author_date) +if (options.committer_date_is_author_date || options.ignore_date) options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--ignore-date" ) || - !strcmp (option,"--whitespace=fix" ) || +if (!strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;else if (skip_prefix (option,"-C" , &p)) {@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (options.committer_date_is_author_date)argv_array_push (&options.git_am_opts,"--committer-date-is-author-date" ); +if (options.ignore_date) +argv_array_push (&options.git_am_opts,"--ignore-date" ); }else if (ignore_whitespace) {string_list_append (&strategy_options,"ignore-space-change" );sequencer.c +5
-0@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")*/ static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") staticGIT_PATH_FUNC (rebase_path_cdate_is_adate,"rebase-merge/cdate_is_adate" ) +static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date") staticGIT_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")@@ -889,6 +890,24 @@ static const char *author_date_from_env_array(const struct argv_array *env)BUG ("GIT_AUTHOR_DATE missing from author script" ); } +/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author);sequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 906
Quoted 10 lines
sequencer.c +10
-0+struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) { +error (_ ("malformed ident line '%s'" ), author); +return NULL ; + } + + len = ident.mail_end - ident.name_begin +1 ; +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin);I wonder if we can do this instead:
Quoted 1 line
strbuf_add(&new_author, ident.name_begin, len);
There is a space at the end of the format string, which I think is needed to separate the name and email from the date we add with datestamp() below
Best Wishes
Phillip
Quoted 11 lines
Quick skim through the code and nothing crashes when make test with:
CFLAGS="-fstack-clash-protection -D_FORTIFY_SOURCE=2"
I think it's OK to be changed.
Quoted 4 lines
sequencer.c +4
-0+datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +} +
Re: [PATCH v5 4/5] rebase -i: support --ignore-date
In reply to Phillip Woodsequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 896
Quoted 4 lines · Phillip Wood
sequencer.c +4
-0+/* Construct a free()able author string with current time as the author date */ +static char *ignore_author_date (const char *author) +{ +int len =strlen (author);
I'd rather not to see this initialization, because ...
sequencer.c static const char *author_date_from_env_array(const struct argv_array *env) · line 900
Quoted 4 lines
sequencer.c +4
-0+struct ident_split ident; +struct strbuf new_author =STRBUF_INIT ; + +if (split_ident_line (&ident, author, len) <0 ) {
... it is away from this line. This line is better written
if (split_ident_line(&ident, author, strlen(author)) < 0) {to show what the third parameter is about. It is not just "len", but is the length of the second parameter, author.
Quoted 9 lines
sequencer.c +9
-0+error (_ ("malformed ident line '%s'" ), author); +return NULL ; + } + + len = ident.mail_end - ident.name_begin +1 ; +strbuf_addf (&new_author,"%.*s " , len, ident.name_begin); +datestamp (&new_author); +return strbuf_detach (&new_author,NULL ); +}
PATCH v5 5/5 rebase: add --reset-author-date
In reply to Phillip WoodFrom: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
--- Documentation/git-rebase.txt | 1 + builtin/rebase.c | 6 ++++-- t/t3436-rebase-more-options.sh | 34 +++++++++++++++++++++------------- 3 files changed, 26 insertions(+), 15 deletions(-)
Documentation/git-rebase.txt +1 -0
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below. date. This option implies --force-rebase. --ignore-date:: +--reset-author-date:: Instead of using the author date of the original commit, use the current time as the author date of the rebased commit. This option implies `--force-rebase`.
builtin/rebase.c +4 -2
@@ -1505,8 +1505,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"committer-date-is-author-date" , &options.committer_date_is_author_date,N_ ("make committer date match author date" )), -OPT_BOOL (0 ,"ignore-date" , &options.ignore_date, -"ignore author date and use current date" ), +OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, +N_ ("synonym of --reset-author-date" )),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
t/t3436-rebase-more-options.sh +21 -13
@@ -117,53 +117,61 @@ test_ctime_is_ignored () { ! grep -v +0000 authortime } -test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && test_ctime_is_ignored -1 ' -test_expect_success '--ignore-date works with merge backend' ' +test_expect_success '--reset-author-date works with merge backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --ignore-date -m HEAD^ && + git rebase --reset-author-date -m HEAD^ && test_ctime_is_ignored -1 ' -test_expect_success '--ignore-date works after conflict resolution' ' - test_must_fail git rebase --ignore-date -m \ +test_expect_success '--reset-author-date works after conflict resolution' ' + test_must_fail git rebase --reset-author-date -m \ --onto commit2^^ commit2^ commit2 && echo resolved >foo && git add foo && git rebase --continue && test_ctime_is_ignored -1 ' -test_expect_success '--ignore-date works with rebase -r' ' +test_expect_success '--reset-author-date works with rebase -r' ' git checkout side && git merge --no-ff commit3 && - git rebase -r --root --ignore-date && + git rebase -r --root --reset-author-date && test_ctime_is_ignored ' -test_expect_success '--ignore-date with --committer-date-is-author-date works' ' +test_expect_success '--reset-author-date with --committer-date-is-author-date works' ' test_must_fail git rebase -m --committer-date-is-author-date \ - --ignore-date --onto commit2^^ commit2^ commit3 && + --reset-author-date --onto commit2^^ commit2^ commit3 && git checkout --theirs foo && git add foo && git rebase --continue && test_ctime_is_atime -2 && test_ctime_is_ignored -2 ' -test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' ' +test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' ' GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \ PATH="./test-bin:$PATH" git rebase -i --strategy=test \ - --ignore-date --committer-date-is-author-date \ - side side && + --reset-author-date \ + --committer-date-is-author-date side side && test_ctime_is_atime -1 && test_ctime_is_ignored -1 ' +test_expect_success '--ignore-date is an alias for --reset-author-date' ' + git commit --amend --date="$GIT_AUTHOR_DATE" && + git rebase --apply --ignore-date HEAD^ && + git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" && + git rebase -m --ignore-date HEAD^ && + test_ctime_is_ignored -2 +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged
Signature · 1 line
2.27.0
Re: [PATCH v5 5/5] rebase: add --reset-author-date
Quoted 7 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
Helped-by Junio C Hamano <[email protected]>
Hmph, did I?
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1511
Quoted 4 lines
builtin/rebase.c +4
-0+OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, + N_("synonym of --reset-author-date")),
It is merely hidden but still supported.
Quoted 5 lines
t/t3436-rebase-more-options.sh +0
-0
t/t3436-rebase-more-options.sh test_ctime_is_ignored () { · line 124
Quoted 10 lines
t/t3436-rebase-more-options.sh +2
-2@@ -117,53 +117,61 @@ test_ctime_is_ignored () { ! grep -v +0000 authortime } -test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && test_ctime_is_ignored -1 '
Are there still some tests that check "--ignore-date"? We probably should have them, if we are not removing the support.
Thanks. The entire series looked reasonable to me.
Re: [PATCH v5 5/5] rebase: add --reset-author-date
Hi Junio
Quoted 11 lines · Junio C Hamano
Quoted 7 lines · Phillip Wood
From: Rohit Ashiwal <[email protected]>
The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.
Helped-by Junio C Hamano <[email protected]>Hmph, did I?
Yes, you added a fixup d82dfa7f5b ("rebase -i: finishing touches to --reset-author-date", 2019-11-21) which I squashed into this patch
Quoted 16 lines
builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1511
Quoted 5 lines
builtin/rebase.c +4
-0+OPT_BOOL (0 ,"reset-author-date" , &options.ignore_date, +N_ ("ignore author date and use current date" )), +OPT_HIDDEN_BOOL (0 ,"ignore-date" , &options.ignore_date, + N_("synonym of --reset-author-date")),It is merely hidden but still supported.
Quoted 8 lines
t/t3436-rebase-more-options.sh +0
-0@@ -117,53 +117,61 @@ test_ctime_is_ignored () { ! grep -v +0000 authortime }
Quoted 10 lines
t/t3436-rebase-more-options.sh test_ctime_is_ignored () { · line 124
Quoted 7 lines
t/t3436-rebase-more-options.sh +2
-2-test_expect_success '--ignore-date works with apply backend' ' +test_expect_success '--reset-author-date works with apply backend' ' git commit --amend --date="$GIT_AUTHOR_DATE" && - git rebase --apply --ignore-date HEAD^ && + git rebase --apply --reset-author-date HEAD^ && test_ctime_is_ignored -1 'Are there still some tests that check "--ignore-date"? We probably should have them, if we are not removing the support.
This patch converts the existing --ignore-date tests to use --reset-author-date and adds a single new test at the end to check --ignore-date
Best Wishes
Phillip
Quoted 3 lines
Thanks. The entire series looked reasonable to me.
Re: [PATCH v5 0/5] cleanup ra/rebase-i-more-options
In reply to Phillip WoodQuoted 7 lines · Phillip Wood
From: Phillip Wood <[email protected]>
I've updated the commit messages, option handling and tests as suggested by dscho. I've also changed the tests that used '--strategy=resolve' to use a real external merge strategy so they continue to test the same code path once Alban's patches to handle the resolve strategy without forking are merged
Thanks, will take a look and replace.
v6 cover fixup ra/rebase-i-more-options
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Thanks for the comments on the last round, I've modified the controversial conditional in the first patch as suggested by Junio and updated patch 4 as suggested as well
Best Wishes
Phillip
Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date
Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date
Documentation/git-rebase.txt | 33 ++++- builtin/rebase.c | 47 +++++-- sequencer.c | 112 ++++++++++++++- sequencer.h | 2 + t/t3422-rebase-incompatible-options.sh | 2 - t/t3436-rebase-more-options.sh | 180 +++++++++++++++++++++++++ 6 files changed, 353 insertions(+), 23 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Range-diff against v5:
1: 43ee10d4d5 ! 1: 5bb4226007 rebase -i: add --ignore-whitespace flag
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
+ if (options.type == REBASE_APPLY) {
+ if (ignore_whitespace)
-+ argv_array_push (&options.git_am_opts,
-+ "--ignore-whitespace");
-+ } else if (ignore_whitespace) {
-+ string_list_append (&strategy_options,
-+ "ignore-space-change");
++ argv_array_push(&options.git_am_opts,
++ "--ignore-whitespace");
++ } else {
++ /* REBASE_MERGE and PRESERVE_MERGES */
++ if (ignore_whitespace) {
++ string_list_append(&strategy_options,
++ "ignore-space-change");
++ }
+ }
+
if (strategy_options.nr) {2: a2b57df19c ! 2: e5fdb574ed rebase -i: support --committer-date-is-author-date
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
allow_preemptive_ff = 0;
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix)
if (ignore_whitespace)
- argv_array_push (&options.git_am_opts,
- "--ignore-whitespace");
+ argv_array_push(&options.git_am_opts,
+ "--ignore-whitespace");
+ if (options.committer_date_is_author_date)
+ argv_array_push(&options.git_am_opts,
+ "--committer-date-is-author-date");
- } else if (ignore_whitespace) {
- string_list_append (&strategy_options,
- "ignore-space-change");
+ } else {
+ /* REBASE_MERGE and PRESERVE_MERGES */
+ if (ignore_whitespace) {
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
3: 363a0140ad = 3: cf5c9a2456 sequencer: rename amend_author to author_to_free
4: 46d9e108be ! 4: 0fc90eaff1 rebase -i: support --ignore-date
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
- OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
- N_("passed to 'git am'"), PARSE_OPT_NOARG),
+ OPT_BOOL(0, "ignore-date", &options.ignore_date,
-+ "ignore author date and use current date"),
++ N_("ignore author date and use current date")),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
N_("passed to 'git apply'"), 0),
OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
"--committer-date-is-author-date");
+ if (options.ignore_date)
+ argv_array_push(&options.git_am_opts, "--ignore-date");
- } else if (ignore_whitespace) {
- string_list_append (&strategy_options,
- "ignore-space-change");
+ } else {
+ /* REBASE_MERGE and PRESERVE_MERGES */
+ if (ignore_whitespace) {
## sequencer.c ##
@@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
@@ sequencer.c: static const char *author_date_from_env_array(const struct argv_arr
+/* Construct a free()able author string with current time as the author date */
+static char *ignore_author_date(const char *author)
+{
-+ int len = strlen(author);
++ int len;
+ struct ident_split ident;
+ struct strbuf new_author = STRBUF_INIT;
+
-+ if (split_ident_line(&ident, author, len) < 0) {
++ if (split_ident_line(&ident, author, strlen(author)) < 0) {
+ error(_("malformed ident line '%s'"), author);
+ return NULL;
+ }5: 26d5eefdcb ! 5: 21cf5e5512 rebase: add --reset-author-date
@@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix
&options.committer_date_is_author_date,
N_("make committer date match author date")),
- OPT_BOOL(0, "ignore-date", &options.ignore_date,
-- "ignore author date and use current date"),
+ OPT_BOOL(0, "reset-author-date", &options.ignore_date,
-+ N_("ignore author date and use current date")),
+ N_("ignore author date and use current date")),
+ OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
+ N_("synonym of --reset-author-date")),
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
Signature · 1 line
2.27.0
PATCH v6 1/5 rebase -i: add --ignore-whitespace flag
From: Rohit Ashiwal <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.
--- Documentation/git-rebase.txt | 19 +++++++- builtin/rebase.c | 19 ++++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 60 ++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 6 deletions(-) create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: + Ignore whitespace differences when trying to reconcile +differences. Currently, each backend implements an approximation of +this behavior: ++ +apply backend: When applying a patch, ignore changes in whitespace in +context lines. Unfortunately, this means that if the "old" lines being +replaced by the patch differ only in whitespace from the existing +file, you will get a merge conflict instead of a successful patch +application. ++ +merge backend: Treat lines with only whitespace changes as unchanged +when merging. Unfortunately, this means that any patch hunks that were +intended to modify whitespace and nothing else will be dropped, even +if the other side had no changes that conflicted. + --whitespace=<option>:: - These flags are passed to the 'git apply' program + This flag is passed to the 'git apply' program (see linkgit:git-apply[1]) that applies the patch. Implies --apply. +
@@ -572,7 +587,6 @@ The following options: * --apply * --committer-date-is-author-date * --ignore-date - * --ignore-whitespace * --whitespace * -C
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --signoff * --preserve-merges and --rebase-merges * --preserve-merges and --empty= + * --preserve-merges and --ignore-whitespace * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +16 -3
@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy; +if (opts->strategy_opts)parse_strategy_opts (&replay, opts->strategy_opts);
@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)struct strbuf revisions =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id merge_base; +int ignore_whitespace =0 ;enum action action =ACTION_NONE ;const char *gpg_sign =NULL ;struct string_list exec =STRING_LIST_INIT_NODUP ;
@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"ignore-whitespace" , &options.git_am_opts, -NULL ,N_ ("passed to 'git am'" ), -PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ),OPT_PASSTHRU_ARGV ('C' ,NULL , &options.git_am_opts,N_ ("n" ),N_ ("passed to 'git apply'" ),0 ), +OPT_BOOL (0 ,"ignore-whitespace" , &ignore_whitespace, +N_ ("ignore changes in whitespace" )),OPT_PASSTHRU_ARGV (0 ,"whitespace" , &options.git_am_opts,N_ ("action" ),N_ ("passed to 'git apply'" ),0 ), OPT_BIT('f', "force-rebase", &options.flags,
@@ -1850,6 +1851,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)imply_merge (&options,"--rebase-merges" ); } +if (options.type ==REBASE_APPLY ) { +if (ignore_whitespace) +argv_array_push (&options.git_am_opts, +"--ignore-whitespace" ); + }else { +/* REBASE_MERGE and PRESERVE_MERGES */ +if (ignore_whitespace) { +string_list_append (&strategy_options, +"ignore-space-change" ); + } + } +if (strategy_options.nr) {int i;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --ignore-whitespace test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
t/t3436-rebase-more-options.sh new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v6 2/5 rebase -i: support --committer-date-is-author-date
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --committer-date-is-author-date option to the merge backend. This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.
--- Documentation/git-rebase.txt | 10 +++-- builtin/rebase.c | 17 +++++--- sequencer.c | 60 +++++++++++++++++++++++++- sequencer.h | 1 + t/t3422-rebase-incompatible-options.sh | 1 - t/t3436-rebase-more-options.sh | 58 ++++++++++++++++++++++++- 6 files changed, 136 insertions(+), 11 deletions(-)
Documentation/git-rebase.txt +7 -3
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted. See also INCOMPATIBLE OPTIONS below. --committer-date-is-author-date:: + Instead of using the current time as the committer date, use + the author date of the commit being rebased as the committer + date. This option implies --force-rebase. + --ignore-date:: - These flags are passed to 'git am' to easily change the dates - of the rebased commits (see linkgit:git-am[1]). + This flag is passed to 'git am' to change the author date + of each rebased commit (see linkgit:git-am[1]). + See also INCOMPATIBLE OPTIONS below.
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS The following options: * --apply - * --committer-date-is-author-date * --ignore-date * --whitespace * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible: * --preserve-merges and --rebase-merges * --preserve-merges and --empty= * --preserve-merges and --ignore-whitespace + * --preserve-merges and --committer-date-is-author-date * --keep-base and --onto * --keep-base and --root
builtin/rebase.c +12 -5
@@ -88,6 +88,7 @@ struct rebase_options {int autosquash;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;
@@ -124,6 +125,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;
@@ -1497,9 +1500,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1794,11 +1797,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;
@@ -1855,6 +1859,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (ignore_whitespace)argv_array_push (&options.git_am_opts,"--ignore-whitespace" ); +if (options.committer_date_is_author_date) +argv_array_push (&options.git_am_opts, +"--committer-date-is-author-date" ); }else {/* REBASE_MERGE and PRESERVE_MERGES */ if (ignore_whitespace) {
sequencer.c +59 -1
108 lines not on this page · raw message
sequencer.h +1 -0
@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +57 -1
80 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date
Hi Phillip,
Quoted 107 lines · Phillip Wood
From: Phillip Wood <[email protected]>
builtin/rebase.c +12
-5@@ -88,6 +88,7 @@ struct rebase_options {int autosquash;char *gpg_sign_opt;int autostash; +int committer_date_is_author_date;char *cmd;int allow_empty_message;int rebase_merges, rebase_cousins;@@ -124,6 +125,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.quiet = !(opts->flags &REBASE_NO_QUIET ); replay.verbose = opts->flags &REBASE_VERBOSE ; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign =xstrdup_or_null (opts->gpg_sign_opt); replay.strategy = opts->strategy;@@ -1497,9 +1500,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },OPT_BOOL (0 ,"signoff" , &options.signoff,N_ ("add a Signed-off-by: line to each commit" )), -OPT_PASSTHRU_ARGV (0 ,"committer-date-is-author-date" , - &options.git_am_opts,NULL , -N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), +OPT_BOOL (0 ,"committer-date-is-author-date" , + &options.committer_date_is_author_date, +N_ ("make committer date match author date" )),OPT_PASSTHRU_ARGV (0 ,"ignore-date" , &options.git_am_opts,NULL ,N_ ("passed to 'git am'" ),PARSE_OPT_NOARG ), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),@@ -1794,11 +1797,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.autosquash) { allow_preemptive_ff =0 ; } +if (options.committer_date_is_author_date) + options.flags |=REBASE_FORCE ;for (i =0 ; i < options.git_am_opts.argc; i++) {const char *option = options.git_am_opts.argv[i], *p; -if (!strcmp (option,"--committer-date-is-author-date" ) || - !strcmp (option,"--ignore-date" ) || +if (!strcmp (option,"--ignore-date" ) || !strcmp (option,"--whitespace=fix" ) || !strcmp (option,"--whitespace=strip" )) allow_preemptive_ff =0 ;@@ -1855,6 +1859,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)if (ignore_whitespace)argv_array_push (&options.git_am_opts,"--ignore-whitespace" ); +if (options.committer_date_is_author_date) +argv_array_push (&options.git_am_opts, +"--committer-date-is-author-date" ); }else {/* REBASE_MERGE and PRESERVE_MERGES */ if (ignore_whitespace) {sequencer.c +21
-0@@ -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")@@ -872,6 +873,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 +955,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 ))
sequencer.c static int try_to_commit(struct repository *r, · line 1378
Quoted 9 lines
sequencer.c +6
-0@@ -1349,6 +1370,31 @@ static int try_to_commit(struct repository *r,commit_list_insert (current_head, &parents); } +if (opts->committer_date_is_author_date) { +struct ident_split ident; +struct strbuf date =STRBUF_INIT ; + +if (split_ident_line (&ident, author, (int )strlen (author)) <0 ) { + res =error (_ ("malformed ident line '%s'" ), author);
I've checked with the translation for my native language (vi). The translators seem to misread ident (as in identity) as indent (as in indentation).
The translation in po/vi.po:25045 (of v2.28.0-rc0) reads:
#~ msgid "malformed ident line"
#~ msgstr "thụt đầu dòng dị hình"
Translating back to English, it reads: "malformed indentation".
Hence, I think it would read better if we write:
res = error(_("malformed identity line '%s'"), author);3 more characters is not that much :)
Quoted 157 lines
sequencer.c +32
-1+ 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;@@ -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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +42
-1@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -21,11 +24,20 @@ test_expect_success 'setup' ' test_write_lines "line 1" "new line 2" "line 3" >file && git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + rm foo && test_write_lines "line 1" " line 2" "line 3" >file && git commit -am "add file" && - git tag main + git tag main && + + mkdir test-bin && + write_script test-bin/git-merge-test <<-\EOF + exec git-merge-recursive "$@" + EOF ' test_expect_success '--ignore-whitespace works with apply backend' '@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' git diff --exit-code side ' +test_ctime_is_atime () { + git log $1 --format=%ai >authortime && + git log $1 --format=%ci >committertime && + test_cmp authortime committertime +} + +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 105
Quoted 10 lines
t/t3436-rebase-more-options.sh +10
-0+ --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo &&
Nitpick: no space after ">" :D
Signature · 1 line
Danh
Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date
Hi Danh
Quoted 22 lines · Đoàn Trần Công Danh
Hi Phillip,
sequencer.c static int try_to_commit(struct repository *r, · line 1378
Quoted 8 lines · Phillip Wood
[...]
sequencer.c +6
-0+if (opts->committer_date_is_author_date) { +struct ident_split ident; +struct strbuf date =STRBUF_INIT ; + +if (split_ident_line (&ident, author, (int )strlen (author)) <0 ) { + res =error (_ ("malformed ident line '%s'" ), author);I've checked with the translation for my native language (vi). The translators seem to misread ident (as in identity) as indent (as in indentation).
The translation in po/vi.po:25045 (of v2.28.0-rc0) reads:
#~ msgid "malformed ident line"
#~ msgstr "thụt đầu dòng dị hình"
Quoted 7 lines
Translating back to English, it reads: "malformed indentation".
Hence, I think it would read better if we write:
res = error(_("malformed identity line '%s'"), author);3 more characters is not that much :)
Looking through the existing strings "invalid ident line: %.*s" is already used by am so maybe we should reuse that (log.c also contains "invalid ident line: %s"). Is the translation correct?
#: builtin/am.c:1270
#, c-format
msgid "invalid ident line: %.*s"
msgstr "dòng thụt lề không hợp lệ: %.*s"
Best Wishes
Phillip
Quoted 171 lines
Quoted 158 lines
sequencer.c +32
-1+ 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;@@ -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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +42
-1@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -21,11 +24,20 @@ test_expect_success 'setup' ' test_write_lines "line 1" "new line 2" "line 3" >file && git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + rm foo && test_write_lines "line 1" " line 2" "line 3" >file && git commit -am "add file" && - git tag main + git tag main && + + mkdir test-bin && + write_script test-bin/git-merge-test <<-\EOF + exec git-merge-recursive "$@" + EOF ' test_expect_success '--ignore-whitespace works with apply backend' '@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' git diff --exit-code side ' +test_ctime_is_atime () { + git log $1 --format=%ai >authortime && + git log $1 --format=%ci >committertime && + test_cmp authortime committertime +} + +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 105
Quoted 10 lines
t/t3436-rebase-more-options.sh +10
-0+ --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo &&Nitpick: no space after ">" :D
Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date
Hi Phillip,
Quoted 25 lines · Phillip Wood
Quoted 17 lines
sequencer.c static int try_to_commit(struct repository *r, · line 1378
Quoted 7 lines
[...]
sequencer.c +6
-0+if (opts->committer_date_is_author_date) { +struct ident_split ident; +struct strbuf date =STRBUF_INIT ; + +if (split_ident_line (&ident, author, (int )strlen (author)) <0 ) { + res =error (_ ("malformed ident line '%s'" ), author);I've checked with the translation for my native language (vi). The translators seem to misread ident (as in identity) as indent (as in indentation).
The translation in po/vi.po:25045 (of v2.28.0-rc0) reads:
#~ msgid "malformed ident line"
#~ msgstr "thụt đầu dòng dị hình"Quoted 7 lines
Translating back to English, it reads: "malformed indentation".
Hence, I think it would read better if we write:
res = error(_("malformed identity line '%s'"), author);3 more characters is not that much :)
Quoted 8 lines
Looking through the existing strings "invalid ident line: %.*s" is already used by am so maybe we should reuse that (
log.calso contains "invalid ident
line: %s"). Is the translation correct?#:
builtin/am.c:1270
#, c-format
msgid "invalid ident line: %.*s"
msgstr "dòng thụt lề không hợp lệ: %.*s"
That translation isn't correct either.
It seems like it's recurring pattern.
I'll take it to the Vietnamese translation team.
Anyway, I've checked with other translation that I can understand in part. I think
invalid ident line: %s
is better candidate for the message.
Since Spanish translation also mis-translates the message:
es.po:9836:msgid "invalid ident line: %.*s" es.po-9837-msgstr "sangría no válida: %.*s"
"sangría" also means "indentation" in this context.
Thanks,
-Danh
Quoted 162 lines
Best Wishes
Phillip
Quoted 157 lines
Quoted 144 lines
sequencer.c +32
-1+ 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;@@ -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 ;sequencer.h +1
-0@@ -45,6 +45,7 @@ struct replay_opts {int verbose;int quiet;int reschedule_failed_exec; +int committer_date_is_author_date;int mainline;t/t3422-rebase-incompatible-options.sh +0
-1@@ -61,7 +61,6 @@ test_rebase_am_only () { } test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' 't/t3436-rebase-more-options.sh +42
-1@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe . "$TEST_DIRECTORY"/lib-rebase.sh +GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30" +export GIT_AUTHOR_DATE + # This is a special case in which both am and interactive backends # provide the same output. It was done intentionally because # both the backends fall short of optimal behaviour.@@ -21,11 +24,20 @@ test_expect_success 'setup' ' test_write_lines "line 1" "new line 2" "line 3" >file && git commit -am "update file" && git tag side && + test_commit commit1 foo foo1 && + test_commit commit2 foo foo2 && + test_commit commit3 foo foo3 && git checkout --orphan master && + rm foo && test_write_lines "line 1" " line 2" "line 3" >file && git commit -am "add file" && - git tag main + git tag main && + + mkdir test-bin && + write_script test-bin/git-merge-test <<-\EOF + exec git-merge-recursive "$@" + EOF ' test_expect_success '--ignore-whitespace works with apply backend' '@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' git diff --exit-code side ' +test_ctime_is_atime () { + git log $1 --format=%ai >authortime && + git log $1 --format=%ci >committertime && + test_cmp authortime committertime +} + +test_expect_success '--committer-date-is-author-date works with apply backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase --apply --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with merge backend' ' + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author && + git rebase -m --committer-date-is-author-date HEAD^ && + test_ctime_is_atime -1 +' + +test_expect_success '--committer-date-is-author-date works with rebase -r' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + git rebase -r --root --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when forking merge' ' + git checkout side && + GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && + PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 104
Quoted 10 lines
t/t3436-rebase-more-options.sh +10
-0+ --committer-date-is-author-date && + test_ctime_is_atime +' + +test_expect_success '--committer-date-is-author-date works when committing conflict resolution' ' + git checkout commit2 && + GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author && + test_must_fail git rebase -m --committer-date-is-author-date \ + --onto HEAD^^ HEAD^ && + echo resolved > foo &&Nitpick: no space after ">" :D
Signature · 1 line
Danh