[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Add --with-diffutils option

From: Justin Erenkrantz <jerenkrantz_at_apache.org>
Date: 2002-12-13 05:34:31 CET

Currently, it is not possible to specify which diff/diff3 combination
should be used by Subversion. You must manually tweak your path in
order to do this. We should be allowing --with-diffutils as an
option. Therefore, I'd really like to see this patch make it in.

I also reworked all of the diffutils detection to be a m4 macro
rather than relying upon shell scripts. This is a much better fit
with the rest of our autoconf code than it was previously.

Any concerns? This works in all combinations I can test. If no one
objects, I will commit tomorrow. -- justin

Allow user to specify --with-diffutils to indicate where their
diff/diff3
should be detected. If this option is not specified, use PATH as a
starting point. Rework diff shell script detection as m4 macro.

* configure.in: Include ac-helpers/gnu-diff.m4. Replace custom
diffutils
code with the SVN_LIB_DIFFUTILS() m4 macro in ac-helpers/gnu-diff.m4

* ac-helpers/gnu-diff3.sh, ac-helpers/check-diff.sh: Removed

* ac-helpers/gnu-diff.m4: Added

Index: configure.in
===================================================================
--- configure.in (revision 4085)
+++ configure.in (working copy)
@@ -52,6 +52,7 @@
 sinclude(ac-helpers/find_apu.m4)
 sinclude(ac-helpers/aprutil.m4)
 sinclude(ac-helpers/swig.m4)
+sinclude(ac-helpers/gnu-diff.m4)

 dnl Grab the libtool macros
 sinclude(ac-helpers/libtool.m4)
@@ -289,51 +290,8 @@
   fi
 fi

-dnl Find a diff that supports the "-u" flag
-AC_MSG_CHECKING([for diff])
-SVN_CLIENT_DIFF="`${abs_srcdir}/ac-helpers/check-diff.sh
${abs_srcdir}/ac-helpers`"
-if test "$SVN_CLIENT_DIFF" = ""; then
- AC_MSG_ERROR([not found
-
-Cannot find a diff in your PATH that supports the -u flag.
-We recommend GNU diff (version 2.7 or later).
-You can get it from ftp://ftp.gnu.org/pub/gnu/diffutils.
- ])
- fi
-AC_MSG_RESULT([$SVN_CLIENT_DIFF])
-AC_DEFINE_UNQUOTED(SVN_CLIENT_DIFF, "$SVN_CLIENT_DIFF",
- [Define to be the full path to diff])
-
-dnl Find a (non-broken) version of GNU diff3
-AC_MSG_CHECKING([for non-broken GNU diff3])
-SVN_CLIENT_DIFF3="`$SHELL ${abs_srcdir}/ac-helpers/gnu-diff3.sh
${abs_srcdir}/ac-helpers`"
-if test "$SVN_CLIENT_DIFF3" = ""; then
- AC_MSG_ERROR([not found
-
-Cannot find an unbroken GNU diff3 program in your PATH.
-Please make sure you have GNU diff (version 2.7 or later) installed.

-You can get it from ftp://ftp.gnu.org/pub/gnu/diffutils.
-
-(Note that FreeBSD uses a modified version of GNU diff that is unable
-to handle certain types of text files. Since diff3 uses GNU diff to
do
-the actual diffing, this effectively breaks diff3 as well. If you
are
-using FreeBSD, please install the /usr/ports/textproc/diffutils
port.)
-])
-fi
-AC_MSG_RESULT([$SVN_CLIENT_DIFF3])
-AC_DEFINE_UNQUOTED(SVN_CLIENT_DIFF3, "$SVN_CLIENT_DIFF3",
- [Define to be the full path to your GNU diff3 program])
-
-dnl Determine whether diff3 supports the --diff-program arg.
-AC_MSG_CHECKING([whether diff3 supports --diff-program arg])
-$SVN_CLIENT_DIFF3 --diff-program=$SVN_CLIENT_DIFF ${0} ${0} ${0} >
/dev/null 2>&1
-if test "$?" = "0"; then
- AC_MSG_RESULT([yes])
- AC_DEFINE_UNQUOTED(SVN_DIFF3_HAS_DIFF_PROGRAM_ARG, 1,
- [Defined if diff3 supports the --diff-program argument])
-else
- AC_MSG_RESULT([no])
-fi
+dnl Find suitable diff utilities
+SVN_LIB_DIFFUTILS(${abs_srcdir}/ac-helpers)

 dnl Since this is used only on Unix-y systems, define the path
separator as '/'
 AC_DEFINE_UNQUOTED(SVN_PATH_LOCAL_SEPARATOR, '/',
Index: ac-helpers/gnu-diff3.sh
===================================================================
--- ac-helpers/gnu-diff3.sh (working copy)
+++ ac-helpers/gnu-diff3.sh (working copy)
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-### Search through $PATH for a binary called 'diff3' or 'gdiff3'
which
-### does not add spurious trailing newlines to its output. Print the
-### full path to a working diff3 binary, or "" if none is found.
-
-### This script assumes $1 is a directory that contains particular
-### 'mine.txt', 'yours.txt', 'older.txt', and 'result.txt' files
-### needed to test merging.
-
-if test "$1" = ""; then
- echo "usage: gnu-diff3.sh <directory containing merge-testfiles>"
- exit 1
-fi
-dir=$1
-
-IFS=':'
-for searchdir in $PATH; do
- # does $searchdir contain an executable called either `gdiff3'
or `diff3'?
- for name in gdiff3 diff3; do
- diff3=$searchdir/$name
- if test -x $diff3; then
- $diff3 -A -m $dir/mine.txt $dir/older.txt $dir/yours.txt
> result
-
- # the actual and expected merge result-files should be the same.
- if cmp -s $dir/result.txt result; then
- identical=yes
- else
- identical=no
- fi
-
- # cleanup
- rm -f result
-
- if test "$identical" = "yes"; then
- echo $diff3
- exit
- fi
- fi
- done
-done
-
-# failed to find a valid diff3
-echo ""
Index: ac-helpers/check-diff.sh
===================================================================
--- ac-helpers/check-diff.sh (working copy)
+++ ac-helpers/check-diff.sh (working copy)
@@ -1,85 +0,0 @@
-#! /bin/sh
-
-# This test searches $PATH for a version of `diff' that supports -u.
-#
-# Usage: gnu-diff.sh AC-HELPERS-DIR
-#
-# The argument AC-HELPERS-DIR is required. It tells check-diff.sh
-# where to find its test input files.
-#
-# Output: either prints the full path of valid `diff' program,
-# or "" if none is found.
-#
-
-if test "$1" = ""; then
- echo "usage: check-diff.sh <ac-helpers-dir>"
- exit 1
-fi
-
-input_1=${1}/check-diff-input-1.txt
-input_2=${1}/check-diff-input-2.txt
-output=${1}/check-diff-output.tmp
-
-# Loop over $PATH, looking for `diff' binaries
-
-IFS=':'
-
-for searchdir in $PATH; do
- # does $searchdir contain an executable called either `gdiff' or
`diff'?
- for name in gdiff diff; do
- diff=$searchdir/$name
- if test -x $diff; then
- # Make absolutely sure there's no output file yet.
- rm -f ${output}
-
- $diff -u ${input_1} ${input_2} > ${output} 2>/dev/null
-
- # If there's an output file with non-zero size, then this
- # diff supported the "-u" flag, so we're done.
- if [ -s ${output} ]; then
- foundit=yes
- else
- foundit=no
- fi
-
- ################ Note: How To Test For GNU Diff:
#################
- #
#
- # Right now, we only test that diff supports "-u", which
is all #
- # we care about ("svn diff" passes -u by default). But
if we #
- # someday want pure GNU diff again, it's an easy tweak
to make. #
- # Just use a construction similar to the if-else-fi
above, but #
- # change the condition to:
#
- #
#
- # grep "\\ No newline at end of file" ${output} >
/dev/null 2>&1 #
- #
#
- # (There are options to suppress grep's output, but who
#
- # knows how portable they are, so just redirect
instead.) #
- #
#
- # This will test for a non-broken GNU diff, because the
#
- # input files are constructed to set off the special
#
- # handling GNU diff has for files that don't end with
\n. #
- #
#
- # Why would we care? Well, we used to check very
carefully for #
- # a non-broken version of GNU diff, because at that time
we #
- # used `diff' not `diff3' for updates. On FreeBSD,
there was #
- # a version of GNU diff that had been modified to remove
the #
- # special support for files that don't end in \n.
#
- #
#
- # Don't ask my why, but somehow I think there's a chance
we #
- # might one day again need GNU diff on the client side.
If that #
- # ever happens, remember to read this note. :-)
#
- #
#
-
##################################################################
-
- # Clean up
- rm -f ${output}*
-
- if test "$foundit" = "yes"; then
- echo $diff
- exit
- fi
- fi
- done
-done
-
-echo ""
Index: ac-helpers/gnu-diff.m4
===================================================================
--- ac-helpers/gnu-diff.m4 (working copy)
+++ ac-helpers/gnu-diff.m4 (working copy)
@@ -0,0 +1,147 @@
+dnl
+dnl SVN_LIB_DIFFUTILS(mergefiles_dir)
+dnl
+dnl Set of autoconf tests to detect the appropriate diff/diff3
combinations.
+dnl
+dnl Looks for a 'diff'/'gdiff' or 'diff3'/'gdiff3'
+dnl
+dnl This script assumes $1 is a directory that contains particular
+dnl 'mine.txt', 'yours.txt', 'older.txt', and 'result.txt' files
+dnl needed to test merging.
+dnl
+
+AC_DEFUN(SVN_LIB_DIFFUTILS,
+[
+ AC_ARG_WITH(diffutils,
+ AC_HELP_STRING([--with-diffutils=PREFIX],
+ [prefix for installed GNU diffutils]),
+ [
+ if test "$withval" = "yes" ; then
+ AC_MSG_ERROR([--with-diffutils requires an argument.])
+ else
+ diffutils_path="$withval/bin"
+ fi
+ ],[
+ diffutils_path=$PATH
+ ])
+
+ helper_dir=$1
+
+ dnl Check for a diff that supports the -u flag
+
+ input_1=$helper_dir/check-diff-input-1.txt
+ input_2=$helper_dir/check-diff-input-2.txt
+ output=$helper_dir/check-diff-output.tmp
+
+ dnl Looking for `diff' binaries
+ AC_PATH_PROGS(SVN_CLIENT_DIFF, [gdiff diff], [none],
[$diffutils_path])
+
+ if test "$SVN_CLIENT_DIFF" = "none" ; then
+ SVN_DOWNLOAD_DIFF()
+ fi
+
+ dnl Make absolutely sure there's no output file yet.
+ rm -f $output
+
+ $SVN_CLIENT_DIFF -u $input_1 $input_2 > $output 2>/dev/null
+
+ dnl If there's an output file with non-zero size, then this
+ dnl diff supported the "-u" flag, so we're done.
+ if test ! -s $output ; then
+ # Clean up
+ rm -f $output*
+ SVN_DOWNLOAD_DIFF()
+ fi
+
+ # Clean up
+ rm -f $output*
+
+ dnl Note: How To Test For GNU Diff:
+ dnl
+ dnl Right now, we only test that diff supports "-u", which is all
+ dnl we care about ("svn diff" passes -u by default). But if we
+ dnl someday want pure GNU diff again, it's an easy tweak to make.
+ dnl Just use a construction similar to the if-else-fi above, but
+ dnl change the condition to:
+ dnl
+ dnl grep "\\ No newline at end of file" ${output} > /dev/null 2>&1
+ dnl
+ dnl (There are options to suppress grep's output, but who
+ dnl knows how portable they are, so just redirect instead.)
+ dnl
+ dnl This will test for a non-broken GNU diff, because the
+ dnl input files are constructed to set off the special
+ dnl handling GNU diff has for files that don't end with \n.
+ dnl
+ dnl Why would we care? Well, we used to check very carefully for
+ dnl a non-broken version of GNU diff, because at that time we
+ dnl used `diff' not `diff3' for updates. On FreeBSD, there was
+ dnl a version of GNU diff that had been modified to remove the
+ dnl special support for files that don't end in \n.
+ dnl
+ dnl Don't ask my why, but somehow I think there's a chance we
+ dnl might one day again need GNU diff on the client side. If that
+ dnl ever happens, remember to read this note. :-)
+
+ AC_DEFINE_UNQUOTED(SVN_CLIENT_DIFF, "$SVN_CLIENT_DIFF",
+ [Define to be the full path to diff])
+
+ dnl Looking for `diff3' binaries
+ AC_PATH_PROGS(SVN_CLIENT_DIFF3, [gdiff3 diff3], [none],
[$diffutils_path])
+
+ if test "$SVN_CLIENT_DIFF3" = "none" ; then
+ SVN_DOWNLOAD_DIFF3()
+ fi
+
+ dnl Check whether diff3 supports --diff-program arg
+ AC_MSG_CHECKING([whether diff3 supports --diff-program arg])
+ $SVN_CLIENT_DIFF3 --diff-program=$SVN_CLIENT_DIFF ${0} ${0} ${0} >
/dev/null 2>&1
+ if test "$?" = "0"; then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE_UNQUOTED(SVN_DIFF3_HAS_DIFF_PROGRAM_ARG, 1,
+ [Defined if diff3 supports the --diff-program
argument])
+ diff3_arg="--diff-program=$SVN_CLIENT_DIFF"
+ else
+ AC_MSG_RESULT([no])
+ diff3_arg=""
+ fi
+
+ $SVN_CLIENT_DIFF3 $diff3_arg -A -m $helper_dir/mine.txt
$helper_dir/older.txt $helper_dir/yours.txt > result 2> /dev/null
+
+ # the actual and expected merge result-files should be the same.
+ cmp -s $helper_dir/result.txt result
+ if test "$?" != "0"; then
+ # cleanup
+ rm -f result
+ SVN_DOWNLOAD_DIFF3()
+ fi
+
+ # cleanup
+ rm -f result
+
+ AC_DEFINE_UNQUOTED(SVN_CLIENT_DIFF3, "$SVN_CLIENT_DIFF3",
+ [Define to be the full path to diff])
+])
+
+AC_DEFUN(SVN_DOWNLOAD_DIFF,
+[
+AC_MSG_ERROR([Suitable diff not found.
+
+Cannot find a diff that supports the -u flag.
+We recommend GNU diff (version 2.7 or later).
+You can get it from ftp://ftp.gnu.org/pub/gnu/diffutils.])
+])
+
+AC_DEFUN(SVN_DOWNLOAD_DIFF3,
+[
+AC_MSG_ERROR([Suitable diff3 not found.
+
+Cannot find an unbroken GNU diff3.
+Please make sure you have GNU diff (version 2.7 or later) installed.
+You can get it from ftp://ftp.gnu.org/pub/gnu/diffutils.
+
+(Note that FreeBSD uses a modified version of GNU diff that is unable
+to handle certain types of text files. Since diff3 uses GNU diff to
do
+the actual diffing, this effectively breaks diff3 as well. If you
are
+using FreeBSD, please install the /usr/ports/textproc/diffutils
port.)])
+])

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Dec 13 05:35:16 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.