[PATCH v3 21/27] rebase -i: explicitly distinguish replay commands and exec tasks
- From
Fabian Ruch <bafain@gmail.com>
- Date
- Aug 18, 2014, 21:23 UTC
- Message-ID
- <f2bd4b597ddabc0fb79d40b494041a43b0ffbddf.1408396036.git.bafain@gmail.com>
- In-Reply-To
- <cover.1408396036.git.bafain@gmail.com>
There are two kinds of to-do list commands available. One kind replays a commit (`pick`, `reword`, `edit`, `squash` and `fixup` that is) and the other executes a shell command (`exec`). We will call the first kind replay commands.
The two kinds of tasks are scheduled using different line formats. Replay commands expect a commit hash argument following the command name and exec concatenates all arguments to assemble a command line.
Adhere to the distinction of formats by not trying to parse the `sha1` field unless we are dealing with a replay command. Move the replay command handling code to a new function `do_replay` which assumes the first argument to be a commit hash and make no more such assumptions in `do_next`.
Signed-off-by: Fabian Ruch <bafain@gmail.com> --- git-rebase--interactive.sh | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 6a123f0..e140bf0 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -577,13 +577,12 @@ do_pick () { fi } -do_next () { - rm -f "$msg" "$author_script" "$amend" || exit - read -r command sha1 rest < "$todo" +do_replay () { + command=$1 + sha1=$2 + rest=$3 + case "$command" in - "$comment_char"*|''|noop) - mark_action_done - ;; pick|p) comment_for_reflog pick @@ -659,6 +658,28 @@ do_next () { esac record_in_rewritten $sha1 ;; + *) + read -r command <"$todo" + warn "Unknown command: $command" + fixtodo="Please fix this using 'git rebase --edit-todo'." + if git rev-parse --verify -q "$sha1" >/dev/null + then + die_with_patch $sha1 "$fixtodo" + else + die "$fixtodo" + fi + ;; + esac +} + +do_next () { + rm -f "$msg" "$author_script" "$amend" || exit + read -r command sha1 rest <"$todo" + + case "$command" in + "$comment_char"*|''|noop) + mark_action_done + ;; x|"exec") read -r command rest < "$todo" mark_action_done @@ -698,14 +719,7 @@ do_next () { fi ;; *) - warn "Unknown command: $command $sha1 $rest" - fixtodo="Please fix this using 'git rebase --edit-todo'." - if git rev-parse --verify -q "$sha1" >/dev/null - then - die_with_patch $sha1 "$fixtodo" - else - die "$fixtodo" - fi + do_replay $command $sha1 "$rest" ;; esac test -s "$todo" && return
-- 2.0.1