mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-27 17:56:37 -04:00
Let author colors follow a change of gui.authorColors
When the config is reloaded, SetCustomAuthors replaces the styles of authors, but the initials and names that were rendered with the old styles stay cached. So do the pipes of the commit graph; each of them carries the style of the author of the commit it starts at. Drop these whenever the colors of authors change. The graph's cache finds out by itself, by comparing a version number, so that nothing has to remember to reset it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
46761ad2e5
commit
c06233073a
@@ -26,6 +26,8 @@ var (
|
||||
customAuthorStyles = make(map[string]*style.TextStyle)
|
||||
// The styles derived from the names of the other authors
|
||||
authorStyleCache = make(map[string]*style.TextStyle)
|
||||
|
||||
colorsVersion int
|
||||
)
|
||||
|
||||
const authorNameWildcard = "*"
|
||||
@@ -137,4 +139,19 @@ func getInitials(authorName string) string {
|
||||
|
||||
func SetCustomAuthors(customAuthorColors map[string]string) {
|
||||
customAuthorStyles = utils.SetCustomColors(customAuthorColors)
|
||||
colorsChanged()
|
||||
}
|
||||
|
||||
// colorsChanged drops what was rendered with the previous colors of authors.
|
||||
func colorsChanged() {
|
||||
authorInitialCache = make(map[string]string)
|
||||
authorNameCache = make(map[authorNameCacheKey]string)
|
||||
colorsVersion++
|
||||
}
|
||||
|
||||
// ColorsVersion changes whenever the colors of authors change, so that
|
||||
// whatever keeps the styles of authors around can tell when they are out of
|
||||
// date.
|
||||
func ColorsVersion() int {
|
||||
return colorsVersion
|
||||
}
|
||||
|
||||
@@ -55,12 +55,6 @@ func TestAuthorColorsFollowTheConfig(t *testing.T) {
|
||||
assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8))
|
||||
|
||||
SetCustomAuthors(map[string]string{"Jane Doe": "blue"})
|
||||
/* EXPECTED:
|
||||
assert.Equal(t, style.FgBlue.Sprint("JD"), ShortAuthor("Jane Doe"))
|
||||
ACTUAL: */
|
||||
assert.Equal(t, style.FgRed.Sprint("JD"), ShortAuthor("Jane Doe"))
|
||||
/* EXPECTED:
|
||||
assert.Equal(t, style.FgBlue.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8))
|
||||
ACTUAL: */
|
||||
assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8))
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ type pipeSetCacheKey struct {
|
||||
var (
|
||||
pipeSetCache = make(map[pipeSetCacheKey][][]graph.Pipe)
|
||||
mutex deadlock.Mutex
|
||||
|
||||
// The pipes have the colors of the authors of the commits they start at,
|
||||
// so they are only good for as long as these colors don't change
|
||||
pipeSetCacheAuthorColors = authors.ColorsVersion()
|
||||
)
|
||||
|
||||
type bisectBounds struct {
|
||||
@@ -302,6 +306,11 @@ func indexOfFirstNonTODOCommit(commits []*models.Commit) int {
|
||||
}
|
||||
|
||||
func loadPipesets(commits []*models.Commit) [][]graph.Pipe {
|
||||
if pipeSetCacheAuthorColors != authors.ColorsVersion() {
|
||||
pipeSetCache = make(map[pipeSetCacheKey][][]graph.Pipe)
|
||||
pipeSetCacheAuthorColors = authors.ColorsVersion()
|
||||
}
|
||||
|
||||
// given that our cache key is a commit hash and a commit count, it's very important that we don't actually try to render pipes
|
||||
// when dealing with things like filtered commits.
|
||||
cacheKey := pipeSetCacheKey{
|
||||
|
||||
@@ -642,8 +642,5 @@ func TestGraphColorsFollowTheAuthorColors(t *testing.T) {
|
||||
assert.Contains(t, renderGraph(), style.FgRed.Sprint("○"))
|
||||
|
||||
authors.SetCustomAuthors(map[string]string{"Jane Doe": "blue"})
|
||||
/* EXPECTED:
|
||||
assert.Contains(t, renderGraph(), style.FgBlue.Sprint("○"))
|
||||
ACTUAL: */
|
||||
assert.Contains(t, renderGraph(), style.FgRed.Sprint("○"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user