native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #231 from onevcat/sentry-hang

Cache main-worktree flag on Worktree to fix App Hang storm

authored by

Wei Wang and committed by
GitHub
0165c26b 8b477f6a

+76 -1
+9
supacode/Domain/Worktree.swift
··· 7 7 let workingDirectory: URL 8 8 let repositoryRootURL: URL 9 9 let createdAt: Date? 10 + let isMain: Bool 10 11 11 12 nonisolated init( 12 13 id: String, ··· 22 23 self.workingDirectory = workingDirectory 23 24 self.repositoryRootURL = repositoryRootURL 24 25 self.createdAt = createdAt 26 + // Pre-compute the main-worktree flag at construction time so that hot SwiftUI 27 + // paths never call the expensive `URL.standardizedFileURL` getter during view 28 + // updates. The fast equality check covers the common case where callers 29 + // already pass normalized URLs; the standardized fallback protects against 30 + // any future call site that forgets to normalize first. 31 + self.isMain = 32 + workingDirectory == repositoryRootURL 33 + || workingDirectory.standardizedFileURL == repositoryRootURL.standardizedFileURL 25 34 } 26 35 } 27 36
+1 -1
supacode/Features/Repositories/Reducer/RepositoriesFeature.swift
··· 1573 1573 } 1574 1574 1575 1575 func isMainWorktree(_ worktree: Worktree) -> Bool { 1576 - worktree.workingDirectory.standardizedFileURL == worktree.repositoryRootURL.standardizedFileURL 1576 + worktree.isMain 1577 1577 } 1578 1578 1579 1579 func isWorktreeMerged(_ worktree: Worktree) -> Bool {
+66
supacodeTests/WorktreeIsMainTests.swift
··· 1 + import Foundation 2 + import Testing 3 + 4 + @testable import supacode 5 + 6 + @MainActor 7 + struct WorktreeIsMainTests { 8 + @Test func identicalURLsAreMain() { 9 + let root = URL(fileURLWithPath: "/tmp/repo") 10 + let worktree = Worktree( 11 + id: "/tmp/repo", 12 + name: "main", 13 + detail: ".", 14 + workingDirectory: root, 15 + repositoryRootURL: root, 16 + ) 17 + #expect(worktree.isMain == true) 18 + } 19 + 20 + @Test func subdirectoryWorktreeIsNotMain() { 21 + let worktree = Worktree( 22 + id: "/tmp/repo/wt-1", 23 + name: "feature", 24 + detail: "wt-1", 25 + workingDirectory: URL(fileURLWithPath: "/tmp/repo/wt-1"), 26 + repositoryRootURL: URL(fileURLWithPath: "/tmp/repo"), 27 + ) 28 + #expect(worktree.isMain == false) 29 + } 30 + 31 + @Test func siblingWorktreeIsNotMain() { 32 + let worktree = Worktree( 33 + id: "/tmp/repo.wt/feature", 34 + name: "feature", 35 + detail: "../repo.wt/feature", 36 + workingDirectory: URL(fileURLWithPath: "/tmp/repo.wt/feature"), 37 + repositoryRootURL: URL(fileURLWithPath: "/tmp/repo"), 38 + ) 39 + #expect(worktree.isMain == false) 40 + } 41 + 42 + @Test func dotComponentEquivalentURLsAreMain() { 43 + // `/tmp/./repo` and `/tmp/repo` are semantically the same directory. 44 + // The standardization fallback in Worktree.init covers this case even 45 + // if the caller forgot to normalize the URL beforehand. 46 + let worktree = Worktree( 47 + id: "/tmp/repo", 48 + name: "main", 49 + detail: ".", 50 + workingDirectory: URL(fileURLWithPath: "/tmp/./repo"), 51 + repositoryRootURL: URL(fileURLWithPath: "/tmp/repo"), 52 + ) 53 + #expect(worktree.isMain == true) 54 + } 55 + 56 + @Test func dotDotComponentEquivalentURLsAreMain() { 57 + let worktree = Worktree( 58 + id: "/tmp/repo", 59 + name: "main", 60 + detail: ".", 61 + workingDirectory: URL(fileURLWithPath: "/tmp/nested/../repo"), 62 + repositoryRootURL: URL(fileURLWithPath: "/tmp/repo"), 63 + ) 64 + #expect(worktree.isMain == true) 65 + } 66 + }