[or-cvs] [githax/master 2/3] Add a script to postprocess a log stream and remove trivial merges

nickm at torproject.org nickm at torproject.org
Wed Jan 12 23:57:05 UTC 2011


Author: Nick Mathewson <nickm at torproject.org>
Date: Tue, 11 Jan 2011 12:12:08 -0500
Subject: Add a script to postprocess a log stream and remove trivial merges
Commit: 9d7400c19c7f8f65bbaff1e19428aa8811e69b4c

---
 hooks/logs_to_emails.pl      |    7 ++++++-
 hooks/remove_empty_merges.pl |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletions(-)
 create mode 100755 hooks/remove_empty_merges.pl

diff --git a/hooks/logs_to_emails.pl b/hooks/logs_to_emails.pl
index 85715e2..39c2d87 100755
--- a/hooks/logs_to_emails.pl
+++ b/hooks/logs_to_emails.pl
@@ -11,10 +11,16 @@ use strict;
 #    --stat
 #    one of: -c, -m, --cc
 #    --reverse
+#
+# Note that if you're using this with remove_empty_merges.pl, you need
+# to put it in the pipeline _AFTER_ remove_empty_merges, since
+# remove_empty_merges consumes and produces git log output, whereas
+# this script consumes logs and produces emails.
 
 # Suggested use in a commit script:
 my $suggested_use = q[
     git log --reverse -p --stat --cc "$oldrev..$newrev" |
+     remove_empty_merges.pl |
      log_to_emails.pl "$projectname/${refname#refs/heads/}" |
        formail -I "To: $recipients" \
                -I "From: $GL_USER at torproject.org" \
@@ -22,7 +28,6 @@ my $suggested_use = q[
 ] ;
 
 # 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;
diff --git a/hooks/remove_empty_merges.pl b/hooks/remove_empty_merges.pl
new file mode 100755
index 0000000..0877ede
--- /dev/null
+++ b/hooks/remove_empty_merges.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+use warnings;
+use strict;
+
+# Post-process git log output and remove every entry that does not
+# contain a diff.
+#
+# The intended use-case is for you're using a log mode that generates
+# patches for nontrivial merges but not for trivial ones: you'll want
+# to mail out the messages that contain diffs, but not the ones that
+# don't.
+
+my $copying = 0;
+my $waiting_for_commit = 1;
+
+my @pending_lines = ();
+
+while (<>) {
+    my $is_commit = /^commit [0-9a-f]+/;
+    if ($copying) {
+	if (! $is_commit) {
+	    print;
+	    next;
+	}
+	$copying = 0;
+    }
+    @pending_lines = () if ($is_commit);
+
+    push @pending_lines, $_;
+    if (/^diff/) {
+	$copying = 1;
+
+	print @pending_lines;
+	@pending_lines = ();
+    }
+}
-- 
1.7.1




More information about the tor-commits mailing list