Skip to content

Commit e4d7886

Browse files
Cway14Cameron Way
authored andcommitted
Add 'ShowTags' configuration option
When working on projects that make heavy use of tags (ie. every commit has multiple tags), it would be nice to be able to hide commit tags. This commit adds this option. Discussion with interest for the feature: #3294
1 parent aa331e5 commit e4d7886

File tree

9 files changed

+86
-7
lines changed

9 files changed

+86
-7
lines changed

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 commit tags are 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
@@ -698,6 +698,9 @@ git:
698698
# displays the whole git graph by default in the commits view (equivalent to passing the --all argument to git log)
699699
showWholeGraph: false
700700
701+
# Configure this with Log menu -> 'Show commit tags' (<c-l> in the commits window by default).
702+
showTags: always
703+
701704
# When copying commit hashes to the clipboard, truncate them to this
702705
# length. Set to 40 to disable truncation.
703706
truncateCopiedCommitHashesTo: 12

pkg/config/user_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ type LogConfig struct {
337337
ShowGraph string `yaml:"showGraph" jsonschema:"deprecated,enum=always,enum=never,enum=when-maximised"`
338338
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
339339
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"`
340342
}
341343

342344
type CommitPrefixConfig struct {
@@ -815,6 +817,7 @@ func GetDefaultConfig() *UserConfig {
815817
Order: "topo-order",
816818
ShowGraph: "always",
817819
ShowWholeGraph: false,
820+
ShowTags: "always",
818821
},
819822
SkipHookPrefix: "WIP",
820823
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presentation
22

33
import (
44
"fmt"
5+
"regexp"
56
"strings"
67
"time"
78

@@ -55,6 +56,7 @@ func GetCommitListDisplayStrings(
5556
startIdx int,
5657
endIdx int,
5758
showGraph bool,
59+
showTags bool,
5860
bisectInfo *git_commands.BisectInfo,
5961
) [][]string {
6062
mutex.Lock()
@@ -203,6 +205,7 @@ func GetCommitListDisplayStrings(
203205
parseEmoji,
204206
getGraphLine(unfilteredIdx),
205207
fullDescription,
208+
showTags,
206209
bisectStatus,
207210
bisectInfo,
208211
))
@@ -355,6 +358,7 @@ func displayCommit(
355358
parseEmoji bool,
356359
graphLine string,
357360
fullDescription bool,
361+
showTags bool,
358362
bisectStatus BisectStatus,
359363
bisectInfo *git_commands.BisectInfo,
360364
) []string {
@@ -391,12 +395,18 @@ func displayCommit(
391395
}
392396

393397
tagString := ""
394-
if fullDescription {
395-
if commit.ExtraInfo != "" {
396-
tagString = style.FgMagenta.SetBold().Sprint(commit.ExtraInfo) + " "
398+
if fullDescription && commit.ExtraInfo != "" {
399+
extraInfo := commit.ExtraInfo
400+
if !showTags {
401+
// Remove tags from the extra info
402+
extraInfo = regexp.MustCompile(`tag: [^,)\s]+,?\s*`).ReplaceAllString(commit.ExtraInfo, "")
403+
extraInfo = strings.Replace(extraInfo, "()", "", 1)
404+
}
405+
if extraInfo != "" {
406+
tagString = style.FgMagenta.SetBold().Sprint(extraInfo) + " "
397407
}
398408
} else {
399-
if len(commit.Tags) > 0 {
409+
if showTags && len(commit.Tags) > 0 {
400410
tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " "
401411
}
402412

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,16 @@
15021502
"type": "boolean",
15031503
"description": "displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)",
15041504
"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"
15051515
}
15061516
},
15071517
"additionalProperties": false,

0 commit comments

Comments
 (0)