git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Nathan W. Panike" <nathan.panike@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: How to efficiently find where a patch applies?
Date: Thu, 5 May 2011 15:55:56 -0400	[thread overview]
Message-ID: <20110505195556.GA1770@sigill.intra.peff.net> (raw)
In-Reply-To: <20110505181741.GA27251@nwp-laptop>

On Thu, May 05, 2011 at 01:17:41PM -0500, Nathan W. Panike wrote:

> 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?

What you have is more or less the best way. As you probably realized,
there could be any number of commits that match the preimage of the diff
exactly. So you are not necessarily finding the fork point, but rather
an appropriate place to apply the patch.

I have to wonder, though, whether it is worth the trouble. If you apply
the patch to your tip, especially using "git am -3", then one of two
things will happen:

  1. The patch will apply cleanly. Either because your tip matched the
     preimage exactly, or because it was close enough and git was able
     to apply anyway.

  2. There are conflicts between what you did and what the patch does.
     In this case, though, what you are doing by searching for the fork
     point will recreate the history locally that your collaborator has.
     But when you go to merge their history, you will end up getting the
     exact same conflicts that you would if you applied to your tip now.

So what is the value in applying their patch to the original fork point?
It better represents the history of what happened. But if you care about
that, I wonder if you should just be pulling from them directly via git
(or if that isn't convenient for some reason, passing around bundles).

> 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

Wow, dynamically generating awk using perl. That's a new one for me. :)

-Peff

  reply	other threads:[~2011-05-05 19:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05 18:17 How to efficiently find where a patch applies? Nathan W. Panike
2011-05-05 19:55 ` Jeff King [this message]
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=20110505195556.GA1770@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=nathan.panike@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).