How to efficiently find where a patch applies?
From: Nathan W. Panike <hidden>
Date: 2016-06-15 22:51:10
In the past couple weeks, I have had several occasions where a collaborator has
sent a patch, which does not have information about where the patch forked from
master. I wrote the following scripts to try to discover where the patch
should be applied. Is there a better way?
create_awk.pl:
----------------------->8------------------------------------------
#! /usr/bin/env perl
print <<HEADER;
BEGIN {
i = 0
}
HEADER
print "/";
my $numseen=0;
my $nummatches = 0;
while(<STDIN>){
if(/^index ([0-9a-f]+)\.\..+$/){
$hash = $1;
} else {
next;
}
if($hash =~ /^0*$/) {
next;
}
print "|" if($numseen > 0);
$numseen = 1;
++$nummatches;
print "$hash";
}
print "/{ i += 1; print \$0}\n";
print <<FOOTER;
END {
if( i == $nummatches) {
print "FOUND IT";
exit 1;
}
print "i =",i;
exit 0;
}
FOOTER
----------------------->8------------------------------------------
To find the place where the patch applies, I then would run something like
git rev-list --all | \
while read commit; do \
git ls-tree -r $commit | \
awk "$(perl ~/programs/git-hacks/create_awk.pl < <patch file>)" > /dev/null || \
echo $commit; \
done
Nathan Panike