[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [githax/master 1/3] Perl script to turn git log output into a good formail input



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue, 11 Jan 2011 11:56:57 -0500
Subject: Perl script to turn git log output into a good formail input
Commit: 618729a02b49dc416f8c198380799b15041d1e1e

---
 hooks/logs_to_emails.pl |   72 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100755 hooks/logs_to_emails.pl

diff --git a/hooks/logs_to_emails.pl b/hooks/logs_to_emails.pl
new file mode 100755
index 0000000..85715e2
--- /dev/null
+++ b/hooks/logs_to_emails.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl -w
+use warnings;
+use strict;
+
+# Turns git log output into formail input. Call "git log"
+# with appropriate options, then pipe that into this script.  This
+# script takes a subject prefix as an argument.
+#
+#  Suggested arguments for "git log" include:
+#    -p
+#    --stat
+#    one of: -c, -m, --cc
+#    --reverse
+
+# Suggested use in a commit script:
+my $suggested_use = q[
+    git log --reverse -p --stat --cc "$oldrev..$newrev" |
+     log_to_emails.pl "$projectname/${refname#refs/heads/}" |
+       formail -I "To: $recipients" \
+               -I "From: $GL_USER@xxxxxxxxxxxxxx" \
+               -s /usr/bin/sendmail -t
+] ;
+
+# Deficiencies:
+#   Doesn't omit conflict-free merges
+#   Doesn't do 003/231 counting in the subject line like format-patch does
+
+my $waiting_for_commit = 1;
+my $prefix = shift @ARGV;
+if ($prefix) {
+    $prefix = "[$prefix] ";
+} else {
+    $prefix = "";
+}
+my @headerlines;
+my $commitnum;
+my %headervals;
+
+while (<>) {
+    if ($waiting_for_commit) {
+	if (! /^commit ([0-9a-f]+)/) {
+	    print;
+	    next;
+	}
+	@headerlines = ();
+	%headervals = ();
+	$waiting_for_commit = 0;
+	$commitnum = $1;
+    }
+    if (/^\S/ or /^\s*$/) {
+	# in header. Accumulate names and values.
+	push @headerlines, $_;
+	chomp;
+	if (/^(\w+):\s+(.*)/) {
+	    $headervals{$1} = $2;
+	}
+	next;
+    }
+    # Done with header.  Generate a mail header and a commit header, then just
+    # echo till the next ^commit.
+    my $subject = $_;
+    $subject =~ s/^\s+//;     $subject =~ s/\s+$//;
+
+    print "From $commitnum Mon Sep 17 00:00:00 2001\n";
+    print "Patch-Author: $headervals{Author}\n";
+    print "Subject: $prefix$subject\n\n";
+
+    print @headerlines;
+    $waiting_for_commit = 1;
+    print $_;
+}
+
-- 
1.7.1