Wednesday, October 17, 2007

The fuzz factor released

Today I've decided to release the patch for bug 199846 - Misuse of the fuzz factor.

Personally, I don't believe that the fuzz factor was never there. I think that because of the fact that nobody was sure how it should work and it wasn't enough documented the fuzz factor somehow evolved into the state we have now. But what does it mean? How was the fuzz factor actually "misused"?

We all work with patches (at least most of us), so we are familiar with the Apply Patch wizard. I'm sure you all noticed the mysterious "Guess" button and the "Maximum fuzz factor" text field. Referring to Eclipse Help doesn't help much. All you can read there about it is : "This factor determines how much the location of the patch in the target file may have changed since the patch was originally generated. The default value is two, but it's not automatically applied. Press the Guess to calculate the fuzz factor that will allow the most hunks to be matched."

Well, you know that it has something to do with the location of the patch and that by pressing the "Guess" a miracle can happen and you will be able to apply the patch. But what happened to the definition of the fuzz factor I mentioned in one of my previous posts. The definition for patch command on Linux man page says: "... [if] the maximum fuzz factor is set to 1 or more, then another scan takes place ignoring the first and last line of context. If that fails, and the maximum fuzz factor is set to 2 or more, the first two and last two lines of context are ignored, and another scan is made."

There is nothing about the patch location there, it's more about context lines, isn't it? The definition from Eclipse Help tries to describe how the fuzz factor is used at this moment - changing the value for the maximum fuzz factor the user was setting how many lines a hunk can be shift up or down in order to be matched. I've heard about people who simply put "999" there and pressed the "Guess" button. This is not the way we would like it to have. According to Michael's suggestion the shifting should be done automatically and the fuzz factor to use should be either selected by the user or guessed (after the "Guess" button has been clicked).

And this is what the patch is all about. From now on, when the user enters a value for the maximum fuzz factor it will define how many context lines will be ignored when applying the patch.

PS. Even though the bug is marked as FIXED there are still some issues related to the patcher. They are all addressed by following bugs: 205761, 205762, 205789 and 206062.