When picking commits whose parents have not changed, we do not need to rewrite the commit. We do not need to reset the working directory to the parent's state, either. Requested by Sverre Rabbelier. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- On Fri, 27 Feb 2009, Johannes Schindelin wrote: > Having said that, I think yours might be such a common case that > it is worth optimizing for. And so I did. git-rebase--interactive.sh | 23 +++++++++++++++++++++++ t/t3404-rebase-interactive.sh | 11 +++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 3dc659d..a9617a2 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -442,6 +442,27 @@ do_rest () { done } +# skip picking commits whose parents are unchanged +skip_unnecessary_picks () { + current=$ONTO + i=0 + while read command sha1 rest + do + test pick = "$command" && + test $current = "$(git rev-parse $sha1^)" || + break + current=$(git rev-parse $sha1) + i=$(($i+1)) + done < "$TODO" + test $i = 0 || { + sed -e "${i}q" < "$TODO" >> "$DONE" && + sed -e "1,${i}d" < "$TODO" >> "$TODO".new && + mv -f "$TODO".new "$TODO" && + ONTO=$current || + die "Could not skip $i pick commands" + } +} + # check if no other options are set is_standalone () { test $# -eq 2 -a "$2" = '--' && @@ -746,6 +767,8 @@ EOF has_action "$TODO" || die_abort "Nothing to do" + test -d "$REWRITTEN" || skip_unnecessary_picks + git update-ref ORIG_HEAD $HEAD output git checkout $ONTO && do_rest ;; diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 603b003..c32ff66 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -459,4 +459,15 @@ test_expect_success 'submodule rebase -i' ' FAKE_LINES="1 squash 2 3" git rebase -i A ' +test_expect_success 'avoid unnecessary reset' ' + git checkout master && + test-chmtime =123456789 file3 && + git update-index --refresh && + HEAD=$(git rev-parse HEAD) && + git rebase -i HEAD~4 && + test $HEAD = $(git rev-parse HEAD) && + MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && + test 123456789 = $MTIME +' + test_done -- 1.6.2.rc1.350.g6caf6 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html