Code

rebase: extract am code to new source file
authorMartin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Tue, 28 Dec 2010 09:30:36 +0000 (10:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Dec 2010 23:05:07 +0000 (15:05 -0800)
Extract the code for am-based rebase to git-rebase--am.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
.gitignore
Makefile
git-rebase--am.sh [new file with mode: 0644]
git-rebase.sh

index 40506ff0da04dba014ad0a3d47a52e3ce79d3d99..ef040585e75ec19c4f0c77f6e34d4ba0e7d2b7cb 100644 (file)
 /git-quiltimport
 /git-read-tree
 /git-rebase
+/git-rebase--am
 /git-rebase--interactive
 /git-rebase--merge
 /git-receive-pack
index ffc3a5d2559dc3f9b5c65ab0ee92d69923e92458..459df3a2a9bdace4c916618e3eebc25c2378f9dd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -369,6 +369,7 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
+SCRIPT_SH += git-rebase--am.sh
 SCRIPT_SH += git-rebase--interactive.sh
 SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
diff --git a/git-rebase--am.sh b/git-rebase--am.sh
new file mode 100644 (file)
index 0000000..9316761
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+case "$action" in
+continue)
+       git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+       move_to_original_branch
+       exit
+       ;;
+skip)
+       git am --skip -3 --resolvemsg="$RESOLVEMSG" &&
+       move_to_original_branch
+       exit
+       ;;
+esac
+
+test -n "$rebase_root" && root_flag=--root
+
+git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+       --src-prefix=a/ --dst-prefix=b/ \
+       --no-renames $root_flag "$revisions" |
+git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
+move_to_original_branch
+ret=$?
+test 0 != $ret -a -d "$state_dir" &&
+       echo $head_name > "$state_dir/head-name" &&
+       echo $onto > "$state_dir/onto" &&
+       echo $orig_head > "$state_dir/orig-head" &&
+       echo "$GIT_QUIET" > "$state_dir/quiet"
+exit $ret
index ee586e8dd07bbdfc18d296c642ffd62e9dd31082..615d9ddea37e460a435258ff7b362b4f3282c018 100755 (executable)
@@ -94,9 +94,9 @@ run_specific_rebase () {
        export onto autosquash strategy strategy_opts verbose rebase_root \
        force_rebase action preserve_merges upstream switch_to head_name \
        state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
-       allow_rerere_autoupdate
+       allow_rerere_autoupdate git_am_opt
        export -f move_to_original_branch
-       test "$type" != am && exec git-rebase--$type
+       exec git-rebase--$type
 }
 
 run_pre_rebase_hook () {
@@ -266,17 +266,11 @@ continue)
        }
        read_basic_state
        run_specific_rebase
-       git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
-       move_to_original_branch
-       exit
        ;;
 skip)
        git reset --hard HEAD || exit $?
        read_basic_state
        run_specific_rebase
-       git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
-       move_to_original_branch
-       exit
        ;;
 abort)
        git rerere clear
@@ -329,14 +323,12 @@ then
        shift
        upstream=`git rev-parse --verify "${upstream_name}^0"` ||
        die "invalid upstream $upstream_name"
-       unset root_flag
        upstream_arg="$upstream_name"
 else
        test -z "$onto" && die "You must specify --onto when using --root"
        unset upstream_name
        unset upstream
-       root_flag="--root"
-       upstream_arg="$root_flag"
+       upstream_arg=--root
 fi
 
 # Make sure the branch to rebase onto is valid.
@@ -461,23 +453,4 @@ else
        revisions="$upstream..$orig_head"
 fi
 
-if test -z "$do_merge"
-then
-       git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-               --src-prefix=a/ --dst-prefix=b/ \
-               --no-renames $root_flag "$revisions" |
-       git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
-       move_to_original_branch
-       ret=$?
-       test 0 != $ret -a -d "$apply_dir" &&
-               echo $head_name > "$apply_dir/head-name" &&
-               echo $onto > "$apply_dir/onto" &&
-               echo $orig_head > "$apply_dir/orig-head" &&
-               echo "$GIT_QUIET" > "$apply_dir/quiet"
-       exit $ret
-fi
-
-# start doing a rebase with git-merge
-# this is rename-aware if the recursive (default) strategy is used
-
 run_specific_rebase