mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-07 13:42:01 +02:00
Make common.UserConfig an atomic.Pointer for safe concurrent access
Currently, userConfig is only read once at startup and then never changes. Later in this branch, we will add the possibility to reload the user config; this can happen either when switching repositories, or when the user has edited the config file. In both cases, reloading happens on the main thread, but the user config could be accessed concurrently from background threads, so we need to make this safe.
This commit is contained in:
parent
f98b57aa5e
commit
d6d48f2866
@ -1,6 +1,8 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -11,7 +13,7 @@ import (
|
||||
type Common struct {
|
||||
Log *logrus.Entry
|
||||
Tr *i18n.TranslationSet
|
||||
userConfig *config.UserConfig
|
||||
userConfig atomic.Pointer[config.UserConfig]
|
||||
AppState *config.AppState
|
||||
Debug bool
|
||||
// for interacting with the filesystem. We use afero rather than the default
|
||||
@ -20,9 +22,9 @@ type Common struct {
|
||||
}
|
||||
|
||||
func (c *Common) UserConfig() *config.UserConfig {
|
||||
return c.userConfig
|
||||
return c.userConfig.Load()
|
||||
}
|
||||
|
||||
func (c *Common) SetUserConfig(userConfig *config.UserConfig) {
|
||||
c.userConfig = userConfig
|
||||
c.userConfig.Store(userConfig)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user