Skip to content

Add 'ShowTags' configuration option #4629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func NewAppConfig(
if appState.GitLogShowGraph == "" {
appState.GitLogShowGraph = userConfig.Git.Log.ShowGraph
}
if appState.GitLogShowTags == "" {
appState.GitLogShowTags = userConfig.Git.Log.ShowTags
}

appConfig := &AppConfig{
name: name,
Expand Down Expand Up @@ -691,6 +694,9 @@ type AppState struct {
// This determines whether the git graph is rendered in the commits panel
// One of 'always' | 'never' | 'when-maximised'
GitLogShowGraph string
// This determines whether the commit tags are rendered in the commits panel
// One of 'always' | 'never' | 'when-maximised'
GitLogShowTags string
}

func getDefaultAppState() *AppState {
Expand All @@ -705,6 +711,7 @@ func getDefaultAppState() *AppState {
RemoteBranchSortOrder: "alphabetical",
GitLogOrder: "", // should be "topo-order" eventually
GitLogShowGraph: "", // should be "always" eventually
GitLogShowTags: "", // should be "always" eventually
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ git:
# displays the whole git graph by default in the commits view (equivalent to passing the --all argument to git log)
showWholeGraph: false

# This determines whether tags are displayed in the commits view
# One of 'always' | 'never' | 'when-maximised'
showTags: always

# When copying commit hashes to the clipboard, truncate them to this
# length. Set to 40 to disable truncation.
truncateCopiedCommitHashesTo: 12
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ type LogConfig struct {
ShowGraph string `yaml:"showGraph" jsonschema:"deprecated,enum=always,enum=never,enum=when-maximised"`
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
ShowWholeGraph bool `yaml:"showWholeGraph"`
// This determines whether tags are displayed in the commits view
ShowTags string `yaml:"showTags" jsonschema:"enum=always,enum=never,enum=when-maximised"`
}

type CommitPrefixConfig struct {
Expand Down Expand Up @@ -815,6 +817,7 @@ func GetDefaultConfig() *UserConfig {
Order: "topo-order",
ShowGraph: "always",
ShowWholeGraph: false,
ShowTags: "always",
},
SkipHookPrefix: "WIP",
MainBranches: []string{"master", "main"},
Expand Down
21 changes: 18 additions & 3 deletions pkg/gui/context/local_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
startIdx,
endIdx,
shouldShowGraph(c),
shouldDisplayForScreenMode(c, viewModel.showTags),
c.Model().BisectInfo,
)
}
Expand Down Expand Up @@ -148,13 +149,17 @@ type LocalCommitsViewModel struct {

// If this is true we'll use git log --all when fetching the commits.
showWholeGitGraph bool

// If this is true we'll show tags in the commit list.
showTags string
}

func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel {
self := &LocalCommitsViewModel{
ListViewModel: NewListViewModel(getModel),
limitCommits: true,
showWholeGitGraph: c.UserConfig().Git.Log.ShowWholeGraph,
showTags: c.UserConfig().Git.Log.ShowTags,
}

return self
Expand Down Expand Up @@ -238,6 +243,14 @@ func (self *LocalCommitsViewModel) SetShowWholeGitGraph(value bool) {
self.showWholeGitGraph = value
}

func (self *LocalCommitsContext) GetShowTags() string {
return self.showTags
}

func (self *LocalCommitsViewModel) SetShowTags(value string) {
self.showTags = value
}

func (self *LocalCommitsViewModel) GetShowWholeGitGraph() bool {
return self.showWholeGitGraph
}
Expand All @@ -247,12 +260,14 @@ func (self *LocalCommitsViewModel) GetCommits() []*models.Commit {
}

func shouldShowGraph(c *ContextCommon) bool {
return shouldDisplayForScreenMode(c, c.GetAppState().GitLogShowGraph)
}

func shouldDisplayForScreenMode(c *ContextCommon, value string) bool {
if c.Modes().Filtering.Active() {
return false
}

value := c.GetAppState().GitLogShowGraph

switch value {
case "always":
return true
Expand All @@ -262,7 +277,7 @@ func shouldShowGraph(c *ContextCommon) bool {
return c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL
}

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

Expand Down
10 changes: 10 additions & 0 deletions pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewSubCommitsContext(
startIdx,
endIdx,
shouldShowGraph(c),
shouldDisplayForScreenMode(c, viewModel.GetShowTags()),
git_commands.NewNullBisectInfo(),
)
}
Expand Down Expand Up @@ -147,6 +148,7 @@ type SubCommitsViewModel struct {

limitCommits bool
showBranchHeads bool
showTags string
}

func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
Expand All @@ -173,6 +175,14 @@ func (self *SubCommitsViewModel) GetShowBranchHeads() bool {
return self.showBranchHeads
}

func (self *SubCommitsViewModel) SetShowTags(value string) {
self.showTags = value
}

func (self *SubCommitsViewModel) GetShowTags() string {
return self.showTags
}

func (self *SubCommitsContext) CanRebase() bool {
return false
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,42 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
})
},
},
{
Label: self.c.Tr.ShowTags,
OpensMenu: true,
OnPress: func() error {
currentValue := self.context().GetShowTags()
onPress := func(value string) func() error {
return func() error {
self.context().SetShowTags(value)
self.c.SaveAppStateAndLogError()
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
return nil
}
}
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.LogMenuTitle,
Items: []*types.MenuItem{
{
Label: "always",
OnPress: onPress("always"),
Widget: types.MakeMenuRadioButton(currentValue == "always"),
},
{
Label: "never",
OnPress: onPress("never"),
Widget: types.MakeMenuRadioButton(currentValue == "never"),
},
{
Label: "when maximised",
OnPress: onPress("when-maximised"),
Widget: types.MakeMenuRadioButton(currentValue == "when-maximised"),
},
},
})
},
},
{
Label: self.c.Tr.SortCommits,
OpensMenu: true,
Expand Down
17 changes: 13 additions & 4 deletions pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package presentation

import (
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -55,6 +56,7 @@ func GetCommitListDisplayStrings(
startIdx int,
endIdx int,
showGraph bool,
showTags bool,
bisectInfo *git_commands.BisectInfo,
) [][]string {
mutex.Lock()
Expand Down Expand Up @@ -203,6 +205,7 @@ func GetCommitListDisplayStrings(
parseEmoji,
getGraphLine(unfilteredIdx),
fullDescription,
showTags,
bisectStatus,
bisectInfo,
))
Expand Down Expand Up @@ -355,6 +358,7 @@ func displayCommit(
parseEmoji bool,
graphLine string,
fullDescription bool,
showTags bool,
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
) []string {
Expand Down Expand Up @@ -391,12 +395,17 @@ func displayCommit(
}

tagString := ""
if fullDescription {
if commit.ExtraInfo != "" {
tagString = style.FgMagenta.SetBold().Sprint(commit.ExtraInfo) + " "
if fullDescription && commit.ExtraInfo != "" {
extraInfo := commit.ExtraInfo
if !showTags {
extraInfo = regexp.MustCompile(`tag: [^,)\s]+,?\s*`).ReplaceAllString(commit.ExtraInfo, "")
extraInfo = strings.Replace(extraInfo, "()", "", 1) // if only tags were present in extraInfo
}
if extraInfo != "" {
tagString = style.FgMagenta.SetBold().Sprint(extraInfo) + " "
}
} else {
if len(commit.Tags) > 0 {
if showTags && len(commit.Tags) > 0 {
tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " "
}

Expand Down
Loading