[Bps-public-commit] rt-extension-quickdelete branch, perlrewrite, created. fb973d01aeaaf29dd1df366d3275d40190073cd6
Kevin Falcone
falcone at bestpractical.com
Wed Mar 3 12:58:39 EST 2010
The branch, perlrewrite has been created
at fb973d01aeaaf29dd1df366d3275d40190073cd6 (commit)
- Log -----------------------------------------------------------------
commit fb973d01aeaaf29dd1df366d3275d40190073cd6
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Tue Sep 29 18:22:23 2009 -0400
snapshot
diff --git a/post-receive-email b/post-receive-email
index c86cdfc..f18f643 100755
--- a/post-receive-email
+++ b/post-receive-email
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env perl
#
# Copyright (c) 2007 Andy Parkins
#
@@ -66,42 +66,43 @@
# - generate_update_XXXX_email
# - generate_delete_XXXX_email
#
-generate_email()
-{
+use strict;
+use warnings;
+
+sub generate_email {
+ my ($oldrev, $newrev, $refname) = @_;
# --- Arguments
- oldrev=$(git rev-parse $1)
- newrev=$(git rev-parse $2)
- refname="$3"
+ $oldrev=`git rev-parse $oldrev`
+ $newrev=`git rev-parse $refname`
# --- Interpret
# 0000->1234 (create)
# 1234->2345 (update)
# 2345->0000 (delete)
- if expr "$oldrev" : '0*$' >/dev/null
- then
- change_type="create"
- else
- if expr "$newrev" : '0*$' >/dev/null
- then
- change_type="delete"
- else
- change_type="update"
- fi
- fi
+
+ my $change_type;
+ if ($oldrev =~ /^0*$/) {
+ $change_type="create";
+ } else {
+ if ($newrev =~ /^0*$/) {
+ $change_type="delete";
+ } else {
+ $change_type="update";
+ }
+ }
# --- Get the revision types
- newrev_type=$(git cat-file -t $newrev 2> /dev/null)
- oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
+ $newrev_type=`git cat-file -t $newrev 2> /dev/null`
+ $oldrev_type=`git cat-file -t "$oldrev" 2> /dev/null`
case "$change_type" in
- create|update)
- rev="$newrev"
- rev_type="$newrev_type"
- ;;
- delete)
- rev="$oldrev"
- rev_type="$oldrev_type"
- ;;
- esac
+ my ($rev, $rev_type);
+ if ($change_type =~ /^(?:create|update)$/) {
+ $rev=$newrev;
+ $rev_type=$newrev_type;
+ } elsif ( $change_type eq 'delete' ) {
+ $rev= $oldrev;
+ $rev_type= $oldrev_type;
+ }
# The revision type tells us what type the commit is, combined with
# the location of the ref we can decide between
@@ -109,95 +110,83 @@ generate_email()
# - tracking branch
# - unannoted tag
# - annotated tag
- case "$refname","$rev_type" in
- refs/tags/*,commit)
+ if ($refname =~ |refs/tags/(.*)|) {
+ if ($rev_type eq 'commit') {
# un-annotated tag
- refname_type="tag"
- short_refname=${refname##refs/tags/}
- ;;
- refs/tags/*,tag)
- # annotated tag
- refname_type="annotated tag"
- short_refname=${refname##refs/tags/}
+ $refname_type="tag";
+ $short_refname=$1;
+ } elsif ($rev_type eq 'tag') {
+ $refname_type="annotated tag";
+ $short_refname=$1;
# change recipients
- if [ -n "$announcerecipients" ]; then
- recipients="$announcerecipients"
- fi
- ;;
- refs/heads/*,commit)
- # branch
- refname_type="branch"
- short_refname=${refname##refs/heads/}
- ;;
- refs/remotes/*,commit)
+ if ($announcerecipients) {
+ $recipients="$announcerecipients";
+ }
+ }
+ } elsif ($refname =~ |refs/heads/(.*)| && $rev_type eq 'commit' ) {
+ $refname_type="branch";
+ $short_refname=$1;
+ } elsif ($refname =~ |refs/removes/(.*)| && $rev_type eq 'commit' ) {
# tracking branch
- refname_type="tracking branch"
- short_refname=${refname##refs/remotes/}
- echo >&2 "*** Push-update of tracking branch, $refname"
- echo >&2 "*** - no email generated."
- exit 0
- ;;
- *)
- # Anything else (is there anything else?)
- echo >&2 "*** Unknown type of update to $refname ($rev_type)"
- echo >&2 "*** - no email generated"
- exit 1
- ;;
- esac
+ $refname_type="tracking branch";
+ $short_refname=$1;
+ warn "*** Push-update of tracking branch, $refname";
+ warn "*** - no email generated.";
+ exit 0;
+ } else {
+ # Anything else (is there anything else?)
+ warn "*** Unknown type of update to $refname ($rev_type)"
+ warn "*** - no email generated"
+ exit 1
+ }
# Check if we've got anyone to send to
- if [ -z "$recipients" ]; then
- case "$refname_type" in
- "annotated tag")
- config_name="hooks.announcelist"
- ;;
- *)
- config_name="hooks.mailinglist"
- ;;
+ unless ($recipients) {
+ my $config_name;
+ if ($refname_type eq 'annotated tag') {
+ $config_name="hooks.announcelist";
+ } else {
+ $config_name="hooks.mailinglist";
esac
- echo >&2 "*** $config_name is not set so no email will be sent"
- echo >&2 "*** for $refname update $oldrev->$newrev"
- exit 0
- fi
+ warn "*** $config_name is not set so no email will be sent";
+ warn "*** for $refname update $oldrev->$newrev";
+ exit 0;
+ }
# Email parameters
# The email subject will contain the best description of the ref
# that we can build from the parameters
- describe=$(git describe $rev 2>/dev/null)
- if [ -z "$describe" ]; then
- describe=$rev
- fi
+ my $describe=`git describe $rev 2>/dev/null`
+ unless ($describe) {
+ $describe=$rev
+ }
- generate_email_header
+ generate_email_header();
# Call the correct body generation function
- fn_name=general
- case "$refname_type" in
- "tracking branch"|branch)
- fn_name=branch
- ;;
- "annotated tag")
- fn_name=atag
- ;;
- esac
- generate_${change_type}_${fn_name}_email
+ $fn_name="general";
+ if ( $refname_type =~ /^(:tracking branch|branch)$/ ) {
+ $fn_name="branch";
+ } elsif ( $refname_type eq "annotated tag" ) {
+ $fn_name="atag";
+ }
+ &{"generate_${change_type}_${fn_name}_email"};
}
-generate_email_header()
-{
+sub generate_email_header {
# --- Email (all stdout will be the email)
# Generate header
- cat <<-EOF
- To: $recipients
- Subject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
- X-Git-Refname: $refname
- X-Git-Reftype: $refname_type
- X-Git-Oldrev: $oldrev
- X-Git-Newrev: $newrev
-
- The $refname_type, $short_refname has been ${change_type}d
- EOF
+ print <<ENDOFHEADERS;
+To: $recipients
+Subject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+X-Git-Refname: $refname
+X-Git-Reftype: $refname_type
+X-Git-Oldrev: $oldrev
+X-Git-Newrev: $newrev
+
+The $refname_type, $short_refname has been ${change_type}d
+ENDOFHEADERS
}
# --------------- Branches
@@ -205,22 +194,19 @@ generate_email_header()
#
# Called for the creation of a branch
#
-generate_create_branch_email()
-{
+sub generate_create_branch_email {
# This is a new branch and so oldrev is not valid
- echo " at $newrev ($newrev_type)"
- echo ""
+ print " at $newrev ($newrev_type)\n";
- echo $LOGBEGIN
- show_new_revisions
- echo $LOGEND
+ print $LOGBEGIN;
+ show_new_revisions();
+ print $LOGEND;
}
#
# Called for the change of a pre-existing branch
#
-generate_update_branch_email()
-{
+sub generate_update_branch_email {
# Consider this:
# 1 --- 2 --- O --- X --- 3 --- 4 --- N
#
@@ -257,7 +243,7 @@ generate_update_branch_email()
# all of our commits. What we really want is to exclude the current
# value of $refname from the --not list, rather than N itself. So:
#
- # git rev-parse --not --all | grep -v $(git rev-parse $refname)
+ # git rev-parse --not --all | grep -v `git rev-parse $refname`
#
# Get's us to something pretty safe (apart from the small time
# between refname being read, and git rev-parse running - for that,
@@ -296,11 +282,11 @@ generate_update_branch_email()
# fast forward update, this list will be empty, because rev-list O
# ^N is empty. For a non fast forward, O ^N is the list of removed
# revisions
- fast_forward=""
- rev=""
- for rev in $(git rev-list $newrev..$oldrev)
+ my $fast_forward=""
+ my $rev=""
+ for rev in `git rev-list $newrev..$oldrev`
do
- revtype=$(git cat-file -t "$rev")
+ revtype=`git cat-file -t "$rev"`
echo " discards $rev ($revtype)"
done
if [ -z "$rev" ]; then
@@ -312,9 +298,9 @@ generate_update_branch_email()
# have already had notification emails and is present to show the
# full detail of the change from rolling back the old revision to
# the base revision and then forward to the new revision
- for rev in $(git rev-list $oldrev..$newrev)
+ for rev in `git rev-list $oldrev..$newrev`
do
- revtype=$(git cat-file -t "$rev")
+ revtype=`git cat-file -t "$rev"`
echo " via $rev ($revtype)"
done
@@ -335,7 +321,7 @@ generate_update_branch_email()
# Find the common ancestor of the old and new revisions and
# compare it with newrev
- baserev=$(git merge-base $oldrev $newrev)
+ baserev=`git merge-base $oldrev $newrev`
rewind_only=""
if [ "$baserev" = "$newrev" ]; then
echo "This update discarded existing revisions and left the branch pointing at"
@@ -448,14 +434,14 @@ generate_atag_email()
# If the tagged object is a commit, then we assume this is a
# release, and so we calculate which tag this tag is
# replacing
- prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
+ prevtag=`git describe --abbrev=0 $newrev^ 2>/dev/null`
if [ -n "$prevtag" ]; then
echo " replaces $prevtag"
fi
;;
*)
- echo " length $(git cat-file -s $tagobject) bytes"
+ echo " length `git cat-file -s $tagobject` bytes"
;;
esac
echo " tagged by $tagger"
@@ -552,7 +538,7 @@ generate_general_email()
# a commit, so there is no log for us to display. It's
# probably not wise to output git cat-file as it could be a
# binary blob. We'll just say how big it is
- echo "$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long."
+ echo "$newrev is a $newrev_type, and is `git cat-file -s $newrev` bytes long."
fi
}
@@ -593,7 +579,7 @@ show_new_revisions()
revspec=$oldrev..$newrev
fi
- git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+ git rev-parse --not --branches | grep -v `git rev-parse $refname` |
if [ -z "$custom_showrev" ]
then
git rev-list --pretty --stdin $revspec
@@ -601,63 +587,62 @@ show_new_revisions()
git rev-list --stdin --reverse $revspec |
while read onerev
do
- eval $(printf "$custom_showrev" $onerev)
+ eval `printf "$custom_showrev" $onerev`
done
fi
}
-send_mail()
-{
+sub send_mail {
if [ -n "$envelopesender" ]; then
- /usr/sbin/sendmail -t -f "$envelopesender"
+ `/usr/sbin/sendmail -t -f "$envelopesender"`
else
- /usr/sbin/sendmail -t
+ `/usr/sbin/sendmail -t`
fi
}
# ---------------------------- main()
# --- Constants
-LOGBEGIN="- Log -----------------------------------------------------------------"
-LOGEND="-----------------------------------------------------------------------"
+our $LOGBEGIN="- Log -----------------------------------------------------------------"
+our $LOGEND="-----------------------------------------------------------------------"
# --- Config
# Set GIT_DIR either from the working directory, or from the environment
# variable.
-GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
-if [ -z "$GIT_DIR" ]; then
- echo >&2 "fatal: post-receive: GIT_DIR not set"
+our $GIT_DIR=`git rev-parse --git-dir 2>/dev/null`
+unless ( $GIT_DIR ) {
+ warn "fatal: post-receive: GIT_DIR not set";
exit 1
-fi
+}
# Remove the one-line synopsis of the project, leaving just its name
-projectdesc=$(sed -ne 's/ - .*//; s/: .*//; 1p' "$GIT_DIR/description")
+$projectdesc=`sed -ne 's/ - .*//; s/: .*//; 1p' "$GIT_DIR/description"`
# Check if the description is unchanged from it's default, and shorten it to
# a more manageable length if it is
-if expr "$projectdesc" : "Unnamed repository.*$" >/dev/null
-then
- projectdesc="UNNAMED PROJECT"
-fi
+if ($projectdesc =~ /Unnamed repository.*$/) {
+ $projectdesc="UNNAMED PROJECT"
+}
-recipients=$(git config hooks.mailinglist)
-announcerecipients=$(git config hooks.announcelist)
-envelopesender=$(git config hooks.envelopesender)
-emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
-custom_showrev=$(git config hooks.showrev)
+our $recipients=`git config hooks.mailinglist`
+our $announcerecipients=`git config hooks.announcelist`
+our $envelopesender=`git config hooks.envelopesender`
+our $emailprefix=`git config hooks.emailprefix || echo '[SCM] '`
+our $custom_showrev=`git config hooks.showrev`
# --- Main loop
# Allow dual mode: run from the command line just like the update hook, or
# if no arguments are given then run as a hook script
-if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
+if ($ARGV[0] && $ARGV[1] && $ARGV[2]) {
# Output to the terminal in command line mode - if someone wanted to
# resend an email; they could redirect the output to sendmail
# themselves
- PAGER= generate_email $2 $3 $1
-else
- while read oldrev newrev refname
- do
- generate_email $oldrev $newrev $refname | send_mail
- done
-fi
+ generate_email($ARGS[1] $ARGV[2] $$ARGV[0]);
+} else {
+ while (my $pack = <STDIN>) {
+ chomp($pack);
+ my ($oldrev,$newrev,$refname) = split(/ /,$pack,3);
+ generate_email($oldrev $newrev $refname);#| send_mail
+ }
+}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list