Skip to content

Commit

Permalink
Merge branch 'js/rebase-i-opt'
Browse files Browse the repository at this point in the history
* js/rebase-i-opt:
  rebase -i: avoid 'git reset' when possible
  • Loading branch information
Junio C Hamano committed Mar 20, 2009
2 parents 17e46ea + 0e757e3 commit 72c2de5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,30 @@ do_rest () {
done
}

# skip picking commits whose parents are unchanged
skip_unnecessary_picks () {
fd=3
while read command sha1 rest
do
# fd=3 means we skip the command
case "$fd,$command,$(git rev-parse --verify --quiet $sha1^)" in
3,pick,"$ONTO"*|3,p,"$ONTO"*)
# pick a commit whose parent is current $ONTO -> skip
ONTO=$sha1
;;
3,#*|3,,*)
# copy comments
;;
*)
fd=1
;;
esac
echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
mv -f "$TODO".new "$TODO" ||
die "Could not skip unnecessary pick commands"
}

# check if no other options are set
is_standalone () {
test $# -eq 2 -a "$2" = '--' &&
Expand Down Expand Up @@ -746,6 +770,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
;;
Expand Down
11 changes: 11 additions & 0 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 72c2de5

Please sign in to comment.