rebase -i: stop checking out the tip of the branch to rebase

One of the first things done when using a sequencer-based
rebase (ie. `rebase -i', `rebase -r', or `rebase -m') is to make a todo
list.  This requires knowledge of the commit range to rebase.  To get
the oid of the last commit of the range, the tip of the branch to rebase
is checked out with prepare_branch_to_be_rebased(), then the oid of the
head is read.  After this, the tip of the branch is not even modified.
The `am' backend, on the other hand, does not check out the branch.

On big repositories, it's a performance penalty: with `rebase -i', the
user may have to wait before editing the todo list while git is
extracting the branch silently, and "quiet" rebases will be slower than
`am'.

Since we already have the oid of the tip of the branch in
`opts->orig_head', it's useless to switch to this commit.

This removes the call to prepare_branch_to_be_rebased() in
do_interactive_rebase(), and adds a `orig_head' parameter to
get_revision_ranges().  prepare_branch_to_be_rebased() is removed as it
is no longer used.

This introduces a visible change: as we do not switch on the tip of the
branch to rebase, no reflog entry is created at the beginning of the
rebase for it.

Unscientific performance measurements, performed on linux.git, are as
follow:

  Before this patch:

    $ time git rebase -m --onto v4.18 463fa44eec2fef50~ 463fa44eec2fef50

    real    0m8,940s
    user    0m6,830s
    sys     0m2,121s

  After this patch:

    $ time git rebase -m --onto v4.18 463fa44eec2fef50~ 463fa44eec2fef50

    real    0m1,834s
    user    0m0,916s
    sys     0m0,206s

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alban Gruin 2020-01-24 16:05:00 +01:00 committed by Junio C Hamano
parent a7312d1a28
commit 767a9c417e
3 changed files with 5 additions and 30 deletions

View File

@ -241,21 +241,17 @@ static int edit_todo_file(unsigned flags)
} }
static int get_revision_ranges(struct commit *upstream, struct commit *onto, static int get_revision_ranges(struct commit *upstream, struct commit *onto,
const char **head_hash, struct object_id *orig_head, const char **head_hash,
char **revisions, char **shortrevisions) char **revisions, char **shortrevisions)
{ {
struct commit *base_rev = upstream ? upstream : onto; struct commit *base_rev = upstream ? upstream : onto;
const char *shorthead; const char *shorthead;
struct object_id orig_head;
if (get_oid("HEAD", &orig_head)) *head_hash = find_unique_abbrev(orig_head, GIT_MAX_HEXSZ);
return error(_("no HEAD?"));
*head_hash = find_unique_abbrev(&orig_head, GIT_MAX_HEXSZ);
*revisions = xstrfmt("%s...%s", oid_to_hex(&base_rev->object.oid), *revisions = xstrfmt("%s...%s", oid_to_hex(&base_rev->object.oid),
*head_hash); *head_hash);
shorthead = find_unique_abbrev(&orig_head, DEFAULT_ABBREV); shorthead = find_unique_abbrev(orig_head, DEFAULT_ABBREV);
if (upstream) { if (upstream) {
const char *shortrev; const char *shortrev;
@ -309,12 +305,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
struct replay_opts replay = get_replay_opts(opts); struct replay_opts replay = get_replay_opts(opts);
struct string_list commands = STRING_LIST_INIT_DUP; struct string_list commands = STRING_LIST_INIT_DUP;
if (prepare_branch_to_be_rebased(the_repository, &replay, if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head,
opts->switch_to)) &head_hash, &revisions, &shortrevisions))
return -1;
if (get_revision_ranges(opts->upstream, opts->onto, &head_hash,
&revisions, &shortrevisions))
return -1; return -1;
if (init_basic_state(&replay, if (init_basic_state(&replay,

View File

@ -3740,20 +3740,6 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts,
return ret; return ret;
} }
int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts,
const char *commit)
{
const char *action;
if (commit && *commit) {
action = reflog_message(opts, "start", "checkout %s", commit);
if (run_git_checkout(r, opts, commit, action))
return error(_("could not checkout %s"), commit);
}
return 0;
}
static int checkout_onto(struct repository *r, struct replay_opts *opts, static int checkout_onto(struct repository *r, struct replay_opts *opts,
const char *onto_name, const struct object_id *onto, const char *onto_name, const struct object_id *onto,
const char *orig_head) const char *orig_head)

View File

@ -184,9 +184,6 @@ void commit_post_rewrite(struct repository *r,
const struct commit *current_head, const struct commit *current_head,
const struct object_id *new_head); const struct object_id *new_head);
int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts,
const char *commit);
#define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_INITIAL_COMMIT (1 << 0)
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
void print_commit_summary(struct repository *repo, void print_commit_summary(struct repository *repo,