Skip to content

Commit ccd80a0

Browse files
committed
add menu options for log stuff
1 parent 37be9db commit ccd80a0

File tree

9 files changed

+143
-6
lines changed

9 files changed

+143
-6
lines changed

docs/Config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ git:
6262
# extra args passed to `git merge`, e.g. --no-ff
6363
args: ''
6464
log:
65-
# one of date-order, reverse, author-date-order, topo-order.
65+
# one of date-order, author-date-order, topo-order.
6666
# topo-order makes it easier to read the git log graph, but commits may not
6767
# appear chronologically. See https://git-scm.com/docs/git-log#_commit_ordering
6868
order: 'topo-order'
@@ -201,6 +201,7 @@ keybinding:
201201
checkoutCommit: '<space>'
202202
resetCherryPick: '<c-R>'
203203
copyCommitMessageToClipboard: '<c-y>'
204+
openLogMenu: '<c-l>'
204205
stash:
205206
popStash: 'g'
206207
commitFiles:

pkg/commands/loading_commits.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ type CommitListBuilder struct {
3737
}
3838

3939
// NewCommitListBuilder builds a new commit list builder
40-
func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *oscommands.OSCommand, tr *i18n.TranslationSet) *CommitListBuilder {
40+
func NewCommitListBuilder(
41+
log *logrus.Entry,
42+
gitCommand *GitCommand,
43+
osCommand *oscommands.OSCommand,
44+
tr *i18n.TranslationSet,
45+
) *CommitListBuilder {
4146
return &CommitListBuilder{
4247
Log: log,
4348
GitCommand: gitCommand,
@@ -88,6 +93,8 @@ type GetCommitsOptions struct {
8893
FilterPath string
8994
IncludeRebaseCommits bool
9095
RefName string // e.g. "HEAD" or "my_branch"
96+
// determines if we show the whole git graph i.e. pass the '--all' flag
97+
All bool
9198
}
9299

93100
func (c *CommitListBuilder) MergeRebasingCommits(commits []*models.Commit) ([]*models.Commit, error) {
@@ -407,12 +414,17 @@ func (c *CommitListBuilder) getLogCmd(opts GetCommitsOptions) *exec.Cmd {
407414
config := c.GitCommand.Config.GetUserConfig().Git.Log
408415

409416
orderFlag := "--" + config.Order
417+
allFlag := ""
418+
if opts.All {
419+
allFlag = " --all"
420+
}
410421

411422
return c.OSCommand.ExecutableFromString(
412423
fmt.Sprintf(
413-
"git log %s %s --oneline %s %s --abbrev=%d %s",
424+
"git log %s %s %s --oneline %s %s --abbrev=%d %s",
414425
c.OSCommand.Quote(opts.RefName),
415426
orderFlag,
427+
allFlag,
416428
prettyFormat,
417429
limitFlag,
418430
20,

pkg/config/user_config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type MergingConfig struct {
8686
}
8787

8888
type LogConfig struct {
89-
Order string `yaml:"order"` // one of date-order, reverse, author-date-order, topo-order
89+
Order string `yaml:"order"` // one of date-order, author-date-order, topo-order
9090
ShowGraph string `yaml:"showGraph"` // one of always, never, when-maximised
9191
}
9292

@@ -237,6 +237,7 @@ type KeybindingCommitsConfig struct {
237237
CheckoutCommit string `yaml:"checkoutCommit"`
238238
ResetCherryPick string `yaml:"resetCherryPick"`
239239
CopyCommitMessageToClipboard string `yaml:"copyCommitMessageToClipboard"`
240+
OpenLogMenu string `yaml:"openLogMenu"`
240241
}
241242

242243
type KeybindingStashConfig struct {
@@ -492,6 +493,7 @@ func GetDefaultConfig() *UserConfig {
492493
CheckoutCommit: "<space>",
493494
ResetCherryPick: "<c-R>",
494495
CopyCommitMessageToClipboard: "<c-y>",
496+
OpenLogMenu: "<c-l>",
495497
},
496498
Stash: KeybindingStashConfig{
497499
PopStash: "g",

pkg/gui/commits_panel.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (gui *Gui) refreshCommitsWithLimit() error {
125125
FilterPath: gui.State.Modes.Filtering.GetPath(),
126126
IncludeRebaseCommits: true,
127127
RefName: "HEAD",
128+
All: gui.State.ShowWholeGitGraph,
128129
},
129130
)
130131
if err != nil {
@@ -670,3 +671,87 @@ func (gui *Gui) handleCopySelectedCommitMessageToClipboard() error {
670671

671672
return nil
672673
}
674+
675+
func (gui *Gui) handleOpenLogMenu() error {
676+
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
677+
{
678+
displayString: gui.Tr.ToggleShowGitGraphAll,
679+
onPress: func() error {
680+
gui.State.ShowWholeGitGraph = !gui.State.ShowWholeGitGraph
681+
682+
if gui.State.ShowWholeGitGraph {
683+
gui.State.Panels.Commits.LimitCommits = false
684+
}
685+
686+
return gui.WithWaitingStatus(gui.Tr.LcLoadingCommits, func() error {
687+
return gui.refreshSidePanels(refreshOptions{mode: SYNC, scope: []RefreshableView{COMMITS}})
688+
})
689+
},
690+
},
691+
{
692+
displayString: gui.Tr.ShowGitGraph,
693+
opensMenu: true,
694+
onPress: func() error {
695+
onSelect := func(value string) {
696+
gui.Config.GetUserConfig().Git.Log.ShowGraph = value
697+
gui.render()
698+
}
699+
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
700+
{
701+
displayString: "always",
702+
onPress: func() error {
703+
onSelect("always")
704+
return nil
705+
},
706+
},
707+
{
708+
displayString: "never",
709+
onPress: func() error {
710+
onSelect("never")
711+
return nil
712+
},
713+
},
714+
{
715+
displayString: "when maximised",
716+
onPress: func() error {
717+
onSelect("when-maximised")
718+
return nil
719+
},
720+
},
721+
}, createMenuOptions{showCancel: true})
722+
},
723+
},
724+
{
725+
displayString: gui.Tr.SortCommits,
726+
opensMenu: true,
727+
onPress: func() error {
728+
onSelect := func(value string) error {
729+
gui.Config.GetUserConfig().Git.Log.Order = value
730+
return gui.WithWaitingStatus(gui.Tr.LcLoadingCommits, func() error {
731+
return gui.refreshSidePanels(refreshOptions{mode: SYNC, scope: []RefreshableView{COMMITS}})
732+
})
733+
}
734+
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
735+
{
736+
displayString: "topological (topo-order)",
737+
onPress: func() error {
738+
return onSelect("topo-order")
739+
},
740+
},
741+
{
742+
displayString: "date-order",
743+
onPress: func() error {
744+
return onSelect("date-order")
745+
},
746+
},
747+
{
748+
displayString: "author-date-order",
749+
onPress: func() error {
750+
return onSelect("author-date-order")
751+
},
752+
},
753+
}, createMenuOptions{showCancel: true})
754+
},
755+
},
756+
}, createMenuOptions{showCancel: true})
757+
}

pkg/gui/gui.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ type guiState struct {
314314
RetainOriginalDir bool
315315
IsRefreshingFiles bool
316316
Searching searchingState
317+
// if this is true, we'll load our commits using `git log --all`
318+
ShowWholeGitGraph bool
317319
ScreenMode WindowMaximisation
318320
Ptmx *os.File
319321
PrevMainWidth int

pkg/gui/keybindings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
724724
Handler: gui.handleFetchRemote,
725725
Description: gui.Tr.LcFetchRemote,
726726
},
727+
{
728+
ViewName: "commits",
729+
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
730+
Key: gui.getKey(config.Commits.OpenLogMenu),
731+
Handler: gui.handleOpenLogMenu,
732+
Description: gui.Tr.LcOpenLogMenu,
733+
OpensMenu: true,
734+
},
727735
{
728736
ViewName: "commits",
729737
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},

pkg/gui/menu_panel.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gui
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67

@@ -13,6 +14,8 @@ type menuItem struct {
1314
displayString string
1415
displayStrings []string
1516
onPress func() error
17+
// only applies when displayString is used
18+
opensMenu bool
1619
}
1720

1821
// every item in a list context needs an ID
@@ -65,8 +68,16 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
6568

6669
stringArrays := make([][]string, len(items))
6770
for i, item := range items {
71+
if item.opensMenu && item.displayStrings != nil {
72+
return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user")
73+
}
74+
6875
if item.displayStrings == nil {
69-
stringArrays[i] = []string{item.displayString}
76+
styledStr := item.displayString
77+
if item.opensMenu {
78+
styledStr = opensMenuStyle(styledStr)
79+
}
80+
stringArrays[i] = []string{styledStr}
7081
} else {
7182
stringArrays[i] = item.displayStrings
7283
}

pkg/gui/options_menu_panel.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ func (gui *Gui) getBindings(v *gocui.View) []*Binding {
3636

3737
func (gui *Gui) displayDescription(binding *Binding) string {
3838
if binding.OpensMenu {
39-
return style.FgMagenta.Sprintf("%s...", binding.Description)
39+
return opensMenuStyle(binding.Description)
4040
}
4141

4242
return style.FgCyan.Sprint(binding.Description)
4343
}
4444

45+
func opensMenuStyle(str string) string {
46+
return style.FgMagenta.Sprintf("%s...", str)
47+
}
48+
4549
func (gui *Gui) handleCreateOptionsMenu() error {
4650
view := gui.g.CurrentView()
4751
if view == nil {

pkg/i18n/english.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,17 @@ type TranslationSet struct {
436436
SelectConfigFile string
437437
NoConfigFileFoundErr string
438438
LcLoadingFileSuggestions string
439+
LcLoadingCommits string
439440
MustSpecifyOriginError string
440441
GitOutput string
441442
GitCommandFailed string
442443
AbortTitle string
443444
AbortPrompt string
445+
LcOpenLogMenu string
446+
LogMenuTitle string
447+
ToggleShowGitGraphAll string
448+
ShowGitGraph string
449+
SortCommits string
444450
Spans Spans
445451
}
446452

@@ -970,11 +976,17 @@ func englishTranslationSet() TranslationSet {
970976
SelectConfigFile: "Select config file",
971977
NoConfigFileFoundErr: "No config file found",
972978
LcLoadingFileSuggestions: "loading file suggestions",
979+
LcLoadingCommits: "loading commits",
973980
MustSpecifyOriginError: "Must specify a remote if specifying a branch",
974981
GitOutput: "Git output:",
975982
GitCommandFailed: "Git command failed. Check command log for details (open with %s)",
976983
AbortTitle: "Abort %s",
977984
AbortPrompt: "Are you sure you want to abort the current %s?",
985+
LcOpenLogMenu: "open log menu",
986+
LogMenuTitle: "Commit Log Options",
987+
ToggleShowGitGraphAll: "toggle show whole git graph (pass the `--all` flag to `git log`)",
988+
ShowGitGraph: "show git graph",
989+
SortCommits: "commit sort order",
978990
Spans: Spans{
979991
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
980992
CheckoutCommit: "Checkout commit",

0 commit comments

Comments
 (0)