Why are we using a custom Git Commit hook

Reinhard Tartler siretart at tauware.de
Tue Sep 27 18:42:35 UTC 2011


Hi,

I noticed that our packages use a custom git-commit-hook that is
installed in /git/pkg-multimedia/git-commit-notice. However, I also
noticed that other teams seem to use /usr/local/bin/git-commit-notice. I
wonder why don't use the system wide one too. For reference see the diff
below:

--- /git/pkg-multimedia/git-commit-notice	2010-09-04 19:49:26.000000000 +0000
+++ /usr/local/bin/git-commit-notice	2011-05-23 10:26:34.116049606 +0000
@@ -138,22 +138,19 @@
 
 	# Check if we've got anyone to send to
 	if [ -z "$recipients" ]; then
-		echo >&2 "*** hooks.recipients is not set so no email will be sent"
+		echo >&2 "*** hooks.mailinglist is not set so no email will be sent"
 		echo >&2 "*** for $refname update $oldrev->$newrev"
 		exit 0
 	fi
 
 	# Email parameters
-	# For ease of mailing list management, we use the pusher's ID
-	# as committer
-	committer="$(id -un)@users.alioth.debian.org"
-	if [ -z "$committer" ] ; then
-		echo >&2 "Could not identify username, not sending email"
-		exit 1
-	fi
+	# The committer will be obtained from the latest existing rev; so
+	# for a deletion it will be the oldrev, for the others, then newrev
+	committer=$(git show --pretty=full -s $rev |
+		perl -M'Encode qw/encode/' -Mencoding=utf-8 -n -e 'print if (s{^Commit: (.*)( <.*>)}{encode("MIME-Q", "\"".$1."\"") . $2}e);')
 	# The email subject will contain the best description of the ref
 	# that we can build from the parameters
-	describe=$(git describe --tags $rev 2>/dev/null)
+	describe=$(git describe $rev 2>/dev/null)
 	if [ -z "$describe" ]; then
 		describe=$rev
 	fi
@@ -177,7 +174,6 @@
 		fi
 		for merged in $(git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --reverse --stdin $oldrev..$newrev); do
 
-			describe=$(git log --pretty=%s "$merged^..$merged")
 			generate_commit_log $merged | $sendmail
 
 			if [ -n "$cia_project" ]; then
@@ -204,8 +200,7 @@
 		echo "Reply-To: $reply_to"
 	fi
 	cat <<-EOF
-	Date: `date --rfc-2822`
-	Subject: ${EMAILPREFIX}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+	Subject: ${EMAILPREFIX}$subjectdesc $refname_type, $short_refname, ${change_type}d. $describe
 	MIME-Version: 1.0
 	Content-Type: text/plain; charset=UTF-8
 	X-Git-Refname: $refname
@@ -229,14 +224,8 @@
 generate_commit_log()
 {
 	rev=$1
-	# Again, use the pushers ID instead of committe
-	committer="$(id -un)@users.alioth.debian.org"
-
-	if [ "$GIT_DIR" = "." ] ; then
-		repo=$(basename $(pwd) .git)
-	else
-		repo=$(basename $GIT_DIR .git)
-	fi
+	committer=$(git show --pretty=full -s $rev | 
+		perl -M'Encode qw/encode/' -Mencoding=utf-8 -n -e 'print if (s{^Commit: (.*)( <.*>)}{encode("MIME-Q", "\"".$1."\"") . $2}e);')
 
 	cat <<-EOF
 	From: $committer
@@ -247,7 +236,7 @@
 		echo "Reply-To: $reply_to"
 	fi
 	cat <<-EOF
-	Subject: ${EMAILPREFIX}$repo/$short_refname: $describe
+	Subject: ${EMAILPREFIX}$subjectdesc $refname_type, $short_refname, ${change_type}d. $describe
 	MIME-Version: 1.0
 	Content-Type: text/plain; charset=UTF-8
 	X-Git-Refname: $refname
@@ -670,6 +659,11 @@
 envelopesender=$(git repo-config hooks.envelopesender)
 cia_project=$(git repo-config hooks.cia-project)
 sendmail="/usr/sbin/sendmail -t"
+subjectdesc=$(git repo-config hooks.subjectdesc)
+
+if [ -z "$subjectdesc" ]; then
+	subjectdesc=$projectdesc
+fi
 
 # --- Main loop
 # Allow dual mode: run from the command line just like the update hook, or if


-- 
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4



More information about the pkg-multimedia-maintainers mailing list