Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this patch applied with a fuzz of 1, and fail with fuzz of 0?

Tags:

diff

patch

$ vim patch
Index: toPatch
===================================================================
--- toPatch
+++ toPatch
@@ -2,4 +2,4 @@
  */
-final public class XMLWriter {
+public class XMLWriter {

$ vim toPatch
 */
final public class XMLWriter {

  public static float CURRENT_VERSION=2.2f;
    $ patch -p0 -ui patch
patching file toPatch
Hunk #1 succeeded at 1 with fuzz 2 (offset -1 lines).

Why the fuzz and the line offset? This is a demo case trying to understand diff and patch, since tools sometimes/often don't seem to work as expected.

like image 288
simpatico Avatar asked Jun 02 '11 14:06

simpatico


People also ask

What is Patch fuzz?

*What is patch fuzz?* Patch fuzz is a situation when the patch tool ignores some of the context lines in order to apply the patch.

What is Patch hunk?

This means that one or more changes, called hunks, could not be introduced into the file. Occasionally this could be because the patch was emailed or copied into a file and whitespace was either added or removed. Try adding --ignore-whitespace to the command line to work around this.


1 Answers

Patch does some basic checking of consistency of the diff and your file, and if these checks fail, you get offset or fuzz.

You have offset -1, since patch expects the contents of the diff match lines 2--4 of your file. In your file, however, they are lines 1--3.

You have fuzz>0, since the first line of the context (two spaces and a */) does not match the line in the actual file (one space and a */). Because of that, patch did a second pass where it ignored the first and the last line of the context.

This doesn't explain why you see fuzz=2 and not 1. Maybe an error copy-pasting the files? Any other ideas, anybody?

like image 199
xofon Avatar answered Sep 24 '22 03:09

xofon