From 6d21efb515f9e5850d30821fee35c71fda560ca2 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Jul 2026 09:57:49 +0200 Subject: [PATCH] Make the local-commits limit-commits flag atomic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CheckoutRef and ResetToRef set this flag from their worker goroutine (to load fewer commits for speed) while the commits refresh reads it on the UI thread in captureCommitsState to decide how many to load — a data race. Make it an atomic.Bool so those writes are safe where they are, rather than routing the flag through a refresh intent. Precedent: Branch.BehindBaseBranch. --- pkg/gui/context/local_commits_context.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 056035cce..d929aca88 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "strings" + "sync/atomic" "time" "github.com/jesseduffield/lazygit/pkg/commands/models" @@ -142,7 +143,9 @@ type LocalCommitsViewModel struct { // If this is true we limit the amount of commits we load, for the sake of keeping things fast. // If the user attempts to scroll past the end of the list, we will load more commits. - limitCommits bool + // Atomic because a checkout or reset sets it from a worker goroutine while the + // commits refresh reads it on the UI thread to decide how many commits to load. + limitCommits atomic.Bool // If this is true we'll use git log --all when fetching the commits. showWholeGitGraph bool @@ -151,9 +154,9 @@ type LocalCommitsViewModel struct { func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel { self := &LocalCommitsViewModel{ ListViewModel: NewListViewModel(getModel), - limitCommits: true, showWholeGitGraph: c.UserConfig().Git.Log.ShowWholeGraph, } + self.limitCommits.Store(true) return self } @@ -225,11 +228,11 @@ func (self *LocalCommitsContext) ModelSearchResults(searchStr string, caseSensit } func (self *LocalCommitsViewModel) SetLimitCommits(value bool) { - self.limitCommits = value + self.limitCommits.Store(value) } func (self *LocalCommitsViewModel) GetLimitCommits() bool { - return self.limitCommits + return self.limitCommits.Load() } func (self *LocalCommitsViewModel) SetShowWholeGitGraph(value bool) {