#!/usr/bin/perl -w # Copyright 2018 The Linux Foundation # License: AGPL-3.0+ use strict; use warnings; use Email::MIME; use Digest::MD5 qw(md5_hex); $| = 0; my $h = '[0-9a-f]'; my $state = ''; my $blob; my $suff; # 16 bytes for git hashing while () { if ($_ eq "blob\n") { $state = 'blob'; } elsif (/^commit /) { $state = 'commit'; } elsif ($state eq 'commit') { if (m{^(M 100644 :\d+) ${h}{2}/${h}{38}}o) { my ($pfx) = ($1); print "$pfx msg\n"; next; } if (/^data (\d+)/) { print $_; my $len = $1; if ($len) { my $tmp; read(STDIN, $tmp, $len) or die "read: $!\n"; print $tmp; } next; } } elsif ($state eq 'blob') { if (/^data (\d+)/) { my $len = $1; print $_; next unless $len; read(STDIN, $blob, $len) or die "read: $!\n"; print $blob; next; } } print $_; }