bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

diff3 and --horizon-lines


From: Greg Hudson
Subject: diff3 and --horizon-lines
Date: Tue, 12 Feb 2002 18:28:28 -0500

Hi.  I have been noticing poor merge results in CVS and have tracked
the problem down to diff3.  The problem is that for some files, "diff3
a a b" can produce conflicts.  For instance, using diff 2.7:

  equal-rites% diff3 -Em a a b | grep -c '<<<<<'
  11
  equal-rites% diff3 --version
  diff3 - GNU diffutils version 2.7

Using diffutils 2.7.2 (I have no idea what this actually is; Red Hat
distributes it in its diffutils RPM for diffutils 2.7.2, and I
compiled it myself from the source tarball in the SRPM, but
ftp.gnu.org only has version 2.7), I still get conflicts, though a
different number of them:

  equal-rites% /tmp/diff/bin/diff3 -Em a a b | grep -c '<<<<<'
  13
  equal-rites% /tmp/diff/bin/diff3 --version
  diff3 (GNU diffutils) 2.7.2
  Copyright 1988, 89, 92, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.

  This program comes with NO WARRANTY, to the extent permitted by law.
  You may redistribute copies of this program
  under the terms of the GNU General Public License.
  For more information about these matters, see the file named COPYING.

  Written by Randy Smith.

I have stashed the files "a" and "b" away in
http://web.mit.edu/ghudson/info/diff3-bug; if people would like me to
send them here I'd be happy to, but since a is 197K and b is 93K, I
thought I should just send a pointer until told otherwise.  (I don't
know how to narrow down the bug to simpler files.)

I have done a little debugging on diff3 (using the diffutils 2.7.2
code), and the problem seems to be that diff3 invokes:

  diff --horizon-lines=10 --inhibit-hunk-merge -- a b

to get the first diff; then it pokes around in that diff, computes a
horizon_lines value of 158, and invokes:

  diff --horizon-lines=158 --inhibit-hunk-merge -- a b

for the second diff.  Because of the different value of
--horizon-lines, diff produces different (though still correct)
output, and the diff3 merge algorithm isn't smart enough to recognize
the equivalence, so it produces conflicts.  I don't really understand
how --horizon-lines works in diff, but from the documentation, it's
not surprising that diff would produce different output with different
values.  (In this case, the larger horizon-lines value results in a
bigger diff--5354 lines versus 4863 lines--but I couldn't say why.)

Why is diff3 fiddling around with the --horizon-lines option?

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]