git/list[1] front-page[2] threads[3] people[4] search[5] about
 

How to efficiently find where a patch applies?

From
Nathan W. Panike <nathan.panike@gmail.com>
Date
May 5, 2011, 18:17 UTC
Message-ID
<20110505181741.GA27251@nwp-laptop>

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
Next: Jeff King
Message 1 of 4 in “How to efficiently find where a patch applies?”
  1. Nathan W. PanikeMay 5, 2011
  2. Jeff KingMay 5, 2011
  3. Nathan W. PanikeMay 5, 2011
  4. Jeff KingMay 5, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.