Skip to content

Commit f9eeaa5

Browse files
author
Cameron Way
committed
Move to LogConfig, and configurable at runtime
1 parent 635bc7d commit f9eeaa5

File tree

11 files changed

+78
-15
lines changed

11 files changed

+78
-15
lines changed

docs/Config.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ gui:
208208
# If true, show jump-to-window keybindings in window titles.
209209
showPanelJumps: true
210210

211-
# If true, show tags alognside commit summary in the commits view.
212-
showCommitTags: true
213-
214211
# Nerd fonts version to use.
215212
# One of: '2' | '3' | empty string (default)
216213
# If empty, do not show icons.

pkg/commands/git_commands/commit_loader.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
213213
message := split[7]
214214

215215
tags := []string{}
216+
if self.AppState.GitLogShowTags == "never" {
217+
extraInfo = regexp.MustCompile(`tag: [^,]+,?\s*`).ReplaceAllString(extraInfo, "")
218+
}
216219

217220
if extraInfo != "" {
218221
extraInfoFields := strings.Split(extraInfo, ",")

pkg/config/app_config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func NewAppConfig(
117117
if appState.GitLogShowGraph == "" {
118118
appState.GitLogShowGraph = userConfig.Git.Log.ShowGraph
119119
}
120+
if appState.GitLogShowTags == "" {
121+
appState.GitLogShowTags = userConfig.Git.Log.ShowTags
122+
}
120123

121124
appConfig := &AppConfig{
122125
name: name,
@@ -691,6 +694,9 @@ type AppState struct {
691694
// This determines whether the git graph is rendered in the commits panel
692695
// One of 'always' | 'never' | 'when-maximised'
693696
GitLogShowGraph string
697+
// This determines whether the git graph is rendered in the commits panel
698+
// One of 'always' | 'never' | 'when-maximised'
699+
GitLogShowTags string
694700
}
695701

696702
func getDefaultAppState() *AppState {
@@ -705,6 +711,7 @@ func getDefaultAppState() *AppState {
705711
RemoteBranchSortOrder: "alphabetical",
706712
GitLogOrder: "", // should be "topo-order" eventually
707713
GitLogShowGraph: "", // should be "always" eventually
714+
GitLogShowTags: "", // should be "always" eventually
708715
}
709716
}
710717

pkg/config/app_config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ git:
701701
# displays the whole git graph by default in the commits view (equivalent to passing the --all argument to git log)
702702
showWholeGraph: false
703703
704+
# Configure this with Log menu -> 'Show commit tags' (<c-l> in the commits window by default).
705+
showTags: always
706+
704707
# When copying commit hashes to the clipboard, truncate them to this
705708
# length. Set to 40 to disable truncation.
706709
truncateCopiedCommitHashesTo: 12

pkg/config/user_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ type GuiConfig struct {
137137
ShowPanelJumps bool `yaml:"showPanelJumps"`
138138
// Deprecated: use nerdFontsVersion instead
139139
ShowIcons bool `yaml:"showIcons" jsonschema:"deprecated"`
140-
// If true, show tags alognside commit summary in the commits view.
141-
ShowCommitTags bool `yaml:"showCommitTags"`
142140
// Nerd fonts version to use.
143141
// One of: '2' | '3' | empty string (default)
144142
// If empty, do not show icons.
@@ -339,6 +337,8 @@ type LogConfig struct {
339337
ShowGraph string `yaml:"showGraph" jsonschema:"deprecated,enum=always,enum=never,enum=when-maximised"`
340338
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
341339
ShowWholeGraph bool `yaml:"showWholeGraph"`
340+
// Configure this with `Log menu -> Show tags` (<c-l> in the commits window by default).
341+
ShowTags string `yaml:"showTags" jsonschema:"enum=always,enum=never,enum=when-maximised"`
342342
}
343343

344344
type CommitPrefixConfig struct {
@@ -772,7 +772,6 @@ func GetDefaultConfig() *UserConfig {
772772
ShowNumstatInFilesView: false,
773773
ShowRandomTip: true,
774774
ShowIcons: false,
775-
ShowCommitTags: true,
776775
NerdFontsVersion: "",
777776
ShowFileIcons: true,
778777
CommitAuthorShortLength: 2,
@@ -818,6 +817,7 @@ func GetDefaultConfig() *UserConfig {
818817
Order: "topo-order",
819818
ShowGraph: "always",
820819
ShowWholeGraph: false,
820+
ShowTags: "always",
821821
},
822822
SkipHookPrefix: "WIP",
823823
MainBranches: []string{"master", "main"},

pkg/gui/context/local_commits_context.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
6161
startIdx,
6262
endIdx,
6363
shouldShowGraph(c),
64+
shouldShowTags(c),
6465
c.Model().BisectInfo,
6566
)
6667
}
@@ -247,12 +248,18 @@ func (self *LocalCommitsViewModel) GetCommits() []*models.Commit {
247248
}
248249

249250
func shouldShowGraph(c *ContextCommon) bool {
251+
return shouldShowBasedOnAppState(c, c.GetAppState().GitLogShowGraph)
252+
}
253+
254+
func shouldShowTags(c *ContextCommon) bool {
255+
return shouldShowBasedOnAppState(c, c.GetAppState().GitLogShowTags)
256+
}
257+
258+
func shouldShowBasedOnAppState(c *ContextCommon, value string) bool {
250259
if c.Modes().Filtering.Active() {
251260
return false
252261
}
253262

254-
value := c.GetAppState().GitLogShowGraph
255-
256263
switch value {
257264
case "always":
258265
return true
@@ -262,7 +269,7 @@ func shouldShowGraph(c *ContextCommon) bool {
262269
return c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL
263270
}
264271

265-
log.Fatalf("Unknown value for git.log.showGraph: %s. Expected one of: 'always', 'never', 'when-maximised'", value)
272+
log.Fatalf("Unknown value: %s. Expected one of: 'always', 'never', 'when-maximised'", value)
266273
return false
267274
}
268275

pkg/gui/context/sub_commits_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewSubCommitsContext(
7676
startIdx,
7777
endIdx,
7878
shouldShowGraph(c),
79+
shouldShowTags(c),
7980
git_commands.NewNullBisectInfo(),
8081
)
8182
}

pkg/gui/controllers/local_commits_controller.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,42 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
11921192
})
11931193
},
11941194
},
1195+
{
1196+
Label: self.c.Tr.ShowTags,
1197+
OpensMenu: true,
1198+
OnPress: func() error {
1199+
currentValue := self.c.GetAppState().GitLogShowTags
1200+
onPress := func(value string) func() error {
1201+
return func() error {
1202+
self.c.GetAppState().GitLogShowTags = value
1203+
self.c.SaveAppStateAndLogError()
1204+
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
1205+
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
1206+
return nil
1207+
}
1208+
}
1209+
return self.c.Menu(types.CreateMenuOptions{
1210+
Title: self.c.Tr.LogMenuTitle,
1211+
Items: []*types.MenuItem{
1212+
{
1213+
Label: "always",
1214+
OnPress: onPress("always"),
1215+
Widget: types.MakeMenuRadioButton(currentValue == "always"),
1216+
},
1217+
{
1218+
Label: "never",
1219+
OnPress: onPress("never"),
1220+
Widget: types.MakeMenuRadioButton(currentValue == "never"),
1221+
},
1222+
{
1223+
Label: "when maximised",
1224+
OnPress: onPress("when-maximised"),
1225+
Widget: types.MakeMenuRadioButton(currentValue == "when-maximised"),
1226+
},
1227+
},
1228+
})
1229+
},
1230+
},
11951231
{
11961232
Label: self.c.Tr.SortCommits,
11971233
OpensMenu: true,

pkg/gui/presentation/commits.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func GetCommitListDisplayStrings(
5555
startIdx int,
5656
endIdx int,
5757
showGraph bool,
58+
showTags bool,
5859
bisectInfo *git_commands.BisectInfo,
5960
) [][]string {
6061
mutex.Lock()
@@ -203,6 +204,7 @@ func GetCommitListDisplayStrings(
203204
parseEmoji,
204205
getGraphLine(unfilteredIdx),
205206
fullDescription,
207+
showTags,
206208
bisectStatus,
207209
bisectInfo,
208210
))
@@ -355,6 +357,7 @@ func displayCommit(
355357
parseEmoji bool,
356358
graphLine string,
357359
fullDescription bool,
360+
showTags bool,
358361
bisectStatus BisectStatus,
359362
bisectInfo *git_commands.BisectInfo,
360363
) []string {
@@ -396,7 +399,6 @@ func displayCommit(
396399
tagString = style.FgMagenta.SetBold().Sprint(commit.ExtraInfo) + " "
397400
}
398401
} else {
399-
showTags := common.UserConfig().Gui.ShowCommitTags
400402
if showTags && len(commit.Tags) > 0 {
401403
tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " "
402404
}

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ type TranslationSet struct {
779779
LogMenuTitle string
780780
ToggleShowGitGraphAll string
781781
ShowGitGraph string
782+
ShowTags string
782783
SortOrder string
783784
SortAlphabetical string
784785
SortByDate string
@@ -1868,6 +1869,7 @@ func EnglishTranslationSet() *TranslationSet {
18681869
LogMenuTitle: "Commit Log Options",
18691870
ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)",
18701871
ShowGitGraph: "Show git graph",
1872+
ShowTags: "Show tags",
18711873
SortOrder: "Sort order",
18721874
SortAlphabetical: "Alphabetical",
18731875
SortByDate: "Date",

schema/config.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,6 @@
604604
"description": "Deprecated: use nerdFontsVersion instead",
605605
"default": false
606606
},
607-
"showCommitTags": {
608-
"type": "boolean",
609-
"description": "If true, show tags alognside commit summary in the commits view.",
610-
"default": true
611-
},
612607
"nerdFontsVersion": {
613608
"type": "string",
614609
"enum": [
@@ -1507,6 +1502,16 @@
15071502
"type": "boolean",
15081503
"description": "displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)",
15091504
"default": false
1505+
},
1506+
"showTags": {
1507+
"type": "string",
1508+
"enum": [
1509+
"always",
1510+
"never",
1511+
"when-maximised"
1512+
],
1513+
"description": "Configure this with `Log menu -\u003e Show tags` (\u003cc-l\u003e in the commits window by default).",
1514+
"default": "always"
15101515
}
15111516
},
15121517
"additionalProperties": false,

0 commit comments

Comments
 (0)