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

[PATCH v2 1/2] contrib/hooks/post-receive-email: Put rev display in separate function

From
PHPete Harlan <pgit@pcharlan.com>
Date
Nov 4, 2008, 07:19 UTC
Message-ID
<1225783194-24640-2-git-send-email-pgit@pcharlan.com>
In-Reply-To
<1225783194-24640-1-git-send-email-pgit@pcharlan.com>

The display of a revision in an email-appropriate format is done in two places with similar code. In preparation for making that display more complex, move it into a separate function that handles both cases.

Signed-off-by: Pete Harlan <pgit@pcharlan.com>
---
 contrib/hooks/post-receive-email |   41 +++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 4136895..2cd373d 100644
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -224,13 +224,7 @@ generate_create_branch_email()
 	echo ""
 
 	echo $LOGBEGIN
-	# This shows all log entries that are not already covered by
-	# another ref - i.e. commits that are now accessible from this
-	# ref that were previously not accessible
-	# (see generate_update_branch_email for the explanation of this
-	# command)
-	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
-	git rev-list --pretty --stdin $newrev
+	show_new_revisions
 	echo $LOGEND
 }
 
@@ -390,8 +384,7 @@ generate_update_branch_email()
 
 		echo ""
 		echo $LOGBEGIN
-		git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
-		git rev-list --pretty --stdin $oldrev..$newrev
+		show_new_revisions
 
 		# XXX: Need a way of detecting whether git rev-list actually
 		# outputted anything, so that we can issue a "no new
@@ -591,6 +584,36 @@ generate_delete_general_email()
 	echo $LOGEND
 }
 
+
+# --------------- Miscellaneous utilities
+
+#
+# Show new revisions as the user would like to see them in the email.
+#
+show_new_revisions()
+{
+	# This shows all log entries that are not already covered by
+	# another ref - i.e. commits that are now accessible from this
+	# ref that were previously not accessible
+	# (see generate_update_branch_email for the explanation of this
+	# command)
+
+	# Revision range passed to rev-list differs for new vs. updated
+	# branches.
+	if [ "$change_type" = create ]
+	then
+		# Show all revisions exclusive to this (new) branch.
+		revspec=$newrev
+	else
+		# Branch update; show revisions not part of $oldrev.
+		revspec=$oldrev..$newrev
+	fi
+
+	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+	git rev-list --pretty --stdin $revspec
+}
+
+
 send_mail()
 {
 	if [ -n "$envelopesender" ]; then
-- 
1.6.0.3.533.ge0502
Previous: Pete HarlanNext: Pete Harlan
Message 2 of 4 in “post-receive-email configurable rev display”
  1. 0/2 post-receive-email configurable rev displayPete Harlan, Nov 4, 2008
  2. 1/2 contrib/hooks/post-receive-email: Put rev display in separate functionPete Harlan, Nov 4, 2008
  3. 2/2 contrib/hooks/post-receive-email: Make revision display configurablePete Harlan, Nov 4, 2008
  4. Junio C HamanoNov 4, 2008

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.