tests/pdiff
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 02 Oct 2019 18:16:02 -0400
changeset 43297 8a2925265402
parent 33611 a2b55ee62803
permissions -rwxr-xr-x
sidedatacopies: fast path data fetching if revision has no sidedata When using the side data mode, we know their won't be any copy information sidedata. Skipping revision restoration give an important speed boost. In the future, there will be other user of sidedata, reducing the efficiency of this. We should consider adding a dedicated flag in revlog V2 to preserve this optimisation. The current situation is good enough for now. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 2.401569 comb 2.400000 user 2.390000 sys 0.010000 (median of 10) after: ! wall 1.429294 comb 1.430000 user 1.410000 sys 0.020000 (median of 10) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 3.519140 comb 3.520000 user 3.470000 sys 0.050000 (median of 10) after: ! wall 1.963332 comb 1.960000 user 1.960000 sys 0.000000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.593880 comb 0.600000 user 0.590000 sys 0.010000 (median of 15) after: ! wall 0.251679 comb 0.250000 user 0.250000 sys 0.000000 (median of 38) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013414 comb 0.020000 user 0.020000 sys 0.000000 (median of 220) after: ! wall 0.013222 comb 0.020000 user 0.020000 sys 0.000000 (median of 223) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.002711 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) after: ! wall 0.001631 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000077 comb 0.000000 user 0.000000 sys 0.000000 (median of 12208) after: ! wall 0.000078 comb 0.000000 user 0.000000 sys 0.000000 (median of 12012) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.410067 comb 0.410000 user 0.410000 sys 0.000000 (median of 23) after: ! wall 0.207786 comb 0.200000 user 0.200000 sys 0.000000 (median of 46) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.097004 comb 0.090000 user 0.090000 sys 0.000000 (median of 100) after: ! wall 0.038495 comb 0.030000 user 0.030000 sys 0.000000 (median of 100) Differential Revision: https://phab.mercurial-scm.org/D7074
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28052
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
#!/bin/sh
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
# Script to get stable diff output on any platform.
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     4
#
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     5
# Output of this script is almost equivalent to GNU diff with "-Nru".
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     6
#
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     7
# Use this script as "hg pdiff" via extdiff extension with preparation
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     8
# below in test scripts:
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     9
#
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    10
#   $ cat >> $HGRCPATH <<EOF
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    11
#   > [extdiff]
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    12
#   > pdiff = sh "$RUNTESTDIR/pdiff"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    13
#   > EOF
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    14
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    15
filediff(){
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    16
    # USAGE: filediff file1 file2 [header]
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    17
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    18
    # compare with /dev/null if file doesn't exist (as "-N" option)
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    19
    file1="$1"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    20
    if test ! -f "$file1"; then
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    21
        file1=/dev/null
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    22
    fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    23
    file2="$2"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    24
    if test ! -f "$file2"; then
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    25
        file2=/dev/null
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    26
    fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    27
28337
869e65e68aee tests: Solaris cmp complains about empty files, even with -s
Danek Duvall <danek.duvall@oracle.com>
parents: 28052
diff changeset
    28
    if cmp -s "$file1" "$file2" 2> /dev/null; then
28052
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    29
        # Return immediately, because comparison isn't needed. This
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    30
        # also avoids redundant message of diff like "No differences
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    31
        # encountered" (on Solaris)
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    32
        return
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    33
    fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    34
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    35
    if test -n "$3"; then
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    36
        # show header only in recursive case
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    37
        echo "$3"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    38
    fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    39
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    40
    # replace "/dev/null" by corresponded filename (as "-N" option)
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    41
    diff -u "$file1" "$file2" |
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    42
    sed "s@^--- /dev/null\(.*\)\$@--- $1\1@" |
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    43
    sed "s@^\+\+\+ /dev/null\(.*\)\$@+++ $2\1@"
33611
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    44
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    45
    # in this case, files differ from each other
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    46
    return 1
28052
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    47
}
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    48
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    49
if test -d "$1" -o -d "$2"; then
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    50
    # ensure comparison in dictionary order
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    51
    (
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    52
    if test -d "$1"; then (cd "$1" && find . -type f); fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    53
    if test -d "$2"; then (cd "$2" && find . -type f); fi
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
    ) |
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    55
    sed 's@^\./@@g' | sort | uniq |
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    56
    while read file; do
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    57
        filediff "$1/$file" "$2/$file" "diff -Nru $1/$file $2/$file"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    58
    done
33611
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    59
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    60
    # TODO: there is no portable way for current while-read based
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    61
    # implementation to return 1 at detecting changes.
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    62
    #
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    63
    # On bash and dash, assignment to variable inside while-block
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    64
    # doesn't affect outside, because inside while-block is executed
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    65
    # in sub-shell. BTW, it affects outside while-block on ksh (as sh
a2b55ee62803 tests: make pdiff return appropriate exit code at comparison of files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28337
diff changeset
    66
    # on Solaris).
28052
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    67
else
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    68
    filediff "$1" "$2"
b59ef0c21405 tests: use portable diff script via extdiff extension
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    69
fi