Hallo Andreas, On Thu, 30 Sep 2010 01:46:48 +0200, Andreas Gruenbacher wrote: > On Wednesday 29 September 2010 18:45:29 Jean Delvare wrote: > > Hi there, > > > > I have attached two versions of a C source GNU diff has a hard time > > diff'ing. The only difference between the two files is that several > > functions have been moved around to avoid forward declarations. But the > > output of "diff -u" is more complex than it should be. While I can > > understand that the algorithm is not perfect and can lead to results > > different from what a human would have done, the following excerpt: > > > > - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) > > - return -ENODEV; > > + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) > > + return -ENODEV; > > > > is obviously wrong, no matter how you look at it. > > > > "diff -ud" gets the correct output. > > But doesn't this already answer your question? Diff doesn't find the minimal > diff when using the fast algorithm which doesn't guarantee optimal results.
No, this doesn't answer my question. While I understand that the fast algorithm isn't guaranteed to find the minimal diff, the specific excerpt I quoted above is not something I consider acceptable. Removing 2 lines to add exactly the same 2 lines immediately doesn't make any sense. The fact that stripping context earlier in both source files causes diff to no longer generate this strange output is also a clear hint that this isn't a fundamental limitation of the fast algorithm, but more likely a corner case which may be fixable. > > Apparently git does as well (I originally received the difference between > > the two files as a git patch.) > > Git 1.7.3.rc2 produces the same, non-minimal result as GNU diff 2.8.7-cvs > without the -d option for me. Odd, as the patch I received originally came from git and looked good. I asked the sender if he had a special configuration setting for patch generation and here is his answer: "Nothing special, really. Currently I am using git verson 1.7.0.87, and format-patch to produce patch files. I had another brief look into the branch with the change; git show also produces clean output." I can't explain why your results are different (remember I'm not so familiar with git.) -- Jean Delvare
