#!/usr/bin/perl -w # based on ciabot.pl: # # Loosely based on cvslog by Russ Allbery # # Copyright 1998 Board of Trustees, Leland Stanford Jr. University # # Copyright 2001, 2003, 2004, 2005 Petr Baudis # Copyright 2010 Peter Palfrader # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License version 2, as published by the # Free Software Foundation. # use in post-receive like that: # | tmpfile=`mktemp` # | trap "rm -f '$tmpfile'" EXIT # | # | cwd="`pwd`" # | REPO_NAME="`basename '$cwd'`" # | while read oldrev newrev refname; do # | echo "$oldrev $newrev $refname" >> "$tmpfile" # | done # | # | while read oldrev newrev refname; do # | for merged in $(git-rev-list $newrev ^$oldrev | tac); do # | ./hooks/nsa-bot "$merged" "$refname" "$REPO_NAME" # | done # | done < "$tmpfile" # | # | # # | #. /usr/share/doc/git-core/contrib/hooks/post-receive-email use strict; use POSIX qw(strftime); use vars qw ($project $from_email $dest_email $sendmail); $project = 'weasel'; $from_email = 'commit@commit.noreply.org'; $dest_email = 'commit@commit.noreply.org'; $sendmail = '/usr/sbin/sendmail'; die ("Usage: $0 [ [ [] ] ]") if (scalar @ARGV < 3); # The commit stuff my $commit = $ARGV[0]; my $branch = $ARGV[1]; my $repos = $ARGV[2]; if (scalar @ARGV > 3) { $project = $ARGV[3]; } if (scalar @ARGV > 4) { $from_email = $ARGV[4]; } if (scalar @ARGV > 5) { $dest_email = $ARGV[5]; } open COMMIT, "git-cat-file commit $commit|" or die "git-cat-file commit $commit: $!"; my $state = 0; my $logmsg = ''; my $line; my $tree; my @parent; my $author; my $timestamp; my $committer; my @files; while (defined ($line = )) { if ($state == 1) { $logmsg .= $line; $state++; next; } elsif ($state > 1) { next; } chomp $line; unless ($line) { $state = 1; next; } my ($key, $value) = split(/ /, $line, 2); if ($key eq 'tree') { $tree = $value; } elsif ($key eq 'parent') { push(@parent, $value); } elsif ($key eq 'author') { ($author, $timestamp) = $value =~ /^(.*)\s+([0-9]+)\s+.?[0-9]{4}$/; $author = $value unless $author; } elsif ($key eq 'committer') { $committer = $value; } } close COMMIT; die ("Did not learn parent or tree.\n") unless (scalar @parent > 0 and defined $tree); open DIFF, "git-diff-tree -r $parent[0] $tree|" or die "git-diff-tree $parent[0] $tree: $!"; while (defined ($line = )) { chomp $line; my @f; (undef, @f) = split(/\t/, $line, 2); push (@files, @f); } close DIFF; $branch =~ s#refs/heads/##; if (defined $repos) { $branch = "$repos/$branch"; } my $message = "[$branch] ".strftime("%Y-%m-%d %H:%M:%S", gmtime($timestamp))." $author: $logmsg"; open (MAIL, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?>>8); #open (MAIL, "| /bin/cat") or die ("Cannot cat!\n"); print MAIL <> 8) . "\n" unless ($? == 0); # vi: set sw=2: