contrib/hooks/post-receive-email: reformat to wrap comments at 76 chars

Signed-off-by: Gerrit Pape <pape@smarden.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Gerrit Pape 2007-11-06 13:48:34 +00:00 committed by Junio C Hamano
parent b5786c8283
commit 15a2f53011

View File

@ -2,24 +2,26 @@
# #
# Copyright (c) 2007 Andy Parkins # Copyright (c) 2007 Andy Parkins
# #
# An example hook script to mail out commit update information. This hook sends emails # An example hook script to mail out commit update information. This hook
# listing new revisions to the repository introduced by the change being reported. The # sends emails listing new revisions to the repository introduced by the
# rule is that (for branch updates) each commit will appear on one email and one email # change being reported. The rule is that (for branch updates) each commit
# only. # will appear on one email and one email only.
# #
# This hook is stored in the contrib/hooks directory. Your distribution will have put # This hook is stored in the contrib/hooks directory. Your distribution
# this somewhere standard. You should make this script executable then link to it in # will have put this somewhere standard. You should make this script
# the repository you would like to use it in. For example, on debian the hook is stored # executable then link to it in the repository you would like to use it in.
# in /usr/share/doc/git-core/contrib/hooks/post-receive-email: # For example, on debian the hook is stored in
# /usr/share/doc/git-core/contrib/hooks/post-receive-email:
# #
# chmod a+x post-receive-email # chmod a+x post-receive-email
# cd /path/to/your/repository.git # cd /path/to/your/repository.git
# ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email hooks/post-receive # ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email hooks/post-receive
# #
# This hook script assumes it is enabled on the central repository of a project, with # This hook script assumes it is enabled on the central repository of a
# all users pushing only to it and not between each other. It will still work if you # project, with all users pushing only to it and not between each other. It
# don't operate in that style, but it would become possible for the email to be from # will still work if you don't operate in that style, but it would become
# someone other than the person doing the push. # possible for the email to be from someone other than the person doing the
# push.
# #
# Config # Config
# ------ # ------
@ -28,11 +30,11 @@
# emails for every ref update. # emails for every ref update.
# hooks.announcelist # hooks.announcelist
# This is the list that all pushes of annotated tags will go to. Leave it # This is the list that all pushes of annotated tags will go to. Leave it
# blank to default to the mailinglist field. The announce emails lists the # blank to default to the mailinglist field. The announce emails lists
# short log summary of the changes since the last annotated tag. # the short log summary of the changes since the last annotated tag.
# hooks.envelopesender # hooks.envelopesender
# If set then the -f option is passed to sendmail to allow the envelope sender # If set then the -f option is passed to sendmail to allow the envelope
# address to be set # sender address to be set
# #
# Notes # Notes
# ----- # -----
@ -49,8 +51,8 @@
# this is and calls the appropriate body-generation routine after outputting # this is and calls the appropriate body-generation routine after outputting
# the common header # the common header
# #
# Note this function doesn't actually generate any email output, that is taken # Note this function doesn't actually generate any email output, that is
# care of by the functions it calls: # taken care of by the functions it calls:
# - generate_email_header # - generate_email_header
# - generate_create_XXXX_email # - generate_create_XXXX_email
# - generate_update_XXXX_email # - generate_update_XXXX_email
@ -225,8 +227,9 @@ generate_create_branch_email()
echo $LOGBEGIN echo $LOGBEGIN
# This shows all log entries that are not already covered by # This shows all log entries that are not already covered by
# another ref - i.e. commits that are now accessible from this # another ref - i.e. commits that are now accessible from this
# ref that were previously not accessible (see generate_update_branch_email # ref that were previously not accessible
# for the explanation of this command) # (see generate_update_branch_email for the explanation of this
# command)
git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
git rev-list --pretty --stdin $newrev git rev-list --pretty --stdin $newrev
echo $LOGEND echo $LOGEND
@ -254,9 +257,10 @@ generate_update_branch_email()
# #
# git-rev-list N ^O ^X ^N # git-rev-list N ^O ^X ^N
# #
# So, we need to build up the list more carefully. git-rev-parse will # So, we need to build up the list more carefully. git-rev-parse
# generate a list of revs that may be fed into git-rev-list. We can get # will generate a list of revs that may be fed into git-rev-list.
# it to make the "--not --all" part and then filter out the "^N" with: # We can get it to make the "--not --all" part and then filter out
# the "^N" with:
# #
# git-rev-parse --not --all | grep -v N # git-rev-parse --not --all | grep -v N
# #
@ -266,16 +270,17 @@ generate_update_branch_email()
# git-rev-list N ^O ^X # git-rev-list N ^O ^X
# #
# This leaves a problem when someone else updates the repository # This leaves a problem when someone else updates the repository
# while this script is running. Their new value of the ref we're working # while this script is running. Their new value of the ref we're
# on would be included in the "--not --all" output; and as our $newrev # working on would be included in the "--not --all" output; and as
# would be an ancestor of that commit, it would exclude all of our # our $newrev would be an ancestor of that commit, it would exclude
# commits. What we really want is to exclude the current value of # all of our commits. What we really want is to exclude the current
# $refname from the --not list, rather than N itself. So: # 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 # Get's us to something pretty safe (apart from the small time
# refname being read, and git-rev-parse running - for that, I give up) # between refname being read, and git-rev-parse running - for that,
# I give up)
# #
# #
# Next problem, consider this: # Next problem, consider this:
@ -283,18 +288,18 @@ generate_update_branch_email()
# \ # \
# * --- X --- * --- N ($newrev) # * --- X --- * --- N ($newrev)
# #
# That is to say, there is no guarantee that oldrev is a strict subset of # That is to say, there is no guarantee that oldrev is a strict
# newrev (it would have required a --force, but that's allowed). So, we # subset of newrev (it would have required a --force, but that's
# can't simply say rev-list $oldrev..$newrev. Instead we find the common # allowed). So, we can't simply say rev-list $oldrev..$newrev.
# base of the two revs and list from there. # Instead we find the common base of the two revs and list from
# there.
# #
# As above, we need to take into account the presence of X; if another # As above, we need to take into account the presence of X; if
# branch is already in the repository and points at some of the revisions # another branch is already in the repository and points at some of
# that we are about to output - we don't want them. The solution is as # the revisions that we are about to output - we don't want them.
# before: git-rev-parse output filtered. # The solution is as before: git-rev-parse output filtered.
# #
# Finally, tags: # Finally, tags: 1 --- 2 --- O --- T --- 3 --- 4 --- N
# 1 --- 2 --- O --- T --- 3 --- 4 --- N
# #
# Tags pushed into the repository generate nice shortlog emails that # Tags pushed into the repository generate nice shortlog emails that
# summarise the commits between them and the previous tag. However, # summarise the commits between them and the previous tag. However,
@ -302,13 +307,14 @@ generate_update_branch_email()
# for a branch update. Therefore we still want to output revisions # for a branch update. Therefore we still want to output revisions
# that have been output on a tag email. # that have been output on a tag email.
# #
# Luckily, git-rev-parse includes just the tool. Instead of using "--all" # Luckily, git-rev-parse includes just the tool. Instead of using
# we use "--branches"; this has the added benefit that "remotes/" will # "--all" we use "--branches"; this has the added benefit that
# be ignored as well. # "remotes/" will be ignored as well.
# List all of the revisions that were removed by this update, in a fast forward # List all of the revisions that were removed by this update, in a
# update, this list will be empty, because rev-list O ^N is empty. For a non # fast forward update, this list will be empty, because rev-list O
# fast forward, O ^N is the list of removed revisions # ^N is empty. For a non fast forward, O ^N is the list of removed
# revisions
fast_forward="" fast_forward=""
rev="" rev=""
for rev in $(git rev-list $newrev..$oldrev) for rev in $(git rev-list $newrev..$oldrev)
@ -321,10 +327,10 @@ generate_update_branch_email()
fi fi
# List all the revisions from baserev to newrev in a kind of # List all the revisions from baserev to newrev in a kind of
# "table-of-contents"; note this list can include revisions that have # "table-of-contents"; note this list can include revisions that
# already had notification emails and is present to show the full detail # have already had notification emails and is present to show the
# of the change from rolling back the old revision to the base revision and # full detail of the change from rolling back the old revision to
# then forward to the new revision # 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 do
revtype=$(git cat-file -t "$rev") revtype=$(git cat-file -t "$rev")
@ -334,19 +340,20 @@ generate_update_branch_email()
if [ "$fast_forward" ]; then if [ "$fast_forward" ]; then
echo " from $oldrev ($oldrev_type)" echo " from $oldrev ($oldrev_type)"
else else
# 1. Existing revisions were removed. In this case newrev is a # 1. Existing revisions were removed. In this case newrev
# subset of oldrev - this is the reverse of a fast-forward, # is a subset of oldrev - this is the reverse of a
# a rewind # fast-forward, a rewind
# 2. New revisions were added on top of an old revision, this is # 2. New revisions were added on top of an old revision,
# a rewind and addition. # this is a rewind and addition.
# (1) certainly happened, (2) possibly. When (2) hasn't happened, # (1) certainly happened, (2) possibly. When (2) hasn't
# we set a flag to indicate that no log printout is required. # happened, we set a flag to indicate that no log printout
# is required.
echo "" echo ""
# Find the common ancestor of the old and new revisions and compare # Find the common ancestor of the old and new revisions and
# it with newrev # compare it with newrev
baserev=$(git merge-base $oldrev $newrev) baserev=$(git merge-base $oldrev $newrev)
rewind_only="" rewind_only=""
if [ "$baserev" = "$newrev" ]; then if [ "$baserev" = "$newrev" ]; then
@ -387,21 +394,22 @@ generate_update_branch_email()
git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
git rev-list --pretty --stdin $oldrev..$newrev git rev-list --pretty --stdin $oldrev..$newrev
# XXX: Need a way of detecting whether git rev-list actually outputted # XXX: Need a way of detecting whether git rev-list actually
# anything, so that we can issue a "no new revisions added by this # outputted anything, so that we can issue a "no new
# update" message # revisions added by this update" message
echo $LOGEND echo $LOGEND
else else
echo "No new revisions were added by this update." echo "No new revisions were added by this update."
fi fi
# The diffstat is shown from the old revision to the new revision. This # The diffstat is shown from the old revision to the new revision.
# is to show the truth of what happened in this change. There's no point # This is to show the truth of what happened in this change.
# showing the stat from the base to the new revision because the base # There's no point showing the stat from the base to the new
# is effectively a random revision at this point - the user will be # revision because the base is effectively a random revision at this
# interested in what this revision changed - including the undoing of # point - the user will be interested in what this revision changed
# previous revisions in the case of non-fast forward updates. # - including the undoing of previous revisions in the case of
# non-fast forward updates.
echo "" echo ""
echo "Summary of changes:" echo "Summary of changes:"
git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
@ -448,7 +456,8 @@ generate_update_atag_email()
# #
generate_atag_email() generate_atag_email()
{ {
# Use git-for-each-ref to pull out the individual fields from the tag # Use git-for-each-ref to pull out the individual fields from the
# tag
eval $(git for-each-ref --shell --format=' eval $(git for-each-ref --shell --format='
tagobject=%(*objectname) tagobject=%(*objectname)
tagtype=%(*objecttype) tagtype=%(*objecttype)
@ -459,8 +468,10 @@ generate_atag_email()
echo " tagging $tagobject ($tagtype)" echo " tagging $tagobject ($tagtype)"
case "$tagtype" in case "$tagtype" in
commit) commit)
# If the tagged object is a commit, then we assume this is a # If the tagged object is a commit, then we assume this is a
# release, and so we calculate which tag this tag is replacing # 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 if [ -n "$prevtag" ]; then
@ -477,25 +488,27 @@ generate_atag_email()
echo "" echo ""
echo $LOGBEGIN echo $LOGBEGIN
# Show the content of the tag message; this might contain a change log # Show the content of the tag message; this might contain a change
# or release notes so is worth displaying. # log or release notes so is worth displaying.
git cat-file tag $newrev | sed -e '1,/^$/d' git cat-file tag $newrev | sed -e '1,/^$/d'
echo "" echo ""
case "$tagtype" in case "$tagtype" in
commit) commit)
# Only commit tags make sense to have rev-list operations performed # Only commit tags make sense to have rev-list operations
# on them # performed on them
if [ -n "$prevtag" ]; then if [ -n "$prevtag" ]; then
# Show changes since the previous release # Show changes since the previous release
git rev-list --pretty=short "$prevtag..$newrev" | git shortlog git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
else else
# No previous tag, show all the changes since time began # No previous tag, show all the changes since time
# began
git rev-list --pretty=short $newrev | git shortlog git rev-list --pretty=short $newrev | git shortlog
fi fi
;; ;;
*) *)
# XXX: Is there anything useful we can do for non-commit objects? # XXX: Is there anything useful we can do for non-commit
# objects?
;; ;;
esac esac
@ -544,13 +557,14 @@ generate_update_general_email()
# #
generate_general_email() generate_general_email()
{ {
# Unannotated tags are more about marking a point than releasing a version; # Unannotated tags are more about marking a point than releasing a
# therefore we don't do the shortlog summary that we do for annotated tags # version; therefore we don't do the shortlog summary that we do for
# above - we simply show that the point has been marked, and print the log # annotated tags above - we simply show that the point has been
# message for the marked point for reference purposes # marked, and print the log message for the marked point for
# reference purposes
# #
# Note this section also catches any other reference type (although there # Note this section also catches any other reference type (although
# aren't any) and deals with them in the same way. # there aren't any) and deals with them in the same way.
echo "" echo ""
if [ "$newrev_type" = "commit" ]; then if [ "$newrev_type" = "commit" ]; then
@ -558,10 +572,10 @@ generate_general_email()
git show --no-color --root -s $newrev git show --no-color --root -s $newrev
echo $LOGEND echo $LOGEND
else else
# What can we do here? The tag marks an object that is not a commit, # What can we do here? The tag marks an object that is not
# so there is no log for us to display. It's probably not wise to # a commit, so there is no log for us to display. It's
# output git-cat-file as it could be a binary blob. We'll just say how # probably not wise to output git-cat-file as it could be a
# big it is # 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 fi
} }
@ -604,8 +618,8 @@ if [ -z "$GIT_DIR" ]; then
fi fi
projectdesc=$(sed -ne '1p' "$GIT_DIR/description") projectdesc=$(sed -ne '1p' "$GIT_DIR/description")
# Check if the description is unchanged from it's default, and shorten it to a # Check if the description is unchanged from it's default, and shorten it to
# more manageable length if it is # a more manageable length if it is
if expr "$projectdesc" : "Unnamed repository.*$" >/dev/null if expr "$projectdesc" : "Unnamed repository.*$" >/dev/null
then then
projectdesc="UNNAMED PROJECT" projectdesc="UNNAMED PROJECT"
@ -616,11 +630,12 @@ announcerecipients=$(git repo-config hooks.announcelist)
envelopesender=$(git-repo-config hooks.envelopesender) envelopesender=$(git-repo-config hooks.envelopesender)
# --- Main loop # --- Main loop
# Allow dual mode: run from the command line just like the update hook, or if # Allow dual mode: run from the command line just like the update hook, or
# no arguments are given then run as a hook script # if no arguments are given then run as a hook script
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
# Output to the terminal in command line mode - if someone wanted to # Output to the terminal in command line mode - if someone wanted to
# resend an email; they could redirect the output to sendmail themselves # resend an email; they could redirect the output to sendmail
# themselves
PAGER= generate_email $2 $3 $1 PAGER= generate_email $2 $3 $1
else else
while read oldrev newrev refname while read oldrev newrev refname