Fri 15 Apr 2011 02:05:55 AM UTC, original submission:
Howdy!
As an Ubuntu distribution developer and packager, I often use diff and patch hundreds of times per day. One thing that costed me quite of bit of time, however, was reading the first few lines of a patch file to manually determine the strip level.
Eventually, I decided to wrap patch itself in a shell script that tries each patch level from 0 - 16 with the --dry-run parameter, and if it finds one that works, then it actually uses that strip level and really applies the patch! It's a sort of "do what I mean" approach to patch, that's a little friendlier to deal with.
For bonus points, I also added support to the shell script to detect if the patch argument looked like a URL, then retrieve it via wget before trying to apply it.
I called my shell script "apply-patch", which we're temporarily shipping in the Ubuntu project/package called "bikeshed" (a place for those tools that don't quite fit anywhere else).
Two questions for the great custodians of patch...
1) Would you be willing/interested in accepting a POSIX shell script (and manpage) like this into your patch project? I'll attach both for your review.
2) Alternatively, I spent several hours trying to hack similar support into patch.c and pch.c, but unfortunately, the use of global variables, and lack of any real central, re-entrant point in the code makes it difficult to iterate through a sequence of possible strip levels. But if you would rather see this sort of code go directly into the C source, and you can offer some pointers, I would be happy to work on this.
Cheers,
:-Dustin
|