bin/169274: [patch] diff exit code always reports "trouble" when there are differences between 2 files

Xin LI delphij at gmail.com
Wed Jun 20 19:20:15 UTC 2012


The following reply was made to PR bin/169274; it has been noted by GNATS.

From: Xin LI <delphij at gmail.com>
To: Garrett Cooper <yanegomi at gmail.com>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: bin/169274: [patch] diff exit code always reports "trouble" when
 there are differences between 2 files
Date: Wed, 20 Jun 2012 12:13:31 -0700

 > $ diff valid.output unittest.dip >/dev/null
 > $ echo $?
 > 2
 
 I tried a few possible permutations and got expected result (when file
 is not accessible I got 2, and otherwise 1), except the case that one
 file is binary.  It's not clear to me whether this is a bug or a
 feature, as our diff(1) does not have a RETURN VALUE section.  With
 your proposed change, diff no longer distinguishes "trouble outputting
 the diff because at least one file is binary and you don't know it"
 and "I know it's binary (--brief) or I know what I am doing (--text),
 just let me know if there is difference", which sounds like a
 regression IMHO.
 
 > The patch attached fixes this logic error and another inconsistency with =
 "magic numbers":
 
 As a rule, cosmetic changes like change in the second one should never
 be applied on contributed code unless they are really broken.
 
 If for a BSD licensed diff maintained by ourselves this would be a
 desirable change.
 
 > $ diff -q /usr/src/contrib/diff/src/diff.c =C2=A0/usr/src/contrib/diff/sr=
 c/diff.c ; echo $?
 > 0
 
 This is expected.
 
 > $ diff -q /usr/src/contrib/diff/src/diff.c =C2=A0/usr/src/contrib/diff/sr=
 c/diff.h ; echo $?
 > Files /usr/src/contrib/diff/src/diff.c and /usr/src/contrib/diff/src/diff=
 .h differ
 > 1
 
 This is expected.
 
 > $ diff -q /usr/src/contrib/diff/src/diff.c =C2=A0/usr/src/contrib/diff/sr=
 c/diff.c~ ; echo $?
 > diff: /usr/src/contrib/diff/src/diff.c~: No such file or directory
 > 2
 
 This is expected.
 
 > $ diff -N /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff=
 .c~ >/dev/null; echo $?
 > 1
 
 This is expected.  What's wrong here?
 
 >>How-To-Repeat:
 > diff /usr/src/contrib/diff/src/diff.c =C2=A0/usr/src/contrib/diff/src/dif=
 f.h >/dev/null
 > ec=3D$?
 > if [ $ec -eq 1 ]
 > then
 > =C2=A0 =C2=A0echo PASS
 > else
 > =C2=A0 =C2=A0echo FAIL
 > fi
 
 I got "PASS" here...
 
 Cheers,
 --=20
 Xin LI <delphij at delphij.net> https://www.delphij.net/
 FreeBSD - The Power to Serve! Live free or die


More information about the freebsd-bugs mailing list