Merge branch 'as/grep-quiet-no-match-exit-code-fix'
[gitweb.git] / t / perf / perf-lib.sh
index 5cf74eddec7552140c5bef14f23fc637a2ad9818..b50211b2591d19904fa3c995b01aea2121db476a 100644 (file)
@@ -52,6 +52,9 @@ TEST_NO_MALLOC_CHECK=t
 # need to export them for test_perf subshells
 export TEST_DIRECTORY TRASH_DIRECTORY GIT_BUILD_DIR GIT_TEST_CMP
 
+MODERN_GIT=$GIT_BUILD_DIR/bin-wrappers/git
+export MODERN_GIT
+
 perf_results_dir=$TEST_OUTPUT_DIRECTORY/test-results
 mkdir -p "$perf_results_dir"
 rm -f "$perf_results_dir"/$(basename "$0" .sh).subtests
@@ -75,33 +78,57 @@ if test -z "$GIT_PERF_LARGE_REPO"; then
        GIT_PERF_LARGE_REPO=$TEST_DIRECTORY/..
 fi
 
+test_perf_do_repo_symlink_config_ () {
+       test_have_prereq SYMLINKS || git config core.symlinks false
+}
+
 test_perf_create_repo_from () {
        test "$#" = 2 ||
        error "bug in the test script: not 2 parameters to test-create-repo"
        repo="$1"
        source="$2"
-       source_git=$source/$(cd "$source" && git rev-parse --git-dir)
+       source_git="$("$MODERN_GIT" -C "$source" rev-parse --git-dir)"
+       objects_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-path objects)"
        mkdir -p "$repo/.git"
        (
-               cd "$repo/.git" &&
-               { cp -Rl "$source_git/objects" . 2>/dev/null ||
-                       cp -R "$source_git/objects" .; } &&
+               cd "$source" &&
+               { cp -Rl "$objects_dir" "$repo/.git/" 2>/dev/null ||
+                       cp -R "$objects_dir" "$repo/.git/"; } &&
                for stuff in "$source_git"/*; do
                        case "$stuff" in
-                               */objects|*/hooks|*/config)
+                               */objects|*/hooks|*/config|*/commondir)
                                        ;;
                                *)
-                                       cp -R "$stuff" . || exit 1
+                                       cp -R "$stuff" "$repo/.git/" || exit 1
                                        ;;
                        esac
-               done &&
-               cd .. &&
-               git init -q &&
-               mv .git/hooks .git/hooks-disabled 2>/dev/null
+               done
+       ) &&
+       (
+               cd "$repo" &&
+               "$MODERN_GIT" init -q &&
+               test_perf_do_repo_symlink_config_ &&
+               mv .git/hooks .git/hooks-disabled 2>/dev/null &&
+               if test -f .git/index.lock
+               then
+                       # We may be copying a repo that can't run "git
+                       # status" due to a locked index. Since we have
+                       # a copy it's fine to remove the lock.
+                       rm .git/index.lock
+               fi
        ) || error "failed to copy repository '$source' to '$repo'"
 }
 
 # call at least one of these to establish an appropriately-sized repository
+test_perf_fresh_repo () {
+       repo="${1:-$TRASH_DIRECTORY}"
+       "$MODERN_GIT" init -q "$repo" &&
+       (
+               cd "$repo" &&
+               test_perf_do_repo_symlink_config_
+       )
+}
+
 test_perf_default_repo () {
        test_perf_create_repo_from "${1:-$TRASH_DIRECTORY}" "$GIT_PERF_REPO"
 }
@@ -121,11 +148,15 @@ test_checkout_worktree () {
 # Performance tests should never fail.  If they do, stop immediately
 immediate=t
 
+# Perf tests require GNU time
+case "$(uname -s)" in Darwin) GTIME="${GTIME:-gtime}";; esac
+GTIME="${GTIME:-/usr/bin/time}"
+
 test_run_perf_ () {
        test_cleanup=:
        test_export_="test_cleanup"
        export test_cleanup test_export_
-       /usr/bin/time -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+       "$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
        [ $# != 0 ] || return 0