From: Mischa POSLAWSKY Date: Thu, 3 Feb 2011 18:55:42 +0000 (+0100) Subject: expand oneliner to proper script X-Git-Url: http://git.shiar.net/git-grep-footer.git/commitdiff_plain/784eaf272112bcfcd72257efb7bb796d34b4f922 expand oneliner to proper script --- diff --git a/git-grep-footer b/git-grep-footer index 026f5bc..1e60d4e 100755 --- a/git-grep-footer +++ b/git-grep-footer @@ -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{ + ^ + (? $HEADERMATCH) + : \s* + (? \S .+) + $ + }imx or next LINE; + + push @headers, \@header; + } + + next BLOCK if not @headers; + + for (@headers) { + say join ': ', @$_; + } + + last BLOCK; } -' +}