Basic working features. Appears to work reasonably well.

This commit is contained in:
Bradley M. Kuhn 2011-05-28 16:29:24 -04:00
parent 1345634988
commit 70c1dcf799

View file

@ -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 = <PATCH>) {
$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:
}