Git development
 help / color / mirror / Atom feed
From: "Nathan W. Panike" <nathan.panike@gmail.com>
To: git@vger.kernel.org
Subject: How to efficiently find where a patch applies?
Date: Thu, 5 May 2011 13:17:41 -0500	[thread overview]
Message-ID: <20110505181741.GA27251@nwp-laptop> (raw)

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

             reply	other threads:[~2011-05-05 18:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05 18:17 Nathan W. Panike [this message]
2011-05-05 19:55 ` How to efficiently find where a patch applies? Jeff King
2011-05-05 20:12   ` Nathan W. Panike
2011-05-05 20:17     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110505181741.GA27251@nwp-laptop \
    --to=nathan.panike@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox