diff --git a/bash-patch-apply.plx b/bash-patch-apply.plx index 38cf3bb..3700b8d 100755 --- a/bash-patch-apply.plx +++ b/bash-patch-apply.plx @@ -33,4 +33,53 @@ foreach my $patchFile (@ARGV) { print STDERR "GPG signature check problem on $patchFile\n"; exit 1; } + open(PATCH, "<", $patchFile) or die "unable to read $patchFile: $!"; + my($log, $takingLog, $inPatch, $date, undef) = ("", 0, 0); + while (my $line = ) { + $takingLog = 1 if ($line =~ /^Patch-ID\s*:/); + if ($line =~ /^\s*Patch\s*:\s*$/) { + $takingLog = 0; + $inPatch = 1; + next; + } + $log .= $line if $takingLog; + + if ($inPatch and $line =~ /^\s*\-\-\-\s+(?:\S+)\s+(.+)\s*$/) { + $date = $1; + last; + } + } + close PATCH; + if ($? != 0) { + print STDERR "error reading $patchFile: $!"; + exit 1; + } + if (not defined $date) { + print "STDERR could not find date for $patchFile\n"; + exit 1; + } + if ($log eq "") { + print "STDERR could not find log for $patchFile\n"; + exit 1; + } + + system("/usr/bin/patch -p0 < $patchFile"); + if ($? != 0) { + print STDERR "$patchFile did not apply clean!\n"; + exit 1; + } + $ENV{GIT_AUTHOR_DATE} = $date; + $ENV{GIT_AUTHOR_NAME} = 'Chet Ramey'; + $ENV{GIT_AUTHOR_EMAIL} = 'chet@cwru.edu'; + open(COMMIT, "|-", "git commit -a -F -") or die "unable to run git: $!"; + print COMMIT $log; + close COMMIT; + if ($? != 0) { + print STDERR "$patchFile commit failed!\n"; + exit 1; + } +############################################################################### +# Local variables: +# compile-command: "perl -c bash-patch-apply.plx" +# End: }