OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: karotlopj on June 20, 2016, 01:46:41 pm

Title: Patch
Post 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?
Title: Re: Patch
Post by: Dave Yeo on June 20, 2016, 04:33:01 pm
Something like,
Code: [Select]
patch -p0 < foo.patchor with git type diffs,
Code: [Select]
patch -p1 < foo.patchThere'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,
Code: [Select]
patch -p0 --binary --dry-run < foo.patch
Title: Re: Patch
Post by: karotlopj on June 20, 2016, 05:20:11 pm
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:-

Quote
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

}
Title: Re: Patch
Post by: Dave Yeo on June 21, 2016, 01:02:28 am
Looks like just dynamically getting the -p value right. The -p is how many parent lines there are, usually 0 or 1