OS2 World Community Forum
OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: karotlopj on June 20, 2016, 01:46:41 pm
-
Can someone remind me how to apply patches? I used to be pretty good at this but have completely lost my way with applying them...
Here is an archive where I'm trying to apply patches:-
http://hobbes.nmsu.edu/download/pub/os2/dev/util/byacc.zip
It contains a patchfile - patches.os2. How do I apply it using gnupatch?
-
Something like,
patch -p0 < foo.patch
or with git type diffs,
patch -p1 < foo.patch
There's also the dry-run option to see if it'll work depending on the -p option and the binary option if you need to preserve eg *nix line breaks,
patch -p0 --binary --dry-run < foo.patch
-
Thanks, Dave. I knew it was fairly straightforward, just couldn't stumble across the correct syntax.
I was looking through some old code from long ago which probably took a couple of days to come up with and looking at it now I have no idea how it works:-
if test -f $PATCHFILE; then
{
patch -p`awk 'BEGIN {
min_p = 1234567
}
$1 == "+++" || $1 == "***" {
gsub (ARCHIVE ".*", "", $2)
gsub (/[^/]/, "", $2)
if (length($2) < min_p) min_p = length($2)
}
END {
print min_p + 1
}' ARCHIVE=$ARCHIVE $PATCHFILE` < $PATCHFILE
}
-
Looks like just dynamically getting the -p value right. The -p is how many parent lines there are, usually 0 or 1