Add commit_message function to get the commit message from a commit and other slight internal improvements. Signed-off-by: Stephan Beyer <s-beyer@xxxxxxx> --- git-rebase--interactive.sh | 61 +++++++++++++++++++++++++------------------ 1 files changed, 35 insertions(+), 26 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 3f926d8..e8ac2ae 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -25,6 +25,7 @@ SQUASH_MSG="$DOTEST"/message-squash PRESERVE_MERGES= STRATEGY= VERBOSE= +MARK_PREFIX='refs/rebase-marks' test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)" test -f "$DOTEST"/verbose && VERBOSE=t @@ -33,7 +34,6 @@ mark the corrected paths with 'git add <paths>', and run 'git rebase --continue'" export GIT_CHERRY_PICK_HELP -mark_prefix=refs/rebase-marks/ warn () { echo "$*" >&2 @@ -73,13 +73,18 @@ comment_for_reflog () { esac } +# Get commit message from commit $1 +commit_message () { + git cat-file commit "$1" | sed -e '1,/^$/d' +} + last_count= mark_action_done () { - sed -e 1q < "$TODO" >> "$DONE" - sed -e 1d < "$TODO" >> "$TODO".new - mv -f "$TODO".new "$TODO" - count=$(grep -c '^[^#]' < "$DONE") - total=$(($count+$(grep -c '^[^#]' < "$TODO"))) + sed -e 1q "$TODO" >>"$DONE" + sed -e 1d "$TODO" >>"$TODO.new" + mv -f "$TODO.new" "$TODO" + count="$(grep -c '^[^#]' "$DONE")" + total="$(expr "$count" + "$(grep -c '^[^#]' "$TODO")")" if test "$last_count" != "$count" then last_count=$count @@ -88,16 +93,18 @@ mark_action_done () { fi } +# Generate message, patch and author script files make_patch () { parent_sha1=$(git rev-parse --verify "$1"^) || die "Cannot get patch for $1^" git diff-tree -p "$parent_sha1".."$1" > "$DOTEST"/patch test -f "$DOTEST"/message || - git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message + commit_message "$1" >"$DOTEST"/message test -f "$DOTEST"/author-script || get_author_ident_from_commit "$1" > "$DOTEST"/author-script } +# Generate a patch and die die_with_patch () { make_patch "$1" git rerere @@ -105,9 +112,9 @@ die_with_patch () { } cleanup_before_quit () { - for ref in $(git for-each-ref --format='%(refname)' "${mark_prefix%/}") + for ref in $(git for-each-ref --format='%(refname)' "$MARK_PREFIX") do - git update-ref -d "$ref" "$ref" || return 1 + git update-ref -d "$ref" "$ref" || return done rm -rf "$DOTEST" } @@ -118,7 +125,7 @@ die_abort () { } has_action () { - grep '^[^#]' "$1" >/dev/null + grep -q '^[^#]' "$1" } redo_merge () { @@ -126,7 +133,7 @@ redo_merge () { shift eval "$(get_author_ident_from_commit $rm_sha1)" - msg="$(git cat-file commit $rm_sha1 | sed -e '1,/^$/d')" + msg="$(commit_message "$rm_sha1")" if ! GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \ GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \ @@ -167,37 +174,39 @@ nth_string () { } make_squash_message () { - if test -f "$SQUASH_MSG"; then - COUNT=$(($(sed -n "s/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p" \ - < "$SQUASH_MSG" | sed -ne '$p')+1)) + if test -f "$SQUASH_MSG" + then + count="$(($(sed -n -e 's/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p' \ + "$SQUASH_MSG" | sed -n -e '$p')+1))" echo "# This is a combination of $COUNT commits." sed -e 1d -e '2,/^./{ /^$/d - }' <"$SQUASH_MSG" + }' "$SQUASH_MSG" else COUNT=2 echo "# This is a combination of two commits." echo "# The first commit's message is:" echo - git cat-file commit HEAD | sed -e '1,/^$/d' + commit_message HEAD fi echo echo "# This is the $(nth_string $COUNT) commit message:" echo - git cat-file commit $1 | sed -e '1,/^$/d' + commit_message "$1" } peek_next_command () { - sed -n "1s/ .*$//p" < "$TODO" + sed -n -e '1s/ .*$//p' "$TODO" } +# If $1 is a mark, make a ref from it; otherwise keep it mark_to_ref () { - if expr "$1" : "^:[0-9][0-9]*$" >/dev/null - then - echo "$mark_prefix$(printf %d ${1#:})" - else - echo "$1" - fi + arg="$1" + ref="$(expr "$arg" : '^:0*\([0-9]\+\)$')" + test -n "$ref" && + arg="$MARK_PREFIX/$ref" + printf '%s\n' "$arg" + unset arg ref } do_next () { @@ -634,7 +643,7 @@ do UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base" test -z "$ONTO" && ONTO=$UPSTREAM - if test ! -z "$2" + if test -n "$2" then output git show-ref --verify --quiet "refs/heads/$2" || die "Invalid branchname: $2" @@ -674,7 +683,7 @@ do create_extended_todo_list else git rev-list --no-merges --reverse --pretty=oneline \ - $common_rev_list_opts | sed -n "s/^>/pick /p" + $common_rev_list_opts | sed -n -e 's/^>/pick /p' fi > "$TODO" cat >> "$TODO" << EOF -- 1.5.5.1.561.gd8556 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html