git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 12/18] rebase -i: Extract a function "commit_message"

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jan 14, 2010, 05:54 UTC
Message-ID
<846f72bfe9246c2ac1f776fa18bd7f75fa77292d.1263447038.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1263447037.git.mhagger@alum.mit.edu>

...instead of repeating the same short but slightly obscure blob of code in several places.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 git-rebase--interactive.sh |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5ed80b0..04a1c3a 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -120,6 +120,11 @@ output () {
 	esac
 }
 
+# Output the commit message for the specified commit.
+commit_message () {
+	git cat-file commit "$1" | sed "1,/^$/d"
+}
+
 run_pre_rebase_hook () {
 	if test -z "$OK_TO_SKIP_PRE_REBASE" &&
 	   test -x "$GIT_DIR/hooks/pre-rebase"
@@ -180,7 +185,7 @@ make_patch () {
 		;;
 	esac > "$DOTEST"/patch
 	test -f "$MSG" ||
-		git cat-file commit "$1" | sed "1,/^$/d" > "$MSG"
+		commit_message "$1" > "$MSG"
 	test -f "$AUTHOR_SCRIPT" ||
 		get_author_ident_from_commit "$1" > "$AUTHOR_SCRIPT"
 }
@@ -318,7 +323,7 @@ pick_one_preserving_merges () {
 			# redo merge
 			author_script=$(get_author_ident_from_commit $sha1)
 			eval "$author_script"
-			msg="$(git cat-file commit $sha1 | sed -e '1,/^$/d')"
+			msg="$(commit_message $sha1)"
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
@@ -363,20 +368,20 @@ make_squash_message () {
 		echo "# This is a combination of 2 commits."
 		echo "# The first commit's message is:"
 		echo
-		git cat-file commit HEAD | sed -e '1,/^$/d'
+		commit_message HEAD
 	fi
 	case $1 in
 	squash)
 		echo
 		echo "# This is the $(nth_string $COUNT) commit message:"
 		echo
-		git cat-file commit $2 | sed -e '1,/^$/d'
+		commit_message $2
 		;;
 	fixup)
 		echo
 		echo "# The $(nth_string $COUNT) commit message will be skipped:"
 		echo
-		git cat-file commit $2 | sed -e '1,/^$/d' -e 's/^/#	/'
+		commit_message $2 | sed -e 's/^/#	/'
 		;;
 	esac
 }
-- 
1.6.6
Previous: Michael HaggertyNext: Michael Haggerty
Message 25 of 34 in “rebase -i: For pure fixups, do not start log message editor”
  1. 00/18 rebase -i: For pure fixups, do not start log message editorMichael Haggerty, Jan 14, 2010
  2. 01/18 rebase -i: Make the condition for an "if" more transparentMichael Haggerty, Jan 14, 2010
  3. Eric BlakeJan 14, 2010
  4. Junio C HamanoJan 14, 2010
  5. Paolo BonziniJan 15, 2010
  6. Johannes SchindelinJan 25, 2010
  7. Michael HaggertyJan 26, 2010
  8. Johannes SchindelinJan 26, 2010
  9. 02/18 rebase -i: Remove dead codeMichael Haggerty, Jan 14, 2010
  10. 03/18 rebase -i: Inline expressionMichael Haggerty, Jan 14, 2010
  11. 04/18 rebase -i: Use "test -n" instead of "test ! -z"Michael Haggerty, Jan 14, 2010
  12. 05/18 rebase -i: Use symbolic constant $MSG consistentlyMichael Haggerty, Jan 14, 2010
  13. 06/18 rebase -i: Document how temporary files are usedMichael Haggerty, Jan 14, 2010
  14. Greg PriceJan 25, 2010
  15. 07/18 rebase -i: Introduce a constant AUTHOR_SCRIPTMichael Haggerty, Jan 14, 2010
  16. 08/18 rebase -i: Introduce a constant AMENDMichael Haggerty, Jan 14, 2010
  17. 09/18 t3404: Test the commit count in commit messages generated by "rebase -i"Michael Haggerty, Jan 14, 2010
  18. Johannes SixtJan 14, 2010
  19. Michael HaggertyJan 14, 2010
  20. Johannes SixtJan 14, 2010
  21. 10/18 rebase -i: Improve consistency of commit count in generated commit messagesMichael Haggerty, Jan 14, 2010
  22. Johannes SixtJan 14, 2010
  23. Michael HaggertyJan 14, 2010
  24. 11/18 rebase -i: Simplify commit counting for generated commit messagesMichael Haggerty, Jan 14, 2010
  25. 12/18 rebase -i: Extract a function "commit_message"Michael Haggerty, Jan 14, 2010
  26. 13/18 rebase -i: Handle the author script all in one place in do_nextMichael Haggerty, Jan 14, 2010
  27. 14/18 rebase -i: Extract function do_with_authorMichael Haggerty, Jan 14, 2010
  28. 15/18 rebase -i: Change function make_squash_message into update_squash_messageMichael Haggerty, Jan 14, 2010
  29. Johannes SixtJan 14, 2010
  30. 16/18 rebase -i: For fixup commands without squashes, do not start editorMichael Haggerty, Jan 14, 2010
  31. 17/18 t3404: Set up more of the test repo in the "setup" stepMichael Haggerty, Jan 14, 2010
  32. 18/18 rebase -i: Retain user-edited commit messages after squash/fixup conflictsMichael Haggerty, Jan 14, 2010
  33. Junio C HamanoJan 14, 2010
  34. Johannes SchindelinJan 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.