Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop-gpui): move a stale zed-cap checkout onto the current GPUI patches
Richie McIlroy3d19c5cfa5e6
diff --git a/scripts/prepare-gpui-dependency.sh b/scripts/prepare-gpui-dependency.shindex 298404074..3ccc9b4c4 100755--- a/scripts/prepare-gpui-dependency.sh+++ b/scripts/prepare-gpui-dependency.sh@@ -3,14 +3,25 @@ set -euo pipefailrepo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"zed_dir="$repo_root/../zed-cap"-patch_files=(- "$repo_root/apps/desktop-gpui/patches/zed-gpui.patch"- "$repo_root/apps/desktop-gpui/patches/zed-windows.patch"- "$repo_root/apps/desktop-gpui/patches/zed-linux.patch"+patch_paths=(+ "apps/desktop-gpui/patches/zed-gpui.patch"+ "apps/desktop-gpui/patches/zed-windows.patch"+ "apps/desktop-gpui/patches/zed-linux.patch")+patch_files=("${patch_paths[@]/#/$repo_root/}")base_revision="5d1f83d9f27a19bec1fb241dc33b42238af9cf8d"remote="https://github.com/wingleeio/zed.git"+copy_patched_paths() {+ local destination="$1" path_list="$2" added removed patched_path+ while IFS=$'\t' read -r -d '' added removed patched_path; do+ if [[ -e "$zed_dir/$patched_path" ]]; then+ mkdir -p "$destination/$(dirname "$patched_path")"+ cp -p "$zed_dir/$patched_path" "$destination/$patched_path"+ fi+ done < "$path_list"+}+verify_checkout() (if ! git -C "$zed_dir" merge-base --is-ancestor "$base_revision" HEAD; thenecho "error: $zed_dir does not contain GPUI base $base_revision" >&2@@ -20,12 +31,7 @@ verify_checkout() (trap 'rm -rf -- "$verification_dir"' EXITgit init --quiet "$verification_dir"git -C "$zed_dir" apply --numstat -z "${patch_files[@]}" > "$verification_dir/patch-paths"- while IFS=$'\t' read -r -d '' added removed patched_path; do- if [[ -e "$zed_dir/$patched_path" ]]; then- mkdir -p "$verification_dir/$(dirname "$patched_path")"- cp -p "$zed_dir/$patched_path" "$verification_dir/$patched_path"- fi- done < "$verification_dir/patch-paths"+ copy_patched_paths "$verification_dir" "$verification_dir/patch-paths"for ((patch_index=${#patch_files[@]}-1; patch_index>=0; patch_index--)); dopatch_file="${patch_files[patch_index]}"if ! git -C "$verification_dir" apply --reverse --unidiff-zero "$patch_file"; then@@ -35,8 +41,78 @@ verify_checkout() (done)+# A checkout prepared before the patches last changed still carries an earlier+# committed version of the stack. When one matches, swap it for the current+# stack on a scratch copy and only write files back once every patch applied.+# Anything else (local edits, a different base) is left for verify to reject.+update_stale_checkout() (+ git -C "$repo_root" rev-parse --verify --quiet HEAD > /dev/null || exit 1+ work_dir="$(mktemp -d "${TMPDIR:-/tmp}/cap-gpui-update.XXXXXX")"+ trap 'rm -rf -- "$work_dir"' EXIT+ revisions="$(git -C "$repo_root" log --format=%H -n 50 -- "${patch_paths[@]}")"+ for revision in $revisions; do+ candidate_dir="$work_dir/$revision"+ mkdir -p "$candidate_dir/patches"+ previous_files=()+ unchanged=1+ for patch_path in "${patch_paths[@]}"; do+ previous_file="$candidate_dir/patches/$(basename "$patch_path")"+ git -C "$repo_root" show "$revision:$patch_path" > "$previous_file" 2> /dev/null || true+ if [[ -s "$previous_file" ]]; then+ previous_files+=("$previous_file")+ fi+ if ! cmp -s "$previous_file" "$repo_root/$patch_path"; then+ unchanged=0+ fi+ done+ if [[ "$unchanged" == 1 || ${#previous_files[@]} == 0 ]]; then+ continue+ fi+ scratch_dir="$candidate_dir/tree"+ git init --quiet "$scratch_dir"+ if ! git -C "$zed_dir" apply --numstat -z "${previous_files[@]}" "${patch_files[@]}" > "$candidate_dir/patch-paths" 2> /dev/null; then+ continue+ fi+ copy_patched_paths "$scratch_dir" "$candidate_dir/patch-paths"+ applied=1+ for ((patch_index=${#previous_files[@]}-1; patch_index>=0; patch_index--)); do+ if ! git -C "$scratch_dir" apply --reverse --unidiff-zero "${previous_files[patch_index]}" 2> /dev/null; then+ applied=0+ break+ fi+ done+ if [[ "$applied" == 1 ]]; then+ for patch_file in "${patch_files[@]}"; do+ if ! git -C "$scratch_dir" apply --unidiff-zero "$patch_file" 2> /dev/null; then+ applied=0+ break+ fi+ done+ fi+ if [[ "$applied" == 0 ]]; then+ continue+ fi+ while IFS=$'\t' read -r -d '' added removed patched_path; do+ if [[ -e "$scratch_dir/$patched_path" ]]; then+ if ! cmp -s "$scratch_dir/$patched_path" "$zed_dir/$patched_path"; then+ mkdir -p "$zed_dir/$(dirname "$patched_path")"+ cp "$scratch_dir/$patched_path" "$zed_dir/$patched_path"+ fi+ elif [[ -e "$zed_dir/$patched_path" ]]; then+ rm -- "$zed_dir/$patched_path"+ fi+ done < "$candidate_dir/patch-paths"+ echo "Updated $zed_dir from Cap's GPUI patches at ${revision:0:12} to the current ones" >&2+ exit 0+ done+ exit 1+)+if [[ -e "$zed_dir/.git" ]]; then- verify_checkout+ if ! verify_checkout 2> /dev/null; then+ update_stale_checkout || true+ verify_checkout+ fiexit 0fidiff --git a/scripts/prepare-gpui-dependency.test.mjs b/scripts/prepare-gpui-dependency.test.mjsindex 1e05556b8..8d786f710 100644--- a/scripts/prepare-gpui-dependency.test.mjs+++ b/scripts/prepare-gpui-dependency.test.mjs@@ -200,4 +200,62 @@ test("dependency verification handles overlapping patches without changing the cassert.equal(existsSync(path.join(zed, "temporary.rs")), true);},);++ git(zed, "apply", path.join(cap, patchDirectory, "zed-linux.patch"));+ git(cap, "init", "--quiet");+ git(cap, "config", "user.name", "Fixture");+ git(cap, "config", "user.email", "[email protected]");+ git(cap, "add", "--all");+ git(cap, "commit", "--quiet", "-m", "Pin first patch stack");+ const windowsPatch = path.join(cap, patchDirectory, "zed-windows.patch");+ const pinWindowsRenderer = (contents) => {+ writeFileSync(+ windowsPatch,+ readFileSync(windowsPatch, "utf8").replace(+ /^\+Windows renderer.*$/m,+ `+${contents}`,+ ),+ );+ git(cap, "commit", "--quiet", "--all", "-m", "Update Windows patch");+ };++ await t.test(+ "a checkout carrying an earlier committed stack moves to the current one",+ () => {+ pinWindowsRenderer("Windows renderer v2");+ const before = fingerprint();+ const result = run(cap, "bash", [script]);+ assert.equal(result.status, 0, result.stderr);+ assert.match(result.stderr, /Updated .* to the current ones/);+ assert.equal(+ readFileSync(path.join(zed, "windows.rs"), "utf8"),+ "Windows renderer v2\n",+ );+ assert.equal(+ readFileSync(path.join(zed, "renderer.rs"), "utf8"),+ "Linux renderer\n",+ );+ assert.equal(existsSync(path.join(zed, "temporary.rs")), false);+ const after = fingerprint();+ assert.deepEqual(after.unrelated, before.unrelated);+ assert.equal(after.head, before.head);+ },+ );++ await t.test(+ "local edits to a patched file are never overwritten by an update",+ () => {+ writeFileSync(path.join(zed, "windows.rs"), "local experiment\n");+ pinWindowsRenderer("Windows renderer v3");+ const before = fingerprint();+ const result = run(cap, "bash", [script]);+ assert.equal(result.status, 1);+ assert.match(result.stderr, /does not contain Cap's pinned GPUI patch/);+ assert.deepEqual(fingerprint(), before);+ assert.equal(+ readFileSync(path.join(zed, "windows.rs"), "utf8"),+ "local experiment\n",+ );+ },+ );});