expand oneliner to proper script
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 3 Feb 2011 18:55:42 +0000 (19:55 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 3 Feb 2011 18:55:42 +0000 (19:55 +0100)
git-grep-footer

index 026f5bcc718e68b336007b19e2da5334201289b6..1e60d4e840c2dc508b55265485c4cdb9db2843bf 100755 (executable)
@@ -1,11 +1,36 @@
-#!/bin/sh
-git log --pretty=%b%x00 "$@" |
-perl -n0 -wMstrict -E '
+#!/usr/bin/perl -0 -CS
+use 5.010;
+use strict;
+use warnings;
+use Data::Dump 'pp';
+
+my $HEADERMATCH = qr/ [a-z]+ (?: (?:-\w+)+ | \ by ) /ix;
+
+while (readline) {
+       BLOCK:
        for (reverse split /\n\n/) {
-               my @headers = grep m{
-                       ^ (?: [a-z]+ (?: (?:-\w+)+ | \ by ) ) : \s* \S
-               }imx, split /\n/ or next;
-               say for @headers;
-               last;
+               my @headers;
+
+               LINE:
+               for (split /\n/) {
+                       next if not /\S/;
+                       my @header = m{
+                               ^
+                               (?<key> $HEADERMATCH)
+                               : \s*
+                               (?<val> \S .+)
+                               $
+                       }imx or next LINE;
+
+                       push @headers, \@header;
+               }
+
+               next BLOCK if not @headers;
+
+               for (@headers) {
+                       say join ': ', @$_;
+               }
+
+               last BLOCK;
        }
-'
+}