Files
reims-vgpu/scripts/internal/new-worktree.sh
T
Anees Iqbal ed685ef8fb 📝 Build each worktree in its own target/, for kache's seeds [ci skip]
kache 2 seeds a worktree's incremental state from another worktree's only
when both targets sit inside their worktrees: it maps the compiler's working
directory to one path, and a target elsewhere puts a path of its own in the
compiler's arguments. Measured on the M3 Max: with targets inside the
worktrees, a second worktree's first edit of core compiled in 4.3 s from the
first's state, against 7.0 s with no donor; with each target in its own
directory under ~/.cache, the seed identities differed and it took 5.7 s.
So a worktree, which lives under ~/.cache, now builds in its own target/
with no CARGO_TARGET_DIR. Also rewraps a line of the previous commit.
2026-11-03 23:47:28 -08:00

39 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# A new worktree whose large tracked files are APFS clones of the main checkout's, so git writes
# only the files that differ. Its builds run in its own target/ (no CARGO_TARGET_DIR), in the
# environment of scripts/internal/dev-env.sh, which builds through kache where it is installed
# (docs/development.md).
#
# scripts/internal/new-worktree.sh PATH BRANCH [START]
#
# BRANCH is a new branch at START (default: the main checkout's HEAD). tests/suite holds 257 of
# the tree's 278 MiB (its expected and generated files), and a plain `git worktree add` writes
# every byte of it again. Here the main checkout's tests/suite is cloned into PATH first (on
# macOS cp -c, which writes nothing until a file changes; on Linux cp --reflink=auto, a copy
# where the filesystem has no reflinks). git then takes each clone that matches START's blob as
# clean and writes the rest, and the clone's files START does not track are removed, so the
# worktree holds START's tree exactly, whatever the main checkout's files are.
#
# The worktree is added from the main checkout: a new worktree takes the sparse-checkout
# settings of the one it is added from.
set -euo pipefail
[[ $# -ge 2 ]] || { echo "usage: scripts/internal/new-worktree.sh PATH BRANCH [START]" >&2; exit 2; }
path=$1 branch=$2
main=$(git worktree list --porcelain | sed -n '1s/^worktree //p')
start=${3:-$(git -C "$main" rev-parse HEAD)}
big=tests/suite
[[ ! -e $path ]] || { echo "new-worktree: $path exists" >&2; exit 1; }
git -C "$main" worktree add -q --no-checkout -b "$branch" "$path" "$start"
path=$(cd "$path" && pwd)
mkdir -p "$path/$(dirname "$big")"
if [[ $(uname) == Darwin ]]; then
cp -c -p -R "$main/$big" "$path/$big"
else
cp -a --reflink=auto "$main/$big" "$path/$big"
fi
git -C "$path" reset -q
git -C "$path" update-index -q --refresh || true
git -C "$path" checkout -q -- .
git -C "$path" clean -q -f -d -x -- "$big"
echo "new-worktree: $path on $branch at $(git -C "$path" rev-parse --short HEAD)"