##// END OF EJS Templates
tests: Solaris cmp complains about empty files, even with -s...
Danek Duvall -
r28337:869e65e6 default
parent child Browse files
Show More
@@ -1,58 +1,58 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 # Script to get stable diff output on any platform.
3 # Script to get stable diff output on any platform.
4 #
4 #
5 # Output of this script is almost equivalent to GNU diff with "-Nru".
5 # Output of this script is almost equivalent to GNU diff with "-Nru".
6 #
6 #
7 # Use this script as "hg pdiff" via extdiff extension with preparation
7 # Use this script as "hg pdiff" via extdiff extension with preparation
8 # below in test scripts:
8 # below in test scripts:
9 #
9 #
10 # $ cat >> $HGRCPATH <<EOF
10 # $ cat >> $HGRCPATH <<EOF
11 # > [extdiff]
11 # > [extdiff]
12 # > pdiff = sh "$RUNTESTDIR/pdiff"
12 # > pdiff = sh "$RUNTESTDIR/pdiff"
13 # > EOF
13 # > EOF
14
14
15 filediff(){
15 filediff(){
16 # USAGE: filediff file1 file2 [header]
16 # USAGE: filediff file1 file2 [header]
17
17
18 # compare with /dev/null if file doesn't exist (as "-N" option)
18 # compare with /dev/null if file doesn't exist (as "-N" option)
19 file1="$1"
19 file1="$1"
20 if test ! -f "$file1"; then
20 if test ! -f "$file1"; then
21 file1=/dev/null
21 file1=/dev/null
22 fi
22 fi
23 file2="$2"
23 file2="$2"
24 if test ! -f "$file2"; then
24 if test ! -f "$file2"; then
25 file2=/dev/null
25 file2=/dev/null
26 fi
26 fi
27
27
28 if cmp -s "$file1" "$file2"; then
28 if cmp -s "$file1" "$file2" 2> /dev/null; then
29 # Return immediately, because comparison isn't needed. This
29 # Return immediately, because comparison isn't needed. This
30 # also avoids redundant message of diff like "No differences
30 # also avoids redundant message of diff like "No differences
31 # encountered" (on Solaris)
31 # encountered" (on Solaris)
32 return
32 return
33 fi
33 fi
34
34
35 if test -n "$3"; then
35 if test -n "$3"; then
36 # show header only in recursive case
36 # show header only in recursive case
37 echo "$3"
37 echo "$3"
38 fi
38 fi
39
39
40 # replace "/dev/null" by corresponded filename (as "-N" option)
40 # replace "/dev/null" by corresponded filename (as "-N" option)
41 diff -u "$file1" "$file2" |
41 diff -u "$file1" "$file2" |
42 sed "s@^--- /dev/null\(.*\)\$@--- $1\1@" |
42 sed "s@^--- /dev/null\(.*\)\$@--- $1\1@" |
43 sed "s@^\+\+\+ /dev/null\(.*\)\$@+++ $2\1@"
43 sed "s@^\+\+\+ /dev/null\(.*\)\$@+++ $2\1@"
44 }
44 }
45
45
46 if test -d "$1" -o -d "$2"; then
46 if test -d "$1" -o -d "$2"; then
47 # ensure comparison in dictionary order
47 # ensure comparison in dictionary order
48 (
48 (
49 if test -d "$1"; then (cd "$1" && find . -type f); fi
49 if test -d "$1"; then (cd "$1" && find . -type f); fi
50 if test -d "$2"; then (cd "$2" && find . -type f); fi
50 if test -d "$2"; then (cd "$2" && find . -type f); fi
51 ) |
51 ) |
52 sed 's@^\./@@g' | sort | uniq |
52 sed 's@^\./@@g' | sort | uniq |
53 while read file; do
53 while read file; do
54 filediff "$1/$file" "$2/$file" "diff -Nru $1/$file $2/$file"
54 filediff "$1/$file" "$2/$file" "diff -Nru $1/$file $2/$file"
55 done
55 done
56 else
56 else
57 filediff "$1" "$2"
57 filediff "$1" "$2"
58 fi
58 fi
General Comments 0
You need to be logged in to leave comments. Login now