From 996d1d662b7c589b9a68822ff36fe682afefabac Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Tue, 15 Sep 2009 12:54:30 +0200 Subject: [PATCH] Add bugstogitformatpatch, small helper for moodle work --- bin/bugstogitformatpatch | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 bin/bugstogitformatpatch diff --git a/bin/bugstogitformatpatch b/bin/bugstogitformatpatch new file mode 100755 index 0000000..fd76071 --- /dev/null +++ b/bin/bugstogitformatpatch @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w +=pod + +=head1 NAME + + bugstogitformatpatch + +=head1 DESCRIPTION + + Searches through the given file (or STDIN) for things that look like moodle + bug ids eg MDL-1234, and greps a git log for patches that contain these bug + numbers and generates git patches for them, ready to be applied with git am. + + Needs to be run in the git checkout directory. + +=head1 USAGE + + --grepfile FILE (otherwise STDIN will be used) + --revlist REVLIST eg origin/cvshead (default) or frompoint..topoint or 123abc + --patchdir DIR (must be empty) to write patches to. Default: .patches + --help Print help and then exit + +=head1 AUTHORS + + Penny Leach + +=cut + +use strict; +use warnings; +use Getopt::Long; +use Pod::Usage; + +my $grepfile = undef; +my $revlist = 'origin/cvshead'; +my $patchdir = '.patches'; +my $help = 0; + +GetOptions( + 'grepfile=s', \$grepfile, + 'revlist=s', \$revlist, + 'patchdir=s', \$patchdir, + 'help', \$help, +) or &usage; + +$help && &usage; + +die "Target directory $patchdir was non empty" if (<$patchdir/*>); + +my $bugs; +if ($grepfile) { + $bugs = `grep MDL $grepfile`; + die "No bugs found in $grepfile" unless $bugs; +} else { + my @input; + while (<>) { + push (@input, $_); + } + $bugs = join ('', grep (/MDL/, @input)); + die "No bugs found in file read in STDIN" unless $bugs; +} +$bugs =~ s/.*?(MDL\-\d+).*/$1/g; +$bugs =~ s/\n/\\|/g; +$bugs =~ s/(.*?)..$/$1/; + +if (! -d $patchdir ) { + `mkdir $patchdir`; +} + +my $hashes = `git log --reverse -r $revlist -i --grep="$bugs" | grep ^commit | awk ' { print \$2 } '`; + +my $count = 0; + +my @hashes = split(/\n/, $hashes); + +foreach my $hash (@hashes) { + `git format-patch -o $patchdir --start-number $count $hash^..$hash`; + $count++; +} + +print "wrote $count patches to $patchdir\n"; +exit 0; + +sub usage { + pod2usage( { + -sections => "USAGE", + -exitval => 0, + -verbose => 99, + -output => \*STDOUT, + }); +} -- 2.39.5