@matheusbsbs / matheus-bagliano / commits / 0e757e30c7
Fork 0

rebase -i: avoid 'git reset' when possible

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@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 3, 2009 at 10:55 UTC 0e757e30c726d9d8ae82bd9989be3cff5d230288
2 files changed +37
git-rebase--interactive.sh
+26
@@ -442,6 +442,30 @@ do_rest () {
442 done
443 }
444
445 +# skip picking commits whose parents are unchanged
446 +skip_unnecessary_picks () {
447 + fd=3
448 + while read command sha1 rest
449 + do
450 + # fd=3 means we skip the command
451 + case "$fd,$command,$(git rev-parse --verify --quiet $sha1^)" in
452 + 3,pick,"$ONTO"*|3,p,"$ONTO"*)
453 + # pick a commit whose parent is current $ONTO -> skip
454 + ONTO=$sha1
455 + ;;
456 + 3,#*|3,,*)
457 + # copy comments
458 + ;;
459 + *)
460 + fd=1
461 + ;;
462 + esac
463 + echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
464 + done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
465 + mv -f "$TODO".new "$TODO" ||
466 + die "Could not skip unnecessary pick commands"
467 +}
468 +
469 # check if no other options are set
470 is_standalone () {
471 test $# -eq 2 -a "$2" = '--' &&
@@ -746,6 +770,8 @@ EOF
770 has_action "$TODO" ||
771 die_abort "Nothing to do"
772
773 + test -d "$REWRITTEN" || skip_unnecessary_picks
774 +
775 git update-ref ORIG_HEAD $HEAD
776 output git checkout $ONTO && do_rest
777 ;;
t/t3404-rebase-interactive.sh
+11
@@ -459,4 +459,15 @@ test_expect_success 'submodule rebase -i' '
459 FAKE_LINES="1 squash 2 3" git rebase -i A
460 '
461
462 +test_expect_success 'avoid unnecessary reset' '
463 + git checkout master &&
464 + test-chmtime =123456789 file3 &&
465 + git update-index --refresh &&
466 + HEAD=$(git rev-parse HEAD) &&
467 + git rebase -i HEAD~4 &&
468 + test $HEAD = $(git rev-parse HEAD) &&
469 + MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
470 + test 123456789 = $MTIME
471 +'
472 +
473 test_done