I recently submitted a patch to Weka to clean up some code formatting. Unfortunately, I didn't think testing the patch was necessary but the maintainer wrote back to tell me it had failed to apply cleanly, with many chunks failing.
I couldn't work out what the issue was. These were incredibly simple changes, changing mixtures of tabs and spaces for indent to spaces, and removing trailing whitespace (two bugbears of mine). Running patch with the verbose switch didn't tell me anything more about why it was failing.
I popped into #habari IRC, where the friendliest and most helpful people I know hang out. Luke from Squareweave suggested that patch might be confused because there were many small changes in one chunk, close together but not contiguous. Investigation showed that the whitespace changes were a red herring, and that any changes would fail. The individual changes would also apply if patched separately. So Luke was right.
To get around the problem, I reduced the context (the number of lines that surround the change) when creating the patch. This forced many of the changes into their own chunks, and the patch applied cleanly.
svn diff --diff-cmd diff -x "-C 1" > whitespace.diff
Subversion's internal diff tool doesn't allow you to change the amount of context, so I use the diff-cmd switch to use the system diff, and the x switch to pass in the necessary diff parameter.
And now the patch has been applied to Weka.