From the Canyon Edge -- :-Dustin
Showing posts with label apply-patch. Show all posts
Showing posts with label apply-patch. Show all posts

Thursday, April 14, 2011

apply-patch $URL

Two updates about the slick new apply-patch tool in Ubuntu's bikeshed...

First, it now can take a URL as an argument, first retrieving the patch via wget, and then iterating over it and automatically detecting the patch level.

Second, I spent several hours hacking on the source to patch itself, trying to add support for the automatic strip level detection.  I haven't yet succeeded, though, as the iterative approach I use with --dry-run in my wrapper script unfortunately doesn't apply.  There's no reentrant function that I can use over and over again.  Dry-run is a global variable that's either on, or off for the length of the running of the program.  There's special behavior based on the boolean value of dry-run.  Anyway, I have filed a bug with the upstream patch project, showing them what I have, and asking if they have advice on if, and how it might be applied directly into the patch source.  Stay tuned...

:-Dustin

Monday, March 28, 2011

Bikeshed: apply-patch (auto detect strip level and apply the specified patch)

It's been a while since I blogged a Bikeshed post, and I still have plenty of utilities to cover :-)

But this one just made it into Ubuntu Natty (11.04), and my bash history says that I've used it 30+ times already this week...

I think Larry Wall's diff and patch utilities are among the most important programs in all of free software.  These are the most fundamental tools that allow us to modify code, share those modifications with one another in both a human and machine readable format, and apply those changes elsewhere.  It's not uncommon for me to use the two of them more than a hundred times in a work day.

And yet there's two things that bother me about patch...
  1. the -p|--strip parameter should be auto detected, if unspecified
  2. usually, I just want to pass a file in as a parameter using tab-completion, rather than piping it or redirecting it from standard input
So, I'd like to introduce you to the apply-patch utility, which addresses both (1) and (2)!  It takes a patch or a diff file as an argument, and then quietly tries to apply the patch using --dry-run, for -p=0..16, until it finds the correct strip level.  Once it does, it actually applies the patch.

Example:

kirkland@x201:/tmp/foo/patch-2.6$ apply-patch debian/patches/lenny-options 
patching file src/patch.c
patching file patch.man

Useful to anyone besides me?

I'm pretty sure I could hack patch.c and pch.c in the upstream source for patch to do this auto detection of strip level, but I wonder if upstream would take it?


:-Dustin

Printfriendly