{"thread":{"id":"65732","subject":"[BUG] t/perf scripts lose GIT_PERF_* when used with --verbose-log","startedAt":"2026-06-02T07:56:47Z","lastAt":"2026-06-02T07:56:47Z","messageCount":1,"participants":["Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"544465","messageId":"20260602075646.GA753532@coredump.intra.peff.net","threadId":"65732","inReplyTo":null,"subject":"[BUG] t/perf scripts lose GIT_PERF_* when used with --verbose-log","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-06-02T07:56:46Z","receivedAt":"2026-06-02T07:56:47Z","isPatch":false,"body":"Imagine I have a perf script like this:\n\n  #!/bin/sh\n  test_description=foo\n  . ./perf-lib.sh\n  echo >&2 \"large_repo = $GIT_PERF_LARGE_REPO\"\n  test_perf_large_repo\n  [...some actual tests...]\n\nIf I run the command below, I'd expect it to use linux.git as the test\nrepo (and print to stderr telling me so). And it does:\n\n  $ GIT_PERF_LARGE_REPO=/path/to/linux.git ./p1234-foo.sh\n  large_repo = /path/to/linux.git\n  [...]\n\nThis is courtesy of 32b74b9809 (perf: do allow `GIT_PERF_*` to be\noverridden again, 2025-04-04). But that breaks if we use --tee or any\nother option which implies it:\n\n  $ GIT_PERF_LARGE_REPO=/path/to/linux.git ./p1234-foo.sh --verbose-log\n  large_repo = /home/peff/compile/git/t/..\n  [...]\n\nWhat happens in the happy path is this:\n\n  0. The script sources perf-lib.sh.\n\n  1. perf-lib.sh stashes GIT_PERF_* in a variable to restore later.\n\n  2. perf-lib.sh sources GIT-BUILD-OPTIONS, which overwrites the\n     environment.\n\n  3. perf-lib.sh sources test-lib.sh.\n\n  4. test-lib.sh itself sources GIT-BUILD-OPTIONS.\n\n  5. Eventually test-lib.sh finishes, returning control to perf-lib.sh.\n\n  6. perf-lib.sh restores GIT_PERF_* from the stashed copy. All is well.\n\nBut if --tee or --verbose-log is used, then step 5 never happens!\nInstead test-lib.sh re-executes a second copy of the script piped to\ntee. And that re-executed copy sees the environment we had after step 4,\nwith all of GIT_PERF_* coming from GIT-BUILD-OPTIONS. So even though it\ntries to do the save/restore, its step 1 never sees the original\nenvironment (so it \"saves\" nothing useful).\n\nThis is especially insidious if you use the \"./run\" program to compare\nversions. It reads GIT-BUILD-OPTIONS, too, and also knows how to\npreserve GIT_PERF_*, courtesy of 79d301c767 (t/perf/run: preserve\nGIT_PERF_* from environment, 2026-01-06). But it reads GIT_TEST_OPTS\nfrom the build-options file and runs each script with it. So while this\nmay work:\n\n  $ GIT_PERF_LARGE_REPO=/path/to/linux.git ./run HEAD p1234-foo.sh\n  [...]\n  === Running 1 tests in /home/peff/compile/git/t/perf/build/1211f0ef99a75931f170bc2a838172a45300ad63/bin-wrappers ===\n  large_repo = /path/to/linux.git\n  [...]\n\nyou may get spooky action at a distance from whenever you last ran make:\n\n  $ make -C ../.. GIT_TEST_OPTS=--verbose-log\n  $ GIT_PERF_LARGE_REPO=/path/to/linux.git ./run HEAD p1234-foo.sh\n  [...]\n  === Running 1 tests in /home/peff/compile/git/t/perf/build/1211f0ef99a75931f170bc2a838172a45300ad63/bin-wrappers ===\n  large_repo = /home/peff/compile/git/t/..\n\nDoubly confusing if that GIT_TEST_OPTS is in your config.mak (because\nyou want normal \"make test\" to run under prove but still keep logs, and\nyou put it in the file ages ago).\n\nI don't think this can be fixed by perf-lib.sh. The problem is internal\nto test-lib.sh, which is overwriting the environment when it sources\nGIT-BUILD-OPTIONS, without any opportunity for perf-lib to act before\ngetting re-executed. It would require test-lib.sh itself to have some\nnotion of \"here are some stashed variables; restore them via eval\".\n\nWhich just feels like stacking band-aids upon band-aids. The original\nproblem started with 4638e8806e (Makefile: use common template for\nGIT-BUILD-OPTIONS, 2024-12-06), though one could argue that even before\nthen the precedence rules were kind of sketchy (it just made things much\nworse because now it crops up even if you don't set GIT_PERF_LARGE_REPO\nin your config.mak at all).\n\nSo I dunno. I couldn't quite bring myself to write a patch, but I\nthought I'd at least write a warning to the list in case anybody else is\nbit by it.\n\n-Peff\n"}]}