Test commit
[cogito/jonas.git] / contrib / gitfeedmaillist.sh
blob0c9e4e57f25fa727aa3d3dad3ddcd0e13d682606
1 #!/usr/bin/env bash
3 # Generate a mail feed for a commits list.
5 # Based on 'gitlog.sh' originally written by (c) Ross Vandegrift.
6 # Adapted to his scripts set by (c) Petr Baudis, 2005.
7 # Major optimizations by (c) Phillip Lougher.
9 # Takes an id resolving to a commit to start from (HEAD by default).
11 # regex for parent declarations
12 PARENTS="^parent [A-Za-z0-9]{40}$"
14 TMPCL=$(mktemp -t gitmail.XXXXXX)
15 TMPCM=$(mktemp -t gitmail.XXXXXX)
16 TMPML=$(mktemp -t gitmail.XXXXXX)
17 TMPMD=$(mktemp -td gitmail.XXXXXX)
19 FROM=`whoami`@`hostname`
20 #SENDMAIL=/usr/lib/sendmail
21 #MLIST=`whoami`@`hostname`
22 # Unless configured otherwise, just cat it instead of mailing.
23 SENDMAIL=tee --append
24 MLIST=git-commits-mail.out
26 # takes an object and generates the object's parent(s)
27 createmails () {
28 local parents new_parent
29 declare -a new_parent
31 new_parent=("$@")
32 parents=$#
34 while [ $parents -gt 0 ]; do
35 parent=${new_parent[$(($parents-1))]}
37 echo $parent >> $TMPCL
39 parents=0
40 ignoredparents=0
41 lastparent=
42 SUBJECT=
44 git-cat-file commit $parent > $TMPCM
46 while read key rest; do
47 case "$key" in
48 "")
49 read SUBJECT
50 echo ""
51 echo "$SUBJECT"
52 cat
53 break;
56 "parent")
57 echo "parent $rest"
58 if grep -q $rest $TMPCL; then
59 ignoredparents=$(($ignoredparents+1))
60 lastparent=$rest
61 else
62 new_parent[$parents]=$rest
63 parents=$(($parents+1))
67 "author"|"committer")
68 date=(${rest#*> })
69 sec=${date[0]}; tz=${date[1]}
70 dtz=${tz/+/+ }; dtz=${dtz/-/- }
71 pdate="$(date -Rud "1970-01-01 UTC + $sec sec $dtz" 2>/dev/null)"
72 if [ "$pdate" ]; then
73 echo $key $rest | sed "s/>.*/> ${pdate/+0000/$tz}/"
74 else
75 echo "$key $rest"
80 echo "$key $rest"
82 esac
83 done > $TMPML < $TMPCM
85 if [ $(($parents+$ignoredparents)) -eq 1 ]; then
86 [ -z "$lastparent" ] && lastparent=${new_parent[0]}
87 # Only one parent; not a merge. Mail this cset
88 ( cat <<EOF
89 From: $FROM
90 To: $MLIST
91 Subject: $SUBJECT
92 MIME-Version: 1.0
93 Content-Type: text/plain; charset=UTF-8
94 X-Git-Commit: $parent
95 X-Git-Parent: $lastparent
97 EOF
98 cat $TMPML
99 echo
100 cg-diff -r $lastparent -r $parent > $TMPCM
101 diffstat -p1 $TMPCM 2>/dev/null
102 echo
103 cat $TMPCM
104 ) > $TMPMD/$parent
105 echo Mail: $SUBJECT
109 while [ $i -lt $(($parents-1)) ]; do
110 createmails ${new_parent[$i]}
111 i=$(($i+1))
112 done
113 done
116 base=$(cg-object-id -c $1)
118 if [ -z $2 ]; then
119 lastmail=`cat .git/tags/MailDone`
120 else
121 lastmail=$(cg-object-id -c $2)
124 #if [ -z $3 ]; then
125 # tagname=`ls -rt .git/tags | grep -v MailDone | tail -1`
126 # release=`cat .git/tags/$tagname`
127 #else
128 # release=$(gitXnormid.sh -c $3)
129 #fi
131 base=$(cg-object-id -c $1) || exit 1
134 if [ "$base" != "$lastmail" ]; then
135 # List the commits at which we should stop following the tree, because
136 # we've come back to commits which were already in $lastmail.
137 git-rev-tree --edges $base $lastmail | cut -f2- -d\ | sed 's/[a-z0-9]*:1//g' >> $TMPCL
139 createmails $base
140 # No 'cg-tag -F' -- cheat.
141 echo $base > .git/tags/MailDone
142 tac $TMPCL | while read commit; do
143 if [ -r "$TMPMD/$commit" ]; then
144 $SENDMAIL $MLIST < $TMPMD/$commit
146 done
148 rm $TMPCL $TMPCM $TMPML
149 rm -rf $TMPMD