summaryrefslogtreecommitdiff
path: root/git-rebase--interactive.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2009-03-03 10:55:31 +0100
committerJunio C Hamano <gitster@pobox.com>2009-03-03 10:56:22 -0800
commit0e757e30c726d9d8ae82bd9989be3cff5d230288 (patch)
treeeb1e1a6de6052abbf6523893f0627aaeb1e6610f /git-rebase--interactive.sh
parent1d035f85649cbb0a4fcc3e341f7e854acf9cf3c1 (diff)
downloadgit-0e757e30c726d9d8ae82bd9989be3cff5d230288.tar.gz
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>
Diffstat (limited to 'git-rebase--interactive.sh')
-rwxr-xr-xgit-rebase--interactive.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 3dc659dd58..314cd364b8 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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" = '--' &&
@@ -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
;;