3 # Copyright (c) 2007 Andy Parkins
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.
11 # This is Girocco-customized version. No matter what is said below, it has
13 # * Calling with arguments is same as giving them on stdin.
14 # * Optional fourth parameter is project name, used at most places instead
16 # * Optional fifth parameter is email sender.
17 # * Optional sixth parameter is extra e-mail header to add.
18 # * If MAIL_SH_OTHER_BRANCHES is set it is taken as branch tips of already seen
19 # revisions when running show_new_revisions and mail.sh skips its own
20 # computation. If it starts with '@' the rest is the hash of a blob that
21 # contains the information (one tip per line).
22 # If MAIL_SH_OTHER_BRANCHES is not set, guess at what they are.
23 # MAIL_SH_OTHER_BRANCHES is ignored if updates are piped in via stdin.
25 # * Default subject prefix is site name.
26 # * Unsubscribe instructions in email footer.
27 # * Default showrev includes gitweb link and show -C.
28 # * Nicer subject line.
29 # * Limit mail size to 256kb.
32 # This hook is stored in the contrib/hooks directory. Your distribution
33 # will have put this somewhere standard. You should make this script
34 # executable then link to it in the repository you would like to use it in.
35 # For example, on debian the hook is stored in
36 # /usr/share/git-core/contrib/hooks/post-receive-email:
38 # chmod a+x post-receive-email
39 # cd /path/to/your/repository.git
40 # ln -sf /usr/share/git-core/contrib/hooks/post-receive-email hooks/post-receive
42 # This hook script assumes it is enabled on the central repository of a
43 # project, with all users pushing only to it and not between each other. It
44 # will still work if you don't operate in that style, but it would become
45 # possible for the email to be from someone other than the person doing the
51 # This is the list that all pushes will go to; leave it blank to not send
52 # emails for every ref update.
54 # If true do not include the actual diff when showing new commits (the
55 # summary information will still be shown). Default is false.
57 # This is the list that all pushes of annotated tags will go to. Leave it
58 # blank to default to the mailinglist field. The announce emails lists
59 # the short log summary of the changes since the last annotated tag.
60 # hooks.envelopesender
61 # If set then the -f option is passed to sendmail to allow the envelope
62 # sender address to be set
64 # All emails have their subjects prefixed with this prefix, or "[SCM]"
65 # if emailprefix is unset, to aid filtering
67 # The shell command used to format each revision in the email, with
68 # "%s" replaced with the commit id. Defaults to "git rev-list -1
69 # --pretty %s", displaying the commit id, author, date and log
70 # message. To list full patches separated by a blank line, you
71 # could set this to "git show -C %s; echo".
72 # To list a gitweb/cgit URL *and* a full patch for each change set, use this:
73 # "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
74 # Be careful if "..." contains things that will be expanded by shell "eval"
79 # All emails include the headers "X-Git-Refname", "X-Git-Oldrev",
80 # "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and
81 # give information for debugging.
84 # ---------------------------- Functions
87 # Function to output arguments without interpretation followed by \n
95 # Function to read a tag's (the single argument) header fields into
96 # tagobject the "object" value
97 # tagtype the "type" value
98 # tagtag the "tag" value
99 # taggername from "tagger" value before first '<'
100 # taggerdate from "tagger" value after '>' but formatted into a date string
101 # taggeremail from "tagger" value between '<' and '>'
102 # On return all fields will be set (to empty if failure) and the three tagger
103 # fields will only be set to non-empty if a "tagger" header field is present.
104 # If the object does not exist or is not a tag the function returns failure.
113 if _tagfields
="$(git cat-file tag "$1" | LC_ALL=C awk -F '[ ]' '
114 function quotesh(sv) {
115 gsub(/'\''/, "'\'\\\\\'\''", sv)
116 return "'\''" sv "'\''"
119 sub(/^[ \t]+/, "", sv)
120 sub(/[ \t]+$/, "", sv)
124 sub(/^[^ ]* /, "", sv)
128 if ($1 == "object
") to=hval($0)
129 if ($1 == "type") ty=hval($0)
130 if ($1 == "tag
") tt=hval($0)
131 if ($1 == "tagger
") tr=hval($0)
134 if (tt == "" || to == "" || ty == "") exit 1
135 print "tagobject
=" quotesh(to)
136 print "tagtype
=" quotesh(ty)
137 print "tagtag
=" quotesh(tt)
138 if (match(tr, /^[ \t]*[^ \t<][^<]*/)) {
139 tn=substr(tr, RSTART, RLENGTH)
140 tr=substr(tr, RSTART + RLENGTH)
143 print "taggername
=" quotesh(tn)
144 if (match(tr, /^<.*>/)) {
146 te=substr(tr, RSTART+1, RLENGTH-2)
147 tr=substr(tr, RSTART + RLENGTH)
150 print "taggeremail
=" quotesh(te)
151 if (match(tr, /^[ \t]*[0-9]+([ \t]+[-+]?[0-9][0-9]([0-9][0-9]([0-9][0-9])?)?)[ \t]*$/))
154 print "taggerdate
=" quotesh(td)
160 [ -z "$taggerdate" ] || taggerdate
="$(strftime "$sdatefmt" $taggerdate)"
167 # Function to prepare for email generation. This decides what type
168 # of update this is and whether an email should even be generated.
173 oldrev
=$
(git rev-parse
--revs-only "$1" --)
174 newrev
=$
(git rev-parse
--revs-only "$2" --)
175 [ "$oldrev" != "$newrev" ] ||
return 1
176 scratch
="${newrev#????????????????}"
177 newrev16
="${newrev%$scratch}"
181 # 0000->1234 (create)
182 # 1234->2345 (update)
183 # 2345->0000 (delete)
184 if LC_ALL
=C
expr "$oldrev" : '0*$' >/dev
/null
188 if LC_ALL
=C
expr "$newrev" : '0*$' >/dev
/null
196 # --- Get the revision types
197 newrev_type
=$
(git cat-file
-t $newrev 2> /dev
/null
)
198 oldrev_type
=$
(git cat-file
-t "$oldrev" 2> /dev
/null
)
199 case "$change_type" in
202 rev_type
="$newrev_type"
206 rev_type
="$oldrev_type"
210 # The revision type tells us what type the commit is, combined with
211 # the location of the ref we can decide between
216 case "$refname","$rev_type" in
220 short_refname
=${refname##refs/tags/}
224 refname_type
="annotated tag"
225 short_refname
=${refname##refs/tags/}
227 if [ -n "$announcerecipients" ]; then
228 recipients
="$announcerecipients"
231 refs
/heads
/*,commit|refs
/heads
/*,tag
)
233 refname_type
="branch"
234 short_refname
=${refname##refs/heads/}
236 refs
/remotes
/*,commit
)
238 refname_type
="tracking branch"
239 short_refname
=${refname##refs/remotes/}
240 echol
>&2 "*** Push-update of tracking branch, $refname"
241 echol
>&2 "*** - no email generated."
244 refs
/mob
/*,commit|refs
/mob
/*,tag
)
246 refname_type
="personal mob ref"
247 short_refname
=${refname##refs/mob/}
248 echol
>&2 "*** Push-update of personal mob ref, $refname"
249 echol
>&2 "*** - no email generated."
253 # Anything else (is there anything else?)
254 echol
>&2 "*** Unknown type of update to $refname ($rev_type)"
255 echol
>&2 "*** - no email generated"
260 # Check if we've got anyone to send to
261 if [ -z "$recipients" ]; then
262 case "$refname_type" in
264 config_name
="hooks.announcelist"
267 config_name
="hooks.mailinglist"
270 echol
>&2 "*** $config_name is not set so no email will be sent"
271 echol
>&2 "*** for $refname update $oldrev->$newrev"
279 # Top level email generation function. This calls the appropriate
280 # body-generation routine after outputting the common header.
282 # Note this function doesn't actually generate any email output, that is
283 # taken care of by the functions it calls:
284 # - generate_email_header
285 # - generate_create_XXXX_email
286 # - generate_update_XXXX_email
287 # - generate_delete_XXXX_email
288 # - generate_email_footer
290 # Note also that this function cannot 'exit' from the script; when this
291 # function is running (in hook script mode), the send_mail() function
292 # is already executing in another process, connected via a pipe, and
293 # if this function exits without, whatever has been generated to that
294 # point will be sent as an email... even if nothing has been generated.
299 # The email subject will contain the best description of the ref
300 # that we can build from the parameters
301 describe
=$
(git describe
$rev 2>/dev
/null
)
302 if [ -z "$describe" ]; then
306 generate_email_header
308 # Call the correct body generation function
310 case "$refname_type" in
311 "tracking branch"|branch
)
318 generate_
${change_type}_
${fn_name}_email
320 generate_email_footer
323 generate_email_header
()
325 # --- Email (all stdout will be the email)
327 if [ -n "$emailsender" ]; then
328 echol
"From: $emailsender"
332 Subject: ${emailprefix}$projectname $refname_type $short_refname ${change_type}d: $describe
334 Content-Type: text/plain; charset=utf-8
335 Content-Transfer-Encoding: 8bit
337 [ -n "$cfg_suppress_x_girocco" ] || echol
"X-Girocco: $cfg_gitweburl"
338 [ -z "$emailextraheader" ] || echol
"$emailextraheader"
340 X-Git-Refname: $refname
341 X-Git-Reftype: $refname_type
342 X-Git-Oldrev: $oldrev
343 X-Git-Newrev: $newrev
344 Auto-Submitted: auto-generated
346 This is an automated email generated because a ref change occurred in the
347 git repository for project $projectname.
349 The $refname_type, $short_refname has been ${change_type}d
353 generate_email_footer
()
359 $cfg_name automatic notification. Contact project admin $projectowner
360 if you want to unsubscribe, or site admin $cfg_admin if you receive
367 # --------------- Branches
370 # Called for the creation of a branch
372 generate_create_branch_email
()
374 # This is a new branch and so oldrev is not valid
375 echol
" at $newrev ($newrev_type)"
378 echol
"Those revisions in this branch that are new to this repository"
379 echol
"have not appeared on any other notification email; so we list"
380 echol
"those revisions in full, below."
387 # If any revisions were shown by show_new_revisions then we show
388 # a diffstat from the last shown revisions's parent (or the empty tree
389 # if the last revision shown is a root revision) to the new revision
390 # provided the last shown revision is not a merge commit and there
391 # was at most a single boundary commit encountered by show_new_revisions.
392 # This is to show the truth of what happened in this change.
394 if [ -n "$LAST_SHOWN_REVISION" ] && [ -n "$LAST_SHOWN_NPARENTS" ] && [ -n "$LAST_SHOWN_NBOUNDARY" ] && \
395 [ "$LAST_SHOWN_NPARENTS" -le 1 ] && [ "$LAST_SHOWN_NBOUNDARY" -le 1 ]; then
396 if [ "$LAST_SHOWN_NPARENTS" -eq 0 ]; then
397 # Note that since Git 1.5.5 the empty tree object is ALWAYS available
398 # whether or not it's actually present in the repository.
400 # Set oldrev to the result of $(git hash-object -t tree --stdin < /dev/null)
401 oldrev
="4b825dc642cb6eb9a060e54bf8d69288fbee4904"
403 # Set oldrev to the parent of the last shown revision
404 oldrev
="$LAST_SHOWN_REVISION^"
407 echol
"Summary of changes:"
408 git diff-tree
--no-color --stat=72 --summary -B --find-copies-harder $oldrev $newrev
413 # Called for the change of a pre-existing branch
415 generate_update_branch_email
()
418 # 1 --- 2 --- O --- X --- 3 --- 4 --- N
420 # O is $oldrev for $refname
421 # N is $newrev for $refname
422 # X is a revision pointed to by some other ref, for which we may
423 # assume that an email has already been generated.
424 # In this case we want to issue an email containing only revisions
425 # 3, 4, and N. Given (almost) by
427 # git rev-list N ^O --not --all
429 # The reason for the "almost", is that the "--not --all" will take
430 # precedence over the "N", and effectively will translate to
432 # git rev-list N ^O ^X ^N
434 # So, we need to build up the list more carefully. git rev-parse
435 # will generate a list of revs that may be fed into git rev-list.
436 # We can get it to make the "--not --all" part and then filter out
439 # git rev-parse --not --all | grep -v N
441 # Then, using the --stdin switch to git rev-list we have effectively
444 # git rev-list N ^O ^X
446 # This leaves a problem when someone else updates the repository
447 # while this script is running. Their new value of the ref we're
448 # working on would be included in the "--not --all" output; and as
449 # our $newrev would be an ancestor of that commit, it would exclude
450 # all of our commits. What we really want is to exclude the current
451 # value of $refname from the --not list, rather than N itself. So:
453 # git rev-parse --not --all | grep -v $(git rev-parse $refname)
455 # Get's us to something pretty safe (apart from the small time
456 # between refname being read, and git rev-parse running - for that,
460 # Next problem, consider this:
461 # * --- B --- * --- O ($oldrev)
463 # * --- X --- * --- N ($newrev)
465 # That is to say, there is no guarantee that oldrev is a strict
466 # subset of newrev (it would have required a --force, but that's
467 # allowed). So, we can't simply say rev-list $oldrev..$newrev.
468 # Instead we find the common base of the two revs and list from
471 # As above, we need to take into account the presence of X; if
472 # another branch is already in the repository and points at some of
473 # the revisions that we are about to output - we don't want them.
474 # The solution is as before: git rev-parse output filtered.
476 # Finally, tags: 1 --- 2 --- O --- T --- 3 --- 4 --- N
478 # Tags pushed into the repository generate nice shortlog emails that
479 # summarise the commits between them and the previous tag. However,
480 # those emails don't include the full commit messages that we output
481 # for a branch update. Therefore we still want to output revisions
482 # that have been output on a tag email.
484 # Luckily, git rev-parse includes just the tool. Instead of using
485 # "--all" we use "--branches"; this has the added benefit that
486 # "remotes/" will be ignored as well.
488 # List all of the revisions that were removed by this update, in a
489 # fast-forward update, this list will be empty, because rev-list O
490 # ^N is empty. For a non-fast-forward, O ^N is the list of removed
494 for rev in $
(git rev-list
$newrev..
$oldrev)
496 revtype
=$
(git cat-file
-t "$rev")
497 echol
" discards $rev ($revtype)"
499 if [ -z "$rev" ]; then
503 # List all the revisions from baserev to newrev in a kind of
504 # "table-of-contents"; note this list can include revisions that
505 # have already had notification emails and is present to show the
506 # full detail of the change from rolling back the old revision to
507 # the base revision and then forward to the new revision
508 for rev in $
(git rev-list
$oldrev..
$newrev)
510 revtype
=$
(git cat-file
-t "$rev")
511 echol
" via $rev ($revtype)"
514 if [ "$fast_forward" ]; then
515 echol
" from $oldrev ($oldrev_type)"
517 # 1. Existing revisions were removed. In this case newrev
518 # is a subset of oldrev - this is the reverse of a
519 # fast-forward, a rewind
520 # 2. New revisions were added on top of an old revision,
521 # this is a rewind and addition.
523 # (1) certainly happened, (2) possibly. When (2) hasn't
524 # happened, we set a flag to indicate that no log printout
529 # Find the common ancestor of the old and new revisions and
530 # compare it with newrev
531 baserev
=$
(git merge-base
$oldrev $newrev)
533 if [ "$baserev" = "$newrev" ]; then
534 echol
"This update discarded existing revisions and left the branch pointing at"
535 echol
"a previous point in the repository history."
537 echol
" * -- * -- N ($newrev)"
539 echol
" O -- O -- O ($oldrev)"
541 echol
"The removed revisions are not necessarily gone - if another reference"
542 echol
"still refers to them they will stay in the repository."
545 echol
"This update added new revisions after undoing existing revisions. That is"
546 echol
"to say, the old revision is not a strict subset of the new revision. This"
547 echol
"situation occurs when you --force push a change and generate a repository"
548 echol
"containing something like this:"
550 echol
" * -- * -- B -- O -- O -- O ($oldrev)"
552 echol
" N -- N -- N ($newrev)"
554 echol
"When this happens we assume that you've already had alert emails for all"
555 echol
"of the O revisions, and so we here report only the revisions in the N"
556 echol
"branch from the common base, B."
561 if [ -z "$rewind_only" ]; then
562 echol
"Those revisions listed above that are new to this repository have"
563 echol
"not appeared on any other notification email; so we list those"
564 echol
"revisions in full, below."
570 # XXX: Need a way of detecting whether git rev-list actually
571 # outputted anything, so that we can issue a "no new
572 # revisions added by this update" message
576 echol
"No new revisions were added by this update."
579 # The diffstat is shown from the old revision to the new revision.
580 # This is to show the truth of what happened in this change.
581 # There's no point showing the stat from the base to the new
582 # revision because the base is effectively a random revision at this
583 # point - the user will be interested in what this revision changed
584 # - including the undoing of previous revisions in the case of
585 # non-fast-forward updates.
587 echol
"Summary of changes:"
588 git diff-tree
--no-color --stat=72 --summary -B --find-copies-harder $oldrev..
$newrev
592 # Called for the deletion of a branch
594 generate_delete_branch_email
()
599 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
603 # --------------- Annotated tags
606 # Called for the creation of an annotated tag
608 generate_create_atag_email
()
610 echol
" at $newrev ($newrev_type)"
616 # Called for the update of an annotated tag (this is probably a rare event
617 # and may not even be allowed)
619 generate_update_atag_email
()
621 echol
" to $newrev ($newrev_type)"
622 echol
" from $oldrev (which is now obsolete)"
628 # Called when an annotated tag is created or changed
630 generate_atag_email
()
632 # Use read_tag_fields to pull out the individual fields from the
633 # tag and git cat-file --batch-check to fully peel the tag if needed
636 read_tag_fields
"$tagrev"
637 if [ "$tagtype" = "tag" ]; then
641 info
="$(echo "$tagrev^
{}" | git cat-file --batch-check='
642 peeledobject=%(objectname)
643 peeledtype=%(objecttype)'
645 case "$info" in *type=*) eval "$info";; *)
649 peeledobject
="$tagobject"
650 peeledtype
="$tagtype"
653 echol
" tagging $peeledobject ($peeledtype)"
654 case "$peeledtype" in
657 # If the tagged object is a commit, then we assume this is a
658 # release, and so we calculate which tag this tag is
660 prevtag
=$
(git describe
--abbrev=0 "$peeledobject^" 2>/dev
/null
)
662 if [ -n "$prevtag" ]; then
663 echol
" replaces $prevtag"
667 echol
" length $(git cat-file -s "$peeledobject" 2>/dev/null) bytes"
670 echol
" tagged by $taggername"
671 echol
" on $taggerdate"
679 echol
"Object: $tagobject ($tagtype)"
680 [ -z "$taggername" ] || \
681 echol
"Tagger: $taggername"
682 [ -z "$taggerdate" ] || \
683 echol
"Date: $taggerdate"
684 echol
"URL: <$projurl/$tagrev16>"
687 # Show the content of the tag message; this might contain a change
688 # log or release notes so is worth displaying.
689 git cat-file tag
"$tagrev" | LC_ALL
=C
sed -e '1,/^$/d;s/^/ /;'
691 [ "$tagtype" = "tag" ]
694 scratch
="${tagrev#????????????????}"
695 tagrev16
="${tagrev%$scratch}"
696 read_tag_fields
"$tagrev" ||
break
699 case "$peeledtype" in
701 # Only commit tags make sense to have rev-list operations
703 if [ -n "$prevtag" ]; then
704 # Show changes since the previous release
705 git shortlog
"$prevtag..$newrev"
707 # No previous tag, show all the changes since time
713 # XXX: Is there anything useful we can do for non-commit
722 # Called for the deletion of an annotated tag
724 generate_delete_atag_email
()
729 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
733 # --------------- General references
736 # Called when any other type of reference is created (most likely a
739 generate_create_general_email
()
741 echol
" at $newrev ($newrev_type)"
743 generate_general_email
747 # Called when any other type of reference is updated (most likely a
750 generate_update_general_email
()
752 echol
" to $newrev ($newrev_type)"
753 echol
" from $oldrev"
755 generate_general_email
759 # Called for creation or update of any other type of reference
761 generate_general_email
()
763 # Unannotated tags are more about marking a point than releasing a
764 # version; therefore we don't do the shortlog summary that we do for
765 # annotated tags above - we simply show that the point has been
766 # marked, and print the log message for the marked point for
769 # Note this section also catches any other reference type (although
770 # there aren't any) and deals with them in the same way.
773 if [ "$newrev_type" = "commit" ]; then
774 if [ -n "$(git rev-list --no-walk --merges $newrev)" ]; then
775 pfmt12
="$pfmt1$pfmt1m$pfmt2"
777 pfmt12
="$pfmt1$pfmt2"
780 git diff-tree
--no-color --date=$datefmt --root -s --always --encoding=UTF-8
--format="$pfmt12$projurlesc/$newrev16$pfmt3" --abbrev=$habbr $newrev
783 # What can we do here? The tag marks an object that is not
784 # a commit, so there is no log for us to display. It's
785 # probably not wise to output git cat-file as it could be a
786 # binary blob. We'll just say how big it is
787 echol
"$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long."
792 # Called for the deletion of any other type of reference
794 generate_delete_general_email
()
799 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
804 # --------------- Miscellaneous utilities
807 # Show new revisions as the user would like to see them in the email.
809 # On return LAST_SHOWN_REVISION will be set to non-empty if any revisions shown
810 # and LAST_SHOWN_NPARENTS will be the number of parents it has (possibly 0)
811 # and LAST_SHOWN_NBOUNDARY will be the number of shown leaves (possibly 0)
815 # This shows all log entries that are not already covered by
816 # another ref - i.e. commits that are now accessible from this
817 # ref that were previously not accessible
818 # (see generate_update_branch_email for the explanation of this
822 LAST_SHOWN_NBOUNDARY
=0
824 # Revision range passed to rev-list differs for new vs. updated
826 if [ "$change_type" = create
]
828 # Show all revisions exclusive to this (new) branch.
831 # Branch update; show revisions not part of $oldrev.
832 revspec
=$oldrev..
$newrev
835 if [ "${MAIL_SH_OTHER_BRANCHES+set}" = "set" ]; then
836 case "$MAIL_SH_OTHER_BRANCHES" in
838 othertips
="git cat-file blob '${MAIL_SH_OTHER_BRANCHES#@}' 2>/dev/null"
841 othertips
='printf "%s\n" $MAIL_SH_OTHER_BRANCHES'
845 othertips
='git for-each-ref --format="%(refname)" refs/heads |
846 LC_ALL=C awk -v "refname=$refname" "\$1 != refname"'
848 # if [ -z "$custom_showrev" ]
850 # git rev-list --pretty --stdin $revspec
852 while read onerev mark pcnt
&& [ -n "$onerev" ] && [ -n "$mark" ] && [ -n "$pcnt" ]
854 if [ "$mark" = "-" ]; then
855 LAST_SHOWN_NBOUNDARY
=$
(( $LAST_SHOWN_NBOUNDARY + 1 ))
858 LAST_SHOWN_REVISION
="$onerev"
859 LAST_SHOWN_NPARENTS
="$pcnt"
860 if [ -n "$custom_showrev" ]; then
861 eval $
(printf "$custom_showrev" $onerev)
863 if [ ${summaryonly:-false} = false
]; then
864 if [ ${pcnt:-1} -gt 1 ]; then
866 pfmt12
="$pfmt1$pfmt1m$pfmt2"
868 opts
="-p --stat=72 --summary"
869 pfmt12
="$pfmt1$pfmt2"
872 if [ ${pcnt:-1} -gt 1 ]; then
874 pfmt12
="$pfmt1$pfmt1m$pfmt2"
876 opts
="--stat=72 --summary"
877 pfmt12
="$pfmt1$pfmt2"
880 scratch
="${onerev#????????????????}"
881 onerev16
="${onerev%$scratch}"
882 git diff-tree
--no-color --date=$datefmt $opts --always --encoding=UTF-8
--format="$pfmt12$projurlesc/$onerev16$pfmt3" --abbrev=$habbr -B -C --root $onerev
886 $(eval "$othertips" |
887 git cat-file --batch-check='^%(objectname)' |
888 LC_ALL=C sed -e '/ missing$/d' |
889 git --no-pager log --stdin --no-color --boundary --format=tformat:"%H %m %p" $revspec |
890 LC_ALL=C awk '{print $1 " " $2 " " NF-2}')
899 while IFS
= read -r line
; do
900 # Include size of RFC 822 trailing CR+LF on each line
901 size
=$
(($size+${#line}+2))
902 if [ $size -gt $1 ]; then
903 echol
"...e-mail trimmed, has been too large."
919 if [ -n "$cfg_sender" ]; then
920 "${cfg_sendmail_bin:-/usr/sbin/sendmail}" -i -t -f "$cfg_sender"
922 "${cfg_sendmail_bin:-/usr/sbin/sendmail}" -i -t
926 # ---------------------------- main()
929 LOGBEGIN
="- Log -----------------------------------------------------------------"
930 LOGEND
="-----------------------------------------------------------------------"
935 # Git formatting to use
939 # strftime formatting to use (empty is default rfc2822 format)
942 # This is --pretty=medium in four parts with a URL: line added
943 # The pfmt1m value must be inserted after the pfmt1 value but only for merges
944 # The URL must be inserted between pfmt2 and pfmt3
945 pfmt1
='format:commit %H%n'
947 pfmt2
='Author: %an <%ae>%nDate: %ad%nURL: <'
948 pfmt3
='>%n%n%w(0,4,4)%s%n%n%b'
950 git_add_config core.abbrev
=$habbr
952 # Set GIT_DIR either from the working directory, or from the environment
954 GIT_DIR
=$
(git rev-parse
--git-dir 2>/dev
/null
)
955 if [ -z "$GIT_DIR" ]; then
956 echol
>&2 "fatal: mail.sh: GIT_DIR not set"
961 ! [ -s "$GIT_DIR/description" ] || projectdesc
=$
(LC_ALL
=C
sed -ne '1p' "$GIT_DIR/description")
962 # Check if the description is unchanged from it's default, and shorten it to
963 # a more manageable length if it is
964 if [ -z "$projectdesc" ] || LC_ALL
=C
expr "$projectdesc" : "Unnamed repository.*$" >/dev
/null
966 projectdesc
="UNNAMED PROJECT"
969 # If --stdout is first argument send all output there instead of mailing
970 if [ "$1" = "--stdout" ]; then
972 cfg_sendmail_bin
="sendmail_to_stdout"
975 projectname
="${4%.git}"
976 if [ -n "$projectname" ]; then
977 projectname
="$projectname.git"
978 projectowner
="$(config_get owner)"
980 projectname
="$(basename "$PWD")"
982 projectboth
="$projectname (\"$projectdesc\")"
983 projurl
="$cfg_gitweburl/$projectname"
984 projurlesc
="$(printf '%s\n' "$projurl" | sed -e 's/%/%%/g')"
987 emailextraheader
="$6"
989 recipients
=$
(git config hooks.mailinglist
)
990 summaryonly
=$
(git config
--bool hooks.summaryonly
2>/dev
/null ||
:)
991 announcerecipients
=$
(git config hooks.announcelist
)
992 envelopesender
=$
(git config hooks.envelopesender
)
993 emailprefix
=$
(git config hooks.emailprefix || echol
"[$cfg_name] ")
994 custom_showrev
=$
(git config hooks.showrev
)
997 # Allow dual mode: run from the command line just like the update hook, or
998 # if no arguments are given then run as a hook script
999 # If --stdout is first argument send all output there instead (handled above)
1000 # Optional 4th (projectname), 5th (sender) and 6th (extra header) arguments
1001 if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
1002 # Handle a single update rather than a batch on stdin
1003 # Output will still be sent to sendmail unless --stdout is used
1004 # Same 3 args as update hook (<refname> <old> <new>)
1005 if prep_for_email
$2 $3 $1; then
1006 PAGER
= generate_email | size_limit $
((256*1024)) | send_mail
1009 # MAIL_SH_OTHER_BRANCHES cannot possibly be valid for multiple updates
1010 unset MAIL_SH_OTHER_BRANCHES
1011 # Same input as pre-receive hook (each line is <old> <new> <refname>)
1012 while read oldrev newrev refname
1014 prep_for_email
$oldrev $newrev $refname ||
continue
1015 PAGER
= generate_email | size_limit $
((256*1024)) | send_mail