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>
Gerrit Pape committed
Nov 6, 2007 at 13:48 UTC
15a2f530111f32d66eb0c25527e540b5e09804ad
1 file changed
+107
-92
contrib/hooks/post-receive-email
+107
-92
@@ -2,24 +2,26 @@
2
#
3
# Copyright (c) 2007 Andy Parkins
4
#
5
-# An example hook script to mail out commit update information. This hook sends emails
6
-# listing new revisions to the repository introduced by the change being reported. The
7
-# rule is that (for branch updates) each commit will appear on one email and one email
8
-# only.
5
+# An example hook script to mail out commit update information. This hook
6
+# sends emails listing new revisions to the repository introduced by the
7
+# change being reported. The rule is that (for branch updates) each commit
8
+# will appear on one email and one email only.
9
#
10
-# This hook is stored in the contrib/hooks directory. Your distribution will have put
11
-# this somewhere standard. You should make this script executable then link to it in
12
-# the repository you would like to use it in. For example, on debian the hook is stored
13
-# in /usr/share/doc/git-core/contrib/hooks/post-receive-email:
10
+# This hook is stored in the contrib/hooks directory. Your distribution
11
+# will have put this somewhere standard. You should make this script
12
+# executable then link to it in the repository you would like to use it in.
13
+# For example, on debian the hook is stored in
14
+# /usr/share/doc/git-core/contrib/hooks/post-receive-email:
15
#
16
# chmod a+x post-receive-email
17
# cd /path/to/your/repository.git
18
# ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email hooks/post-receive
19
#
19
-# This hook script assumes it is enabled on the central repository of a project, with
20
-# all users pushing only to it and not between each other. It will still work if you
21
-# don't operate in that style, but it would become possible for the email to be from
22
-# someone other than the person doing the push.
20
+# This hook script assumes it is enabled on the central repository of a
21
+# project, with all users pushing only to it and not between each other. It
22
+# will still work if you don't operate in that style, but it would become
23
+# possible for the email to be from someone other than the person doing the
24
+# push.
25
#
26
# Config
27
# ------
@@ -28,11 +30,11 @@
30
# emails for every ref update.
31
# hooks.announcelist
32
# This is the list that all pushes of annotated tags will go to. Leave it
31
-# blank to default to the mailinglist field. The announce emails lists the
32
-# short log summary of the changes since the last annotated tag.
33
+# blank to default to the mailinglist field. The announce emails lists
34
+# the short log summary of the changes since the last annotated tag.
35
# hooks.envelopesender
34
-# If set then the -f option is passed to sendmail to allow the envelope sender
35
-# address to be set
36
+# If set then the -f option is passed to sendmail to allow the envelope
37
+# sender address to be set
38
#
39
# Notes
40
# -----
@@ -49,8 +51,8 @@
51
# this is and calls the appropriate body-generation routine after outputting
52
# the common header
53
#
52
-# Note this function doesn't actually generate any email output, that is taken
53
-# care of by the functions it calls:
54
+# Note this function doesn't actually generate any email output, that is
55
+# taken care of by the functions it calls:
56
# - generate_email_header
57
# - generate_create_XXXX_email
58
# - generate_update_XXXX_email
@@ -225,8 +227,9 @@ generate_create_branch_email()
227
echo $LOGBEGIN
228
# This shows all log entries that are not already covered by
229
# another ref - i.e. commits that are now accessible from this
228
- # ref that were previously not accessible (see generate_update_branch_email
229
- # for the explanation of this command)
230
+ # ref that were previously not accessible
231
+ # (see generate_update_branch_email for the explanation of this
232
+ # command)
233
git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
234
git rev-list --pretty --stdin $newrev
235
echo $LOGEND
@@ -254,9 +257,10 @@ generate_update_branch_email()
257
#
258
# git-rev-list N ^O ^X ^N
259
#
257
- # So, we need to build up the list more carefully. git-rev-parse will
258
- # generate a list of revs that may be fed into git-rev-list. We can get
259
- # it to make the "--not --all" part and then filter out the "^N" with:
260
+ # So, we need to build up the list more carefully. git-rev-parse
261
+ # will generate a list of revs that may be fed into git-rev-list.
262
+ # We can get it to make the "--not --all" part and then filter out
263
+ # the "^N" with:
264
#
265
# git-rev-parse --not --all | grep -v N
266
#
@@ -266,16 +270,17 @@ generate_update_branch_email()
270
# git-rev-list N ^O ^X
271
#
272
# This leaves a problem when someone else updates the repository
269
- # while this script is running. Their new value of the ref we're working
270
- # on would be included in the "--not --all" output; and as our $newrev
271
- # would be an ancestor of that commit, it would exclude all of our
272
- # commits. What we really want is to exclude the current value of
273
- # $refname from the --not list, rather than N itself. So:
273
+ # while this script is running. Their new value of the ref we're
274
+ # working on would be included in the "--not --all" output; and as
275
+ # our $newrev would be an ancestor of that commit, it would exclude
276
+ # all of our commits. What we really want is to exclude the current
277
+ # value of $refname from the --not list, rather than N itself. So:
278
#
279
# git-rev-parse --not --all | grep -v $(git-rev-parse $refname)
280
#
277
- # Get's us to something pretty safe (apart from the small time between
278
- # refname being read, and git-rev-parse running - for that, I give up)
281
+ # Get's us to something pretty safe (apart from the small time
282
+ # between refname being read, and git-rev-parse running - for that,
283
+ # I give up)
284
#
285
#
286
# Next problem, consider this:
@@ -283,18 +288,18 @@ generate_update_branch_email()
288
# \
289
# * --- X --- * --- N ($newrev)
290
#
286
- # That is to say, there is no guarantee that oldrev is a strict subset of
287
- # newrev (it would have required a --force, but that's allowed). So, we
288
- # can't simply say rev-list $oldrev..$newrev. Instead we find the common
289
- # base of the two revs and list from there.
291
+ # That is to say, there is no guarantee that oldrev is a strict
292
+ # subset of newrev (it would have required a --force, but that's
293
+ # allowed). So, we can't simply say rev-list $oldrev..$newrev.
294
+ # Instead we find the common base of the two revs and list from
295
+ # there.
296
#
291
- # As above, we need to take into account the presence of X; if another
292
- # branch is already in the repository and points at some of the revisions
293
- # that we are about to output - we don't want them. The solution is as
294
- # before: git-rev-parse output filtered.
297
+ # As above, we need to take into account the presence of X; if
298
+ # another branch is already in the repository and points at some of
299
+ # the revisions that we are about to output - we don't want them.
300
+ # The solution is as before: git-rev-parse output filtered.
301
#
296
- # Finally, tags:
297
- # 1 --- 2 --- O --- T --- 3 --- 4 --- N
302
+ # Finally, tags: 1 --- 2 --- O --- T --- 3 --- 4 --- N
303
#
304
# Tags pushed into the repository generate nice shortlog emails that
305
# summarise the commits between them and the previous tag. However,
@@ -302,13 +307,14 @@ generate_update_branch_email()
307
# for a branch update. Therefore we still want to output revisions
308
# that have been output on a tag email.
309
#
305
- # Luckily, git-rev-parse includes just the tool. Instead of using "--all"
306
- # we use "--branches"; this has the added benefit that "remotes/" will
307
- # be ignored as well.
308
-
309
- # List all of the revisions that were removed by this update, in a fast forward
310
- # update, this list will be empty, because rev-list O ^N is empty. For a non
311
- # fast forward, O ^N is the list of removed revisions
310
+ # Luckily, git-rev-parse includes just the tool. Instead of using
311
+ # "--all" we use "--branches"; this has the added benefit that
312
+ # "remotes/" will be ignored as well.
313
+
314
+ # List all of the revisions that were removed by this update, in a
315
+ # fast forward update, this list will be empty, because rev-list O
316
+ # ^N is empty. For a non fast forward, O ^N is the list of removed
317
+ # revisions
318
fast_forward=""
319
rev=""
320
for rev in $(git rev-list $newrev..$oldrev)
@@ -321,10 +327,10 @@ generate_update_branch_email()
327
fi
328
329
# List all the revisions from baserev to newrev in a kind of
324
- # "table-of-contents"; note this list can include revisions that have
325
- # already had notification emails and is present to show the full detail
326
- # of the change from rolling back the old revision to the base revision and
327
- # then forward to the new revision
330
+ # "table-of-contents"; note this list can include revisions that
331
+ # have already had notification emails and is present to show the
332
+ # full detail of the change from rolling back the old revision to
333
+ # the base revision and then forward to the new revision
334
for rev in $(git rev-list $oldrev..$newrev)
335
do
336
revtype=$(git cat-file -t "$rev")
@@ -334,19 +340,20 @@ generate_update_branch_email()
340
if [ "$fast_forward" ]; then
341
echo " from $oldrev ($oldrev_type)"
342
else
337
- # 1. Existing revisions were removed. In this case newrev is a
338
- # subset of oldrev - this is the reverse of a fast-forward,
339
- # a rewind
340
- # 2. New revisions were added on top of an old revision, this is
341
- # a rewind and addition.
343
+ # 1. Existing revisions were removed. In this case newrev
344
+ # is a subset of oldrev - this is the reverse of a
345
+ # fast-forward, a rewind
346
+ # 2. New revisions were added on top of an old revision,
347
+ # this is a rewind and addition.
348
343
- # (1) certainly happened, (2) possibly. When (2) hasn't happened,
344
- # we set a flag to indicate that no log printout is required.
349
+ # (1) certainly happened, (2) possibly. When (2) hasn't
350
+ # happened, we set a flag to indicate that no log printout
351
+ # is required.
352
353
echo ""
354
348
- # Find the common ancestor of the old and new revisions and compare
349
- # it with newrev
355
+ # Find the common ancestor of the old and new revisions and
356
+ # compare it with newrev
357
baserev=$(git merge-base $oldrev $newrev)
358
rewind_only=""
359
if [ "$baserev" = "$newrev" ]; then
@@ -387,21 +394,22 @@ generate_update_branch_email()
394
git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
395
git rev-list --pretty --stdin $oldrev..$newrev
396
390
- # XXX: Need a way of detecting whether git rev-list actually outputted
391
- # anything, so that we can issue a "no new revisions added by this
392
- # update" message
397
+ # XXX: Need a way of detecting whether git rev-list actually
398
+ # outputted anything, so that we can issue a "no new
399
+ # revisions added by this update" message
400
401
echo $LOGEND
402
else
403
echo "No new revisions were added by this update."
404
fi
405
399
- # The diffstat is shown from the old revision to the new revision. This
400
- # is to show the truth of what happened in this change. There's no point
401
- # showing the stat from the base to the new revision because the base
402
- # is effectively a random revision at this point - the user will be
403
- # interested in what this revision changed - including the undoing of
404
- # previous revisions in the case of non-fast forward updates.
406
+ # The diffstat is shown from the old revision to the new revision.
407
+ # This is to show the truth of what happened in this change.
408
+ # There's no point showing the stat from the base to the new
409
+ # revision because the base is effectively a random revision at this
410
+ # point - the user will be interested in what this revision changed
411
+ # - including the undoing of previous revisions in the case of
412
+ # non-fast forward updates.
413
echo ""
414
echo "Summary of changes:"
415
git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
@@ -448,7 +456,8 @@ generate_update_atag_email()
456
#
457
generate_atag_email()
458
{
451
- # Use git-for-each-ref to pull out the individual fields from the tag
459
+ # Use git-for-each-ref to pull out the individual fields from the
460
+ # tag
461
eval $(git for-each-ref --shell --format='
462
tagobject=%(*objectname)
463
tagtype=%(*objecttype)
@@ -459,8 +468,10 @@ generate_atag_email()
468
echo " tagging $tagobject ($tagtype)"
469
case "$tagtype" in
470
commit)
471
+
472
# If the tagged object is a commit, then we assume this is a
463
- # release, and so we calculate which tag this tag is replacing
473
+ # release, and so we calculate which tag this tag is
474
+ # replacing
475
prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
476
477
if [ -n "$prevtag" ]; then
@@ -477,25 +488,27 @@ generate_atag_email()
488
echo ""
489
echo $LOGBEGIN
490
480
- # Show the content of the tag message; this might contain a change log
481
- # or release notes so is worth displaying.
491
+ # Show the content of the tag message; this might contain a change
492
+ # log or release notes so is worth displaying.
493
git cat-file tag $newrev | sed -e '1,/^$/d'
494
495
echo ""
496
case "$tagtype" in
497
commit)
487
- # Only commit tags make sense to have rev-list operations performed
488
- # on them
498
+ # Only commit tags make sense to have rev-list operations
499
+ # performed on them
500
if [ -n "$prevtag" ]; then
501
# Show changes since the previous release
502
git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
503
else
493
- # No previous tag, show all the changes since time began
504
+ # No previous tag, show all the changes since time
505
+ # began
506
git rev-list --pretty=short $newrev | git shortlog
507
fi
508
;;
509
*)
498
- # XXX: Is there anything useful we can do for non-commit objects?
510
+ # XXX: Is there anything useful we can do for non-commit
511
+ # objects?
512
;;
513
esac
514
@@ -544,13 +557,14 @@ generate_update_general_email()
557
#
558
generate_general_email()
559
{
547
- # Unannotated tags are more about marking a point than releasing a version;
548
- # therefore we don't do the shortlog summary that we do for annotated tags
549
- # above - we simply show that the point has been marked, and print the log
550
- # message for the marked point for reference purposes
560
+ # Unannotated tags are more about marking a point than releasing a
561
+ # version; therefore we don't do the shortlog summary that we do for
562
+ # annotated tags above - we simply show that the point has been
563
+ # marked, and print the log message for the marked point for
564
+ # reference purposes
565
#
552
- # Note this section also catches any other reference type (although there
553
- # aren't any) and deals with them in the same way.
566
+ # Note this section also catches any other reference type (although
567
+ # there aren't any) and deals with them in the same way.
568
569
echo ""
570
if [ "$newrev_type" = "commit" ]; then
@@ -558,10 +572,10 @@ generate_general_email()
572
git show --no-color --root -s $newrev
573
echo $LOGEND
574
else
561
- # What can we do here? The tag marks an object that is not a commit,
562
- # so there is no log for us to display. It's probably not wise to
563
- # output git-cat-file as it could be a binary blob. We'll just say how
564
- # big it is
575
+ # What can we do here? The tag marks an object that is not
576
+ # a commit, so there is no log for us to display. It's
577
+ # probably not wise to output git-cat-file as it could be a
578
+ # binary blob. We'll just say how big it is
579
echo "$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long."
580
fi
581
}
@@ -604,8 +618,8 @@ if [ -z "$GIT_DIR" ]; then
618
fi
619
620
projectdesc=$(sed -ne '1p' "$GIT_DIR/description")
607
-# Check if the description is unchanged from it's default, and shorten it to a
608
-# more manageable length if it is
621
+# Check if the description is unchanged from it's default, and shorten it to
622
+# a more manageable length if it is
623
if expr "$projectdesc" : "Unnamed repository.*$" >/dev/null
624
then
625
projectdesc="UNNAMED PROJECT"
@@ -616,11 +630,12 @@ announcerecipients=$(git repo-config hooks.announcelist)
630
envelopesender=$(git-repo-config hooks.envelopesender)
631
632
# --- Main loop
619
-# Allow dual mode: run from the command line just like the update hook, or if
620
-# no arguments are given then run as a hook script
633
+# Allow dual mode: run from the command line just like the update hook, or
634
+# if no arguments are given then run as a hook script
635
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
636
# Output to the terminal in command line mode - if someone wanted to
623
- # resend an email; they could redirect the output to sendmail themselves
637
+ # resend an email; they could redirect the output to sendmail
638
+ # themselves
639
PAGER= generate_email $2 $3 $1
640
else
641
while read oldrev newrev refname