-#!/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;
}
-'
+}