PDA

View Full Version : HOWTO: Patch (discussion)


John Adams
10-11-2006, 06:34 AM
This didn't belong in eq4me's thread about the gcc4.1 patch, but sorta applies to it in general... I want no trout smackinz!!

To the matter...

eq4me, your patch definitely fixes the compile problems I have in FC5 with gcc4.1 - so bravo, thank you for that. However, using "patch < diff.patch" refused to work for me no matter what I did. I saw some lines that might have been broken, thought I fixed them, to no avail. I did go line-by-line and get all the changes in, and compiled successfully. /cheer!

Can I beg for one more scrap of info? Something I have not been able to find here yet is a precise "this is exactly what to type" command for using a patch file to update your local source.

Wikipedia showed me "patch < [patch file name]", but in this case I kept getting errors that it could not find the destination file, and prompted me for the file name. When entering a name, it thought the file was already patched and wanted to revert it (-R). If I did that, it just stopped working.

So here's info I could use, and might help others who have questions about source patching.

- Is there a specific source/destination folder structure needed? (ie, /orig-source, /new-source, etc) or will any old name do?

- What directory must the patch live in? Say, /home/build/patchfile, with the source directories under that?

- Is "patch" the only command line needed, or should we use --strip or other params to apply these diffs?

The end result I am seeking is, take a patch file/post from here, paste it into a file on *NIX, and simply patch the emu source. Thanks in advance for any input or time to explain this to the Linux newbies in the crowd.
J

eq4me
10-11-2006, 08:09 AM
- Is there a specific source/destination folder structure needed? (ie, /orig-source, /new-source, etc) or will any old name do?
No, not really. Any two different directories will do. I just stick to some meaningful names when I generate a patch to have some info.

- What directory must the patch live in? Say, /home/build/patchfile, with the source directories under that?

Where the patchfile is is not relevant you just give the full path to it.

- Is "patch" the only command line needed, or should we use --strip or other params to apply these diffs?

Yes, You have to use the "--strip or "-p" option. Basically it does omit subdirectories from the chunk description.
If you dont use that option patch will omit !any! directory structure. See the snap&paste from the manpage below.

so if you have a chunk like:


--- EQEmu-0.7.0-857/Makefile 2006-10-07 07:22:52.000000000 +0000
+++ EQEmu-0.7.0-857-gcc4.1/Makefile 2006-10-10 08:55:04.084514500 +0000
[...]


an


cd [EQEmu source dir to patch]
patch -p1 < [path/patch file name]


would strip the leading EQEmu-0.7.0-857 and EQEmu-0.7.0-857-gcc4.1 from the chunk description. So patch would try to find ./Makefile and patch it. Provided you are in the top EQEmu source dir that is exactly what you want.

Edit: From the manpage


-pnum or --strip=num
Strip the smallest prefix containing num leading slashes from each
file name found in the patch file. A sequence of one or more adja-
cent slashes is counted as a single slash. This controls how file
names found in the patch file are treated, in case you keep your
files in a different directory than the person who sent out the
patch. For example, supposing the file name in the patch file was

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and not specifying -p at all just gives you blurfl.c. Whatever you
end up with is looked for either in the current directory, or the
directory specified by the -d option.