Bounce WORKTREES model updates onto the UI thread

refreshWorktrees now writes Model.Worktrees in an
onUIThreadUnlessRepoChanged bounce. loadWorktrees becomes a pure loader
that returns the worktrees instead of writing them, since it's shared
with refreshBranches; refreshWorktrees bounces the result, and the
branches call site writes it directly for now (that write moves into
refreshBranches's own bounce when that scope is migrated).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-07-03 14:23:22 +02:00
parent ff7ecf2d2a
commit d6f6d0ceba

View file

@ -719,7 +719,10 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele
self.rebuildPullRequestsMap()
if refreshWorktrees {
self.loadWorktrees()
// TODO: this synchronous worker write goes away when refreshBranches is
// itself migrated to bouncing; for now it matches the rest of this
// not-yet-bounced function.
self.c.Model().Worktrees = self.loadWorktrees()
self.refreshView(self.c.Contexts().Worktrees)
}
@ -959,18 +962,24 @@ func (self *RefreshHelper) refreshRemotes() error {
return nil
}
func (self *RefreshHelper) loadWorktrees() {
func (self *RefreshHelper) loadWorktrees() []*models.Worktree {
worktrees, err := self.c.Git().Loaders.Worktrees.GetWorktrees()
if err != nil {
self.c.Log.Error(err)
self.c.Model().Worktrees = []*models.Worktree{}
} else {
self.c.Model().Worktrees = worktrees
return []*models.Worktree{}
}
return worktrees
}
func (self *RefreshHelper) refreshWorktrees() {
self.loadWorktrees()
generation := self.c.State().GetRepoGeneration()
worktrees := self.loadWorktrees()
self.onUIThreadUnlessRepoChanged(generation, func() error {
self.c.Model().Worktrees = worktrees
return nil
})
// need to refresh branches because the branches view shows worktrees against
// branches