The final building block for a faster rebase -i
v6 cover The final building block for a faster rebase -i
This patch series reimplements the expensive pre- and post-processing of the todo script in C.
And it concludes the work I did to accelerate rebase -i so far.
I am still unwilling to replace a compile-time safe way to pass the options to the revision machinery by the alternative (which I am still flabbergasted about) proposed by Junio. This will not change.
I know that we want to concentrate on bug fixes on master, but this patch series will most likely take a couple of months to get there, anyway. So I may just as well send this iteration now. It's also not like I haven't contributed any bug fixes lately...
Changes since v5:
- replaced a get_sha1() call by a get_oid() call already.
- adjusted to hashmap API changes
Johannes Schindelin (10):
t3415: verify that an empty instructionFormat is handled as before rebase -i: generate the script via rebase--helper rebase -i: remove useless indentation
rebase -i: do not invent onelines when expanding/collapsing SHA-1s rebase -i: also expand/collapse the SHA-1s via the rebase--helper
t3404: relax rebase.missingCommitsCheck tests
rebase -i: check for missing commits in the rebase--helper rebase -i: skip unnecessary picks using the rebase--helper
t3415: test fixup with wrapped oneline
rebase -i: rearrange fixup/squash lines using the rebase--helper
Documentation/git-rebase.txt | 16 +- builtin/rebase--helper.c | 29 ++- git-rebase--interactive.sh | 373 ++++------------------------- sequencer.c | 531 ++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 8 + t/t3404-rebase-interactive.sh | 22 +- t/t3415-rebase-autosquash.sh | 28 ++- 7 files changed, 647 insertions(+), 360 deletions(-)
base-commit: f3da2b79be9565779e4f76dc5812c68e156afdf0
Based-On: rebase--helper at https://github.com/dscho/git
Fetch-Base-Via: git fetch https://github.com/dscho/git rebase--helper
Published-As: https://github.com/dscho/git/releases/tag/rebase-i-extra-v6
Fetch-It-Via: git fetch https://github.com/dscho/git rebase-i-extra-v6
Interdiff vs v5:
diff --git a/sequencer.c b/sequencer.c
index 8713cc8d1d5..c54596f9699 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2654,7 +2654,7 @@ int skip_unnecessary_picks(void)
if (!read_oneliner(&buf, rebase_path_onto(), 0))
return error(_("could not read 'onto'"));
- if (get_sha1(buf.buf, onto_oid.hash)) {
+ if (get_oid(buf.buf, &onto_oid)) {
strbuf_release(&buf);
return error(_("need a HEAD to fixup"));
}
@@ -2756,8 +2756,9 @@ struct subject2item_entry {
char subject[FLEX_ARRAY];
};
-static int subject2item_cmp(const struct subject2item_entry *a,
- const struct subject2item_entry *b, const void *key)
+static int subject2item_cmp(const void *fndata,
+ const struct subject2item_entry *a,
+ const struct subject2item_entry *b, const void *key)
{
return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject);
}
@@ -2802,7 +2803,7 @@ int rearrange_squash(void)
* be moved to appear after the i'th.
*/
hashmap_init(&subject2item, (hashmap_cmp_fn) subject2item_cmp,
- todo_list.nr);
+ NULL, todo_list.nr);
ALLOC_ARRAY(next, todo_list.nr);
ALLOC_ARRAY(tail, todo_list.nr);
ALLOC_ARRAY(subjects, todo_list.nr);
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 1/10 t3415: verify that an empty instructionFormat is handled as before
An upcoming patch will move the todo list generation into the rebase--helper. An early version of that patch regressed on an empty rebase.instructionFormat value (the shell version could not discern between an empty one and a non-existing one, but the C version used the empty one as if that was intended to skip the oneline from the pick <hash> lines).
Let's verify that this still works as before.
--- t/t3415-rebase-autosquash.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)
t/t3415-rebase-autosquash.sh +12 -0
@@ -271,6 +271,18 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' test 2 = $(git cat-file commit HEAD^ | grep squash | wc -l) ' +test_expect_success 'autosquash with empty custom instructionFormat' ' + git reset --hard base && + test_commit empty-instructionFormat-test && + ( + set_cat_todo_editor && + test_must_fail git -c rebase.instructionFormat= \ + rebase --autosquash --force -i HEAD^ >actual && + git log -1 --format="pick %h %s" >expect && + test_cmp expect actual + ) +' + set_backup_editor () { write_script backup-editor.sh <<-\EOF cp "$1" .git/backup-"$(basename "$1")"
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 2/10 rebase -i: generate the script via rebase--helper
In reply to Johannes SchindelinThe first step of an interactive rebase is to generate the so-called "todo script", to be stored in the state directory as "git-rebase-todo" and to be edited by the user.
Originally, we adjusted the output of git log <options> using a simple sed script. Over the course of the years, the code became more complicated. We now use shell scripting to edit the output of git log conditionally, depending whether to keep "empty" commits (i.e. commits that do not change any files).
On platforms where shell scripting is not native, this can be a serious drag. And it opens the door for incompatibilities between platforms when it comes to shell scripting or to Unix-y commands.
Let's just re-implement the todo script generation in plain C, using the revision machinery directly.
This is substantially faster, improving the speed relative to the shell script version of the interactive rebase from 2x to 3x on Windows.
Note that the rearrange_squash() function in git-rebase--interactive relied on the fact that we set the "format" variable to the config setting rebase.instructionFormat. Relying on a side effect like this is no good, hence we explicitly perform that assignment (possibly again) in rearrange_squash().
--- builtin/rebase--helper.c | 8 +++++++- git-rebase--interactive.sh | 44 +++++++++++++++++++++-------------------- sequencer.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 3 +++ 4 files changed, 82 insertions(+), 22 deletions(-)
builtin/rebase--helper.c +7 -1
@@ -12,15 +12,19 @@ static const char * const builtin_rebase_helper_usage[] = {int cmd_rebase__helper (int argc,const char **argv,const char *prefix) {struct replay_opts opts =REPLAY_OPTS_INIT ; +int keep_empty =0 ;enum { -CONTINUE =1 ,ABORT +CONTINUE =1 ,ABORT ,MAKE_SCRIPT } command =0 ;struct option options[] = {OPT_BOOL (0 ,"ff" , &opts.allow_ff,N_ ("allow fast-forward" )), +OPT_BOOL (0 ,"keep-empty" , &keep_empty,N_ ("keep empty commits" )),OPT_CMDMODE (0 ,"continue" , &command,N_ ("continue rebase" ),CONTINUE ),OPT_CMDMODE (0 ,"abort" , &command,N_ ("abort rebase" ),ABORT ), +OPT_CMDMODE (0 ,"make-script" , &command, +N_ ("make rebase script" ),MAKE_SCRIPT ),OPT_END () };
@@ -37,5 +41,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)return !!sequencer_continue (&opts);if (command ==ABORT && argc ==1 )return !!sequencer_remove_state (&opts); +if (command ==MAKE_SCRIPT && argc >1 ) +return !!sequencer_make_script (keep_empty, stdout, argc, argv);usage_with_options (builtin_rebase_helper_usage, options); }
git-rebase--interactive.sh +23 -21
63 lines not on this page · raw message
sequencer.c +49 -0
52 lines not on this page · raw message
sequencer.h +3 -0
@@ -45,6 +45,9 @@ int sequencer_continue(struct replay_opts *opts);int sequencer_rollback (struct replay_opts *opts);int sequencer_remove_state (struct replay_opts *opts); +int sequencer_make_script (int keep_empty,FILE *out, +int argc,const char **argv); +extern const char sign_off_header[];void append_signoff (struct strbuf *msgbuf,int ignore_footer,unsigned flag);
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
Re: [PATCH v6 02/10] rebase -i: generate the script via rebase--helper
Quoted 14 lines · Johannes Schindelin
The first step of an interactive rebase is to generate the so-called "todo script", to be stored in the state directory as "git-rebase-todo" and to be edited by the user.
Originally, we adjusted the output of
git log <options>using a simple sed script. Over the course of the years, the code became more complicated. We now use shell scripting to edit the output ofgit logconditionally, depending whether to keep "empty" commits (i.e. commits that do not change any files).On platforms where shell scripting is not native, this can be a serious drag. And it opens the door for incompatibilities between platforms when it comes to shell scripting or to Unix-y commands.
Quoted 5 lines
Let's just re-implement the todo script generation in plain C, using the revision machinery directly.
This is substantially faster, improving the speed relative to the shell script version of the interactive rebase from 2x to 3x on Windows.
Thanks for working on this
Quoted 10 lines
sequencer.c +9
-0+int sequencer_make_script (int keep_empty,FILE *out, +int argc,const char **argv) +{ +init_revisions (&revs,NULL ); + revs.verbose_header =1 ; + revs.max_parents =1 ; + revs.cherry_pick =1 ; + revs.limited =1 ; + revs.reverse =1 ;
sequencer.c void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag) · line 2441
Quoted 10 lines
sequencer.c +10
-0+ revs.right_only =1 ; + revs.sort_order =REV_SORT_IN_GRAPH_ORDER ; + revs.topo_order =1 ; + + revs.pretty_given =1 ; +git_config_get_string ("rebase.instructionFormat" , &format); +if (!format || !*format) { +free (format); + format =xstrdup ("%s" ); + }
https://public-inbox.org/git/[email protected]/
So this is the core part that you and Junio have differing opinions on.
Quoted 7 lines
All of the above feels like inviting unnecessary future breakages by knowing too much about the implementation the current version of
revision.chappens to use. A more careful implementation would be to allocate our own av[] and prepare "--reverse", "--left-right", "--cherry-pick", etc. to be parsed bysetup_revisions()call we see below. The parsing is not an expensive part of the operation anyway, and that way we do not have to worry about one less thing.
Allow me go through each of the options which may help us finding a consensus (at least it helps me having a more informed opinion).
List of options used outside of revision.c, which in the ideal world of Git are parsed in e.g. handle_revision_opt called from setup_revisions:
.verbose_header
bisect.c: opt.verbose_header = 1;
builtin/commit.c: rev.verbose_header = 1;
builtin/log.c: rev->verbose_header = 1; builtin/log.c: rev.verbose_header = 1; builtin/log.c: rev.verbose_header = 1;
.max_parents
builtin/log.c: check_rev.max_parents = 1; builtin/log.c: revs.max_parents = 1; builtin/log.c: rev.max_parents = 1; builtin/log.c: revs.max_parents = 1;
.cherry_pick
is clean!
.limited
ref-filter.c: revs.limited = 1;
.reverse
seems clean.
.right_only:
.sort_order:
is clean!
.topo_order:
builtin/fast-export.c: revs.topo_order = 1;
builtin/log.c: revs.topo_order = 1;
.pretty_given
builtin/log.c: if (!rev->show_notes_given && (!rev->pretty_given || w.notes)) builtin/log.c: if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {
There are two conflicting messages I get:
* only a few fields seem to be polluted (verbose_header, max_parents), much fewer than I thought
* we do use these undocumented ways already, but not at the scale that DScho is trying to here.
In the reply to the cover letter I outlined that we may have a problem with integrating the repository struct when using string arrays only.
Thanks,
Stefan
Re: [PATCH v6 02/10] rebase -i: generate the script via rebase--helper
Hi Stefan,
Quoted 5 lines · Stefan Beller
There are two conflicting messages I get:
* only a few fields seem to be polluted (verbose_header,max_parents), much fewer than I thought
* we do use these undocumented ways already, but not at the scale that DScho is trying to here.
We use mostly undocumented ways, because there is simply no API. It was decided early on that libgit was never intended to be a public API. So that's that.
TBH a much better way to handle this would have been to say: this is fragile, as the pretty-printing is not properly abstracted, and hence we may need to break the contract at some stage (which would not cause compile errors, though), maybe you, Dscho, can fix that after this patch series was applied by abstracting it properly?
Ciao,
Dscho
PATCH v6 3/10 rebase -i: remove useless indentation
In reply to Johannes SchindelinThe commands used to be indented, and it is nice to look at, but when we transform the SHA-1s, the indentation is removed. So let's do away with it.
For the moment, at least: when we will use the upcoming rebase--helper to transform the SHA-1s, we *will* keep the indentation and can reintroduce it. Yet, to be able to validate the rebase--helper against the output of the current shell script version, we need to remove the extra indentation.
--- git-rebase--interactive.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
git-rebase--interactive.sh +7 -7
@@ -155,13 +155,13 @@ reschedule_last_action () { append_todo_help () { gettext " Commands: - p, pick = use commit - r, reword = use commit, but edit the commit message - e, edit = use commit, but stop for amending - s, squash = use commit, but meld into previous commit - f, fixup = like \"squash\", but discard this commit's log message - x, exec = run command (the rest of the line) using shell - d, drop = remove commit +p, pick = use commit +r, reword = use commit, but edit the commit message +e, edit = use commit, but stop for amending +s, squash = use commit, but meld into previous commit +f, fixup = like \"squash\", but discard this commit's log message +x, exec = run command (the rest of the line) using shell +d, drop = remove commit These lines can be re-ordered; they are executed from top to bottom. " | git stripspace --comment-lines >>"$todo"
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 4/10 rebase -i: do not invent onelines when expanding/collapsing SHA-1s
In reply to Johannes SchindelinTo avoid problems with short SHA-1s that become non-unique during the rebase, we rewrite the todo script with short/long SHA-1s before and after letting the user edit the script. Since SHA-1s are not intuitive for humans, rebase -i also provides the onelines (commit message subjects) in the script, purely for the user's convenience.
It is very possible to generate a todo script via different means than rebase -i and then to let rebase -i run with it; In this case, these onelines are not required.
And this is where the expand/collapse machinery has a bug: it *expects* that oneline, and failing to find one reuses the previous SHA-1 as "oneline".
It was most likely an oversight, and made implementation in the (quite limiting) shell script language less convoluted. However, we are about to reimplement performance-critical parts in C (and due to spawning a git.exe process for every single line of the todo script, the expansion/collapsing of the SHA-1s *is* performance-hampering on Windows), therefore let's fix this bug to make cross-validation with the C version of that functionality possible.
--- git-rebase--interactive.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
git-rebase--interactive.sh +6 -1
@@ -760,7 +760,12 @@ transform_todo_ids () { ;; *) sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) && - rest="$sha1 ${rest#*[ ]}" + if test "a$rest" = "a${rest#*[ ]}" + then + rest=$sha1 + else + rest="$sha1 ${rest#*[ ]}" + fi ;; esac printf '%s\n' "$command${rest:+ }$rest"
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 5/10 rebase -i: also expand/collapse the SHA-1s via the rebase--helper
In reply to Johannes SchindelinThis is crucial to improve performance on Windows, as the speed is now mostly dominated by the SHA-1 transformation (because it spawns a new rev-parse process for *every* line, and spawning processes is pretty slow from Git for Windows' MSYS2 Bash).
--- builtin/rebase--helper.c | 10 +++++++- git-rebase--interactive.sh | 27 ++-------------------- sequencer.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 2 ++ 4 files changed, 70 insertions(+), 26 deletions(-)
builtin/rebase--helper.c +9 -1
@@ -14,7 +14,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)struct replay_opts opts =REPLAY_OPTS_INIT ;int keep_empty =0 ;enum { -CONTINUE =1 ,ABORT ,MAKE_SCRIPT +CONTINUE =1 ,ABORT ,MAKE_SCRIPT ,SHORTEN_SHA1S ,EXPAND_SHA1S } command =0 ;struct option options[] = {OPT_BOOL (0 ,"ff" , &opts.allow_ff,N_ ("allow fast-forward" )),
@@ -25,6 +25,10 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) ABORT),OPT_CMDMODE (0 ,"make-script" , &command,N_ ("make rebase script" ),MAKE_SCRIPT ), +OPT_CMDMODE (0 ,"shorten-ids" , &command, +N_ ("shorten SHA-1s in the todo list" ),SHORTEN_SHA1S ), +OPT_CMDMODE (0 ,"expand-ids" , &command, +N_ ("expand SHA-1s in the todo list" ),EXPAND_SHA1S ), OPT_END() };
@@ -43,5 +47,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)return !!sequencer_remove_state (&opts);if (command ==MAKE_SCRIPT && argc >1 )return !!sequencer_make_script (keep_empty, stdout, argc, argv); +if (command ==SHORTEN_SHA1S && argc ==1 ) +return !!transform_todo_ids (1 ); +if (command ==EXPAND_SHA1S && argc ==1 ) +return !!transform_todo_ids (0 );usage_with_options (builtin_rebase_helper_usage, options); }
git-rebase--interactive.sh +2 -25
@@ -750,35 +750,12 @@ skip_unnecessary_picks () { die "$(gettext "Could not skip unnecessary pick commands")" } -transform_todo_ids () { - while read -r command rest - do - case "$command" in - "$comment_char"* | exec) - # Be careful for oddball commands like 'exec' - # that do not have a SHA-1 at the beginning of $rest. - ;; - *) - sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) && - if test "a$rest" = "a${rest#*[ ]}" - then - rest=$sha1 - else - rest="$sha1 ${rest#*[ ]}" - fi - ;; - esac - printf '%s\n' "$command${rest:+ }$rest" - done <"$todo" >"$todo.new" && - mv -f "$todo.new" "$todo" -} - expand_todo_ids() { - transform_todo_ids + git rebase--helper --expand-ids } collapse_todo_ids() { - transform_todo_ids --short + git rebase--helper --shorten-ids } # Rearrange the todo list that has both "pick sha1 msg" and
sequencer.c +57 -0
60 lines not on this page · raw message
sequencer.h +2 -0
@@ -48,6 +48,8 @@ int sequencer_remove_state(struct replay_opts *opts);int sequencer_make_script (int keep_empty,FILE *out,int argc,const char **argv); +int transform_todo_ids (int shorten_ids); +extern const char sign_off_header[];void append_signoff (struct strbuf *msgbuf,int ignore_footer,unsigned flag);
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 6/10 t3404: relax rebase.missingCommitsCheck tests
In reply to Johannes SchindelinThese tests were a bit anal about the *exact* warning/error message printed by git rebase. But those messages are intended for the *end user*, therefore it does not make sense to test so rigidly for the *exact* wording.
In the following, we will reimplement the missing commits check in the sequencer, with slightly different words.
So let's just test for the parts in the warning/error message that we *really* care about, nothing more, nothing less.
--- t/t3404-rebase-interactive.sh | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
t/t3404-rebase-interactive.sh +4 -18
@@ -1249,20 +1249,13 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' -cat >expect <<EOF -Warning: the command isn't recognized in the following line: - - badcmd $(git rev-list --oneline -1 master~1) - -You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. -Or you can abort the rebase with 'git rebase --abort'. -EOF - test_expect_success 'static check of bad command' ' rebase_setup_and_clean bad-cmd && set_fake_editor && test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ncmp expect actual && + test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual && + test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual && FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo && git rebase --continue && test E = $(git cat-file commit HEAD | sed -ne \$p) &&
@@ -1284,20 +1277,13 @@ test_expect_success 'tabs and spaces are accepted in the todolist' ' test E = $(git cat-file commit HEAD | sed -ne \$p) ' -cat >expect <<EOF -Warning: the SHA-1 is missing or isn't a commit in the following line: - - edit XXXXXXX False commit - -You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. -Or you can abort the rebase with 'git rebase --abort'. -EOF - test_expect_success 'static check of bad SHA-1' ' rebase_setup_and_clean bad-sha && set_fake_editor && test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ git rebase -i --root 2>actual && - test_i18ncmp expect actual && + test_i18ngrep "edit XXXXXXX False commit" actual && + test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual && FAKE_LINES="1 2 4 5 6" git rebase --edit-todo && git rebase --continue && test E = $(git cat-file commit HEAD | sed -ne \$p)
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 7/10 rebase -i: check for missing commits in the rebase--helper
In reply to Johannes SchindelinIn particular on Windows, where shell scripts are even more expensive than on MacOSX or Linux, it makes sense to move a loop that forks Git at least once for every line in the todo list into a builtin.
--- builtin/rebase--helper.c | 7 +- git-rebase--interactive.sh | 164 ++------------------------------------------- sequencer.c | 122 +++++++++++++++++++++++++++++++++ sequencer.h | 1 + 4 files changed, 134 insertions(+), 160 deletions(-)
builtin/rebase--helper.c +6 -1
@@ -14,7 +14,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)struct replay_opts opts =REPLAY_OPTS_INIT ;int keep_empty =0 ;enum { -CONTINUE =1 ,ABORT ,MAKE_SCRIPT ,SHORTEN_SHA1S ,EXPAND_SHA1S +CONTINUE =1 ,ABORT ,MAKE_SCRIPT ,SHORTEN_SHA1S ,EXPAND_SHA1S , +CHECK_TODO_LIST } command =0 ;struct option options[] = {OPT_BOOL (0 ,"ff" , &opts.allow_ff,N_ ("allow fast-forward" )),
@@ -29,6 +30,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),OPT_CMDMODE (0 ,"expand-ids" , &command,N_ ("expand SHA-1s in the todo list" ),EXPAND_SHA1S ), +OPT_CMDMODE (0 ,"check-todo-list" , &command, +N_ ("check the todo list" ),CHECK_TODO_LIST ), OPT_END() };
@@ -51,5 +54,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)return !!transform_todo_ids (1 );if (command ==EXPAND_SHA1S && argc ==1 )return !!transform_todo_ids (0 ); +if (command ==CHECK_TODO_LIST && argc ==1 ) +return !!check_todo_list ();usage_with_options (builtin_rebase_helper_usage, options); }
git-rebase--interactive.sh +5 -159
182 lines not on this page · raw message
sequencer.c +122 -0
125 lines not on this page · raw message
sequencer.h +1 -0
@@ -49,6 +49,7 @@ int sequencer_make_script(int keep_empty, FILE *out, int argc, const char **argv);int transform_todo_ids (int shorten_ids); +int check_todo_list (void );extern const char sign_off_header[];
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 8/10 rebase -i: skip unnecessary picks using the rebase--helper
In reply to Johannes SchindelinIn particular on Windows, where shell scripts are even more expensive than on MacOSX or Linux, it makes sense to move a loop that forks Git at least once for every line in the todo list into a builtin.
Note: The original code did not try to skip unnecessary picks of root commits but punts instead (probably --root was not considered common enough of a use case to bother optimizing). We do the same, for now.
--- builtin/rebase--helper.c | 6 ++- git-rebase--interactive.sh | 41 ++--------------- sequencer.c | 107 +++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 1 + 4 files changed, 116 insertions(+), 39 deletions(-)
builtin/rebase--helper.c +5 -1
@@ -15,7 +15,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)int keep_empty =0 ;enum {CONTINUE =1 ,ABORT ,MAKE_SCRIPT ,SHORTEN_SHA1S ,EXPAND_SHA1S , -CHECK_TODO_LIST +CHECK_TODO_LIST ,SKIP_UNNECESSARY_PICKS } command =0 ;struct option options[] = {OPT_BOOL (0 ,"ff" , &opts.allow_ff,N_ ("allow fast-forward" )),
@@ -32,6 +32,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),OPT_CMDMODE (0 ,"check-todo-list" , &command,N_ ("check the todo list" ),CHECK_TODO_LIST ), +OPT_CMDMODE (0 ,"skip-unnecessary-picks" , &command, +N_ ("skip unnecessary picks" ),SKIP_UNNECESSARY_PICKS ), OPT_END() };
@@ -56,5 +58,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)return !!transform_todo_ids (0 );if (command ==CHECK_TODO_LIST && argc ==1 )return !!check_todo_list (); +if (command ==SKIP_UNNECESSARY_PICKS && argc ==1 ) +return !!skip_unnecessary_picks ();usage_with_options (builtin_rebase_helper_usage, options); }
git-rebase--interactive.sh +3 -38
53 lines not on this page · raw message
sequencer.c +107 -0
110 lines not on this page · raw message
sequencer.h +1 -0
@@ -50,6 +50,7 @@ int sequencer_make_script(int keep_empty, FILE *out,int transform_todo_ids (int shorten_ids);int check_todo_list (void ); +int skip_unnecessary_picks (void );extern const char sign_off_header[];
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 9/10 t3415: test fixup with wrapped oneline
In reply to Johannes SchindelinThe git commit --fixup command unwraps wrapped onelines when constructing the commit message, without wrapping the result.
We need to make sure that git rebase --autosquash keeps handling such cases correctly, in particular since we are about to move the autosquash handling into the rebase--helper.
--- t/t3415-rebase-autosquash.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
t/t3415-rebase-autosquash.sh +14 -0
@@ -316,4 +316,18 @@ test_expect_success 'extra spaces after fixup!' ' test $base = $parent ' +test_expect_success 'wrapped original subject' ' + if test -d .git/rebase-merge; then git rebase --abort; fi && + base=$(git rev-parse HEAD) && + echo "wrapped subject" >wrapped && + git add wrapped && + test_tick && + git commit --allow-empty -m "$(printf "To\nfixup")" && + test_tick && + git commit --allow-empty -m "fixup! To fixup" && + git rebase -i --autosquash --keep-empty HEAD~2 && + parent=$(git rev-parse HEAD^) && + test $base = $parent +' + test_done
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
PATCH v6 10/10 rebase -i: rearrange fixup/squash lines using the rebase--helper
In reply to Johannes SchindelinThis operation has quadratic complexity, which is especially painful on Windows, where shell scripts are *already* slow (mainly due to the overhead of the POSIX emulation layer).
Let's reimplement this with linear complexity (using a hash map to match the commits' subject lines) for the common case; Sadly, the fixup/squash feature's design neglected performance considerations, allowing arbitrary prefixes (read: fixup! hell will match the commit subject hello world), which means that we are stuck with quadratic performance in the worst case.
The reimplemented logic also happens to fix a bug where commented-out lines (representing empty patches) were dropped by the previous code.
While at it, clarify how the fixup/squash feature works in git rebase -i's man page.
--- Documentation/git-rebase.txt | 16 ++-- builtin/rebase--helper.c | 6 +- git-rebase--interactive.sh | 90 +------------------- sequencer.c | 196 +++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 1 + t/t3415-rebase-autosquash.sh | 2 +- 6 files changed, 213 insertions(+), 98 deletions(-)
Documentation/git-rebase.txt +9 -7
@@ -430,13 +430,15 @@ without an explicit `--interactive`. --autosquash:: --no-autosquash:: When the commit log message begins with "squash! ..." (or - "fixup! ..."), and there is a commit whose title begins with - the same ..., automatically modify the todo list of rebase -i - so that the commit marked for squashing comes right after the - commit to be modified, and change the action of the moved - commit from `pick` to `squash` (or `fixup`). Ignores subsequent - "fixup! " or "squash! " after the first, in case you referred to an - earlier fixup/squash with `git commit --fixup/--squash`. + "fixup! ..."), and there is already a commit in the todo list that + matches the same `...`, automatically modify the todo list of rebase + -i so that the commit marked for squashing comes right after the + commit to be modified, and change the action of the moved commit + from `pick` to `squash` (or `fixup`). A commit matches the `...` if + the commit subject matches, or if the `...` refers to the commit's + hash. As a fall-back, partial matches of the commit subject work, + too. The recommended way to create fixup/squash commits is by using + the `--fixup`/`--squash` options of linkgit:git-commit[1]. + This option is only valid when the `--interactive` option is used. +
builtin/rebase--helper.c +5 -1
@@ -15,7 +15,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)int keep_empty =0 ;enum {CONTINUE =1 ,ABORT ,MAKE_SCRIPT ,SHORTEN_SHA1S ,EXPAND_SHA1S , -CHECK_TODO_LIST ,SKIP_UNNECESSARY_PICKS +CHECK_TODO_LIST ,SKIP_UNNECESSARY_PICKS ,REARRANGE_SQUASH } command =0 ;struct option options[] = {OPT_BOOL (0 ,"ff" , &opts.allow_ff,N_ ("allow fast-forward" )),
@@ -34,6 +34,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) N_("check the todo list"), CHECK_TODO_LIST),OPT_CMDMODE (0 ,"skip-unnecessary-picks" , &command,N_ ("skip unnecessary picks" ),SKIP_UNNECESSARY_PICKS ), +OPT_CMDMODE (0 ,"rearrange-squash" , &command, +N_ ("rearrange fixup/squash lines" ),REARRANGE_SQUASH ), OPT_END() };
@@ -60,5 +62,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)return !!check_todo_list ();if (command ==SKIP_UNNECESSARY_PICKS && argc ==1 )return !!skip_unnecessary_picks (); +if (command ==REARRANGE_SQUASH && argc ==1 ) +return !!rearrange_squash ();usage_with_options (builtin_rebase_helper_usage, options); }
git-rebase--interactive.sh +1 -89
102 lines not on this page · raw message
sequencer.c +196 -0
205 lines not on this page · raw message
sequencer.h +1 -0
@@ -51,6 +51,7 @@ int sequencer_make_script(int keep_empty, FILE *out,int transform_todo_ids (int shorten_ids);int check_todo_list (void );int skip_unnecessary_picks (void ); +int rearrange_squash (void );extern const char sign_off_header[];
t/t3415-rebase-autosquash.sh +1 -1
@@ -290,7 +290,7 @@ set_backup_editor () { test_set_editor "$PWD/backup-editor.sh" } -test_expect_failure 'autosquash with multiple empty patches' ' +test_expect_success 'autosquash with multiple empty patches' ' test_tick && git commit --allow-empty -m "empty" && test_tick &&
Signature · 1 line
2.13.3.windows.1.13.gaf0c2223da0
Quoted 8 lines · Johannes Schindelin
This patch series reimplements the expensive pre- and post-processing of the todo script in C.
And it concludes the work I did to accelerate rebase -i so far.
I am still unwilling to replace a compile-time safe way to pass the options to the revision machinery by the alternative (which I am still flabbergasted about) proposed by Junio. This will not change.
There is new input for this discussion, though. :)
https://public-inbox.org/git/[email protected]/
was sent out to gauge interest if we want to pull through with removing all the submodule hack, such as 'add_submodule_odb' in submodule.c which just adds the submodule objects as an alternate object store, such that we can do some things in-process (check if a submodule has certain commits, merge_submodule).
For one of these ('merge_submodule') I would have to add the 'struct repository' as another parameter to pass around to the diff and revision walking machinery. But the API for these subsystems is traditionally only operated via an array of strings instead of passing assigning a member field to a value.
So If I were to follow the "use arrays of strings only to operate the revision machinery" I would:
* pass a string indicating which repo to use
(probably the path to git dir?)
* the repository objects are cached, so we can lookup e.g. "the_repository" via the correct string.
* use that repo object inside the revision machinery.
That sounds cumbersome and I would prefer to pass in the repository object directory. So maybe we want to have some other way opposed to "an array of strings" to operate the revision machinery.
Quoted 3 lines
-static int subject2item_cmp(const struct
subject2item_entry*a,
- const structsubject2item_entry*b, const void *key)
+static int subject2item_cmp(const void *fndata,
This could also be named unused_fndata.
Please see origin/sb/hashmap-cleanup, if that makes sense as well (have all arguments const void and cast them inside the function, such that we can avoid the cast to hashmap_cmp_fn in hashmap_init)
Thanks,
Stefan
Hi Stefan,
Quoted 8 lines · Stefan Beller
Quoted 3 lines · Johannes Schindelin
-static int subject2item_cmp(const struct
subject2item_entry*a,
- const structsubject2item_entry*b, const void *key)
+static int subject2item_cmp(const void *fndata,This could also be named
unused_fndata.
Sure. I simply took the version Junio used when he merged the previous patch series iteration into pu.
The function is short enough, though, that I feel it obvious that the parameter is unused.
Ciao,
Dscho
Quoted 5 lines · Johannes Schindelin
Changes since v5:
- replaced a
get_sha1()call by aget_oid()call already.- adjusted to hashmap API changes
Applying this to the tip of 'master' yields exactly the same result as merging the previous round js/rebase-i-final to the tip of 'master' and then applying merge-fix/js/rebase-i-final to adjust to the codebase, so the net effect of this reroll is none. Which is a good sign, as it means there wasn't any rebase mistake and the evil merge we've been carrying was a good one.
But at the same time, I prefer to avoid rebasing to newer 'master' until the codebase starts drifting too far apart, or until a new feature release is made out of newer 'master'. This is primarily because I want dates on commits to mean something---namely, "this change hasn't seen a need to be updated for 'oops, that was wrong' since this date". This use of commit dates as 'priority date' matters much less for a topic not in 'next', but as a general principle, my workflow tries to preserve commit dates for all topics.
For the above reason, I may hold onto this patch series in my inbox without actually updating js/rebase-i-final topic until the current cycle is over; please do not mistake it as this new reroll being ignored.
Thanks.
Hi Junio,
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Changes since v5:
- replaced a
get_sha1()call by aget_oid()call already.
Quoted 8 lines
Quoted 1 line
- adjusted to hashmap API changes
Applying this to the tip of 'master' yields exactly the same result as merging the previous round js/rebase-i-final to the tip of 'master' and then applying merge-fix/js/rebase-i-final to adjust to the codebase, so the net effect of this reroll is none. Which is a good sign, as it means there wasn't any rebase mistake and the evil merge we've been carrying was a good one.
Good.
Quoted 9 lines
But at the same time, I prefer to avoid rebasing to newer 'master' until the codebase starts drifting too far apart, or until a new feature release is made out of newer 'master'. This is primarily because I want dates on commits to mean something---namely, "this change hasn't seen a need to be updated for 'oops, that was wrong' since this date". This use of commit dates as 'priority date' matters much less for a topic not in 'next', but as a general principle, my workflow tries to preserve commit dates for all topics.
By that token, commit message updates would also be inappropriate, in particular when they came from somebody else than the patch author ;-P
As to avoiding a rebase: we can add that to the growing list of things on which we disagree.
If the author dates really meant anything, we would also have to avoid v2, v3, v4, ... v226 of patch series. So that flies in the face of trying to keep the meaning of author dates.
In addition, the development flow I prefer is one that is in harmony with the modern Continuous Integration style, where topic branches are merged into a single, always-ready-to-release integration branch.
That means that I always work off of master, unless there is a good reason to base off of next or even pu. That's to avoid merge conflicts, to see what really gets applied.
I am *especially* adamant about rebasing to a newer upstream commit when there are merge conflicts.
Such as is the case here.
Quoted 4 lines
For the above reason, I may hold onto this patch series in my inbox without actually updating js/rebase-i-final topic until the current cycle is over; please do not mistake it as this new reroll being ignored.
You do as you want, of course. But please note that I will not rebase my topic branches to an ancient revision, especially if that would cause merge conflicts with the current master.
And if there should be another iteration of this wallflower patch series, I will rebase it to the then-current master again [*1*].
Ciao,
Dscho
Footnote *1*: in general, I try to abide by the wishes of maintainers when contributing code, unless those wishes are contrary to what I consider correct software development. Like, when in Rome, I will do as the Romans do. Except when I see them looting a parking meter.