[PATCH] rebase -i: avoid --cherry-pick when rebasing to a direct ancestor
- From
Thomas Rast <trast@student.ethz.ch>
- Date
- Feb 19, 2010, 23:30 UTC
- Message-ID
- <d1a75633daa062b25527dfb0675673480974c940.1266620423.git.trast@student.ethz.ch>
- In-Reply-To
- <dfb660301002191324i7aeca7f5x990501bbca1475a9@mail.gmail.com>
Ordinary 'rebase -i' reads the commits to rebase with (roughly)
git rev-list --left-right --cherry-pick $upstream...
which gives it the feature of skipping commits that are already present in $upstream. However, in the common use-case of rewriting a few commits up to an ancestor, as in 'git rebase -i HEAD~3', the --cherry-pick is useless since there are no commits to compare to.
Add a check if $upstream is a direct ancestor of HEAD, and leave away the --cherry-pick if so. Since the --cherry-pick is already in $MERGES_OPTION, we need to decide this before setting the latter.
For simplicity we skip --root mode. In theory we could do the same optimization, but using --root --onto <ancestor> is probably even more rare than having performance issues with --cherry-pick.
Signed-off-by: Thomas Rast <trast@student.ethz.ch> ---
The --cherry-pick mechanism itself could get a similar optimization, but I don't know that code.
git-rebase--interactive.sh | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 1fda620..10b0ed8 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -870,7 +870,12 @@ first and then run 'git rebase --continue' again." MERGES_OPTION= first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)" else - MERGES_OPTION="--no-merges --cherry-pick" + if test -z "$REBASE_ROOT" && + test $(git merge-base $UPSTREAM $HEAD) = $UPSTREAM; then + MERGES_OPTION="--no-merges" + else + MERGES_OPTION="--no-merges --cherry-pick" + fi fi SHORTHEAD=$(git rev-parse --short $HEAD)
-- 1.7.0.139.gd1a75