Applying patches to a folder

Ken Moffat zarniwhoop at ntlworld.com
Fri Aug 13 02:05:46 UTC 2021


On Tue, Aug 03, 2021 at 01:27:39PM -0400, Jonathan Moore wrote:
> Hi,
> 
> I have a few patches I would like to apply to a entire folder or directory
> of source files
> when I use bash to try to apply to a folder and I use the asterisk wildcard
> I get an ambiguous redirect to resolve this issue.
> 
> Thank You,
> 
> Jonathan

Since nobody has replied, I guess you've already found out that this
is not how patches work.  A patch changes something in a specific
file to something else.  If you are using a context diff to create
the patch, it will typically apply even if the lines have moved (and
report it applied with some fuzz).

What you *can* do is:

1. Copy ALL the directory, call it 'a' or somename.orig.
2. Copy all of it again, call it 'b' or somename.
3. Change each file in 'b' or 'somename' as required.
4. Go up above this, diff the directories, e.g.
 diff -Naur a b >the-diff
  or
 diff -Naur somename{,orig,} >the-diff
5. You can then apply the-diff with patch -p1 to a future version of
   the directory, but eventually you will need to rediff when patches
   for one or more of the files no-longer apply.

Alternatively, for some changes I guess sed might be the way to go -
if so, make sure you have a copy of the directory before the sed,
and diff them : the results of sed can often change more than was
expected.

ĸen
-- 
Truth, in front of her huge walk-in wardrobe, selected black leather
boots with stiletto heels for such a barefaced truth.
                                     - Unseen Academicals


More information about the freebsd-questions mailing list