From 6f8063217ddf132dca36b75affaa7f7273f89d9d Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 8 May 2022 14:23:32 +1000 Subject: [PATCH 1/2] rename displayString to label for menu items --- pkg/gui/context/menu_context.go | 8 ++-- .../controllers/basic_commits_controller.go | 10 ++--- pkg/gui/controllers/bisect_controller.go | 12 +++--- pkg/gui/controllers/branches_controller.go | 12 +++--- pkg/gui/controllers/files_controller.go | 14 +++---- .../controllers/files_remove_controller.go | 10 ++--- pkg/gui/controllers/git_flow_controller.go | 26 ++++++------ .../helpers/merge_and_rebase_helper.go | 2 +- pkg/gui/controllers/helpers/refs_helper.go | 2 +- pkg/gui/controllers/helpers/tags_helper.go | 4 +- .../controllers/local_commits_controller.go | 36 ++++++++-------- pkg/gui/controllers/submodules_controller.go | 6 +-- .../controllers/workspace_reset_controller.go | 12 +++--- pkg/gui/diffing.go | 8 ++-- pkg/gui/extras_panel.go | 6 +-- pkg/gui/filtering_menu_panel.go | 8 ++-- pkg/gui/menu_panel.go | 4 +- pkg/gui/options_menu_panel.go | 2 +- pkg/gui/patch_options_panel.go | 42 +++++++++---------- pkg/gui/recent_repos_panel.go | 2 +- .../custom_commands/handler_creator.go | 4 +- pkg/gui/status_panel.go | 2 +- pkg/gui/types/common.go | 16 ++++--- 23 files changed, 126 insertions(+), 122 deletions(-) diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index be748eb70..b705adcee 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -58,7 +58,7 @@ func (self *MenuContext) GetSelectedItemId() string { return "" } - return item.DisplayString + return item.Label } type MenuViewModel struct { @@ -96,11 +96,11 @@ func (self *MenuViewModel) GetDisplayStrings(_startIdx int, _length int) [][]str } func getItemDisplayStrings(item *types.MenuItem) []string { - if item.DisplayStrings != nil { - return item.DisplayStrings + if item.LabelColumns != nil { + return item.LabelColumns } - styledStr := item.DisplayString + styledStr := item.Label if item.OpensMenu { styledStr = presentation.OpensMenuStyle(styledStr) } diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 66455eecf..cecba00fe 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -101,35 +101,35 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard, Items: []*types.MenuItem{ { - DisplayString: self.c.Tr.LcCommitSha, + Label: self.c.Tr.LcCommitSha, OnPress: func() error { return self.copyCommitSHAToClipboard(commit) }, Key: 's', }, { - DisplayString: self.c.Tr.LcCommitURL, + Label: self.c.Tr.LcCommitURL, OnPress: func() error { return self.copyCommitURLToClipboard(commit) }, Key: 'u', }, { - DisplayString: self.c.Tr.LcCommitDiff, + Label: self.c.Tr.LcCommitDiff, OnPress: func() error { return self.copyCommitDiffToClipboard(commit) }, Key: 'd', }, { - DisplayString: self.c.Tr.LcCommitMessage, + Label: self.c.Tr.LcCommitMessage, OnPress: func() error { return self.copyCommitMessageToClipboard(commit) }, Key: 'm', }, { - DisplayString: self.c.Tr.LcCommitAuthor, + Label: self.c.Tr.LcCommitAuthor, OnPress: func() error { return self.copyAuthorToClipboard(commit) }, diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 168076135..805911030 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -67,7 +67,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c menuItems := []*types.MenuItem{ { - DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.NewTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.NewTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.BisectMark) if err := self.git.Bisect.Mark(commit.Sha, info.NewTerm()); err != nil { @@ -79,7 +79,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c Key: 'b', }, { - DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.BisectMark) if err := self.git.Bisect.Mark(commit.Sha, info.OldTerm()); err != nil { @@ -91,7 +91,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c Key: 'g', }, { - DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()), + Label: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.BisectSkip) if err := self.git.Bisect.Skip(commit.Sha); err != nil { @@ -103,7 +103,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c Key: 's', }, { - DisplayString: self.c.Tr.Bisect.ResetOption, + Label: self.c.Tr.Bisect.ResetOption, OnPress: func() error { return self.helpers.Bisect.Reset() }, @@ -122,7 +122,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, Title: self.c.Tr.Bisect.BisectMenuTitle, Items: []*types.MenuItem{ { - DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.StartBisect) if err := self.git.Bisect.Start(); err != nil { @@ -138,7 +138,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, Key: 'b', }, { - DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.StartBisect) if err := self.git.Bisect.Start(); err != nil { diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 096082ac4..6b86dfcd3 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -111,7 +111,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error Title: self.c.Tr.Actions.SetUnsetUpstream, Items: []*types.MenuItem{ { - DisplayStrings: []string{self.c.Tr.LcUnsetUpstream}, + LabelColumns: []string{self.c.Tr.LcUnsetUpstream}, OnPress: func() error { if err := self.git.Branch.UnsetUpstream(selectedBranch.Name); err != nil { return self.c.Error(err) @@ -130,7 +130,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error Key: 'u', }, { - DisplayStrings: []string{self.c.Tr.LcSetUpstream}, + LabelColumns: []string{self.c.Tr.LcSetUpstream}, OnPress: func() error { return self.helpers.Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error { upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream) @@ -417,20 +417,20 @@ func (self *BranchesController) newBranch(selectedBranch *models.Branch) error { func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { menuItems := make([]*types.MenuItem, 0, 4) - fromToDisplayStrings := func(from string, to string) []string { + fromToLabelColumns := func(from string, to string) []string { return []string{fmt.Sprintf("%s → %s", from, to)} } menuItemsForBranch := func(branch *models.Branch) []*types.MenuItem { return []*types.MenuItem{ { - DisplayStrings: fromToDisplayStrings(branch.Name, self.c.Tr.LcDefaultBranch), + LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.LcDefaultBranch), OnPress: func() error { return self.createPullRequest(branch.Name, "") }, }, { - DisplayStrings: fromToDisplayStrings(branch.Name, self.c.Tr.LcSelectBranch), + LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.LcSelectBranch), OnPress: func() error { return self.c.Prompt(types.PromptOpts{ Title: branch.Name + " →", @@ -447,7 +447,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra if selectedBranch != checkedOutBranch { menuItems = append(menuItems, &types.MenuItem{ - DisplayStrings: fromToDisplayStrings(checkedOutBranch.Name, selectedBranch.Name), + LabelColumns: fromToLabelColumns(checkedOutBranch.Name, selectedBranch.Name), OnPress: func() error { return self.createPullRequest(checkedOutBranch.Name, selectedBranch.Name) }, diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 26c6e131f..c461af919 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -500,19 +500,19 @@ func (self *FilesController) handleStatusFilterPressed() error { Title: self.c.Tr.FilteringMenuTitle, Items: []*types.MenuItem{ { - DisplayString: self.c.Tr.FilterStagedFiles, + Label: self.c.Tr.FilterStagedFiles, OnPress: func() error { return self.setStatusFiltering(filetree.DisplayStaged) }, }, { - DisplayString: self.c.Tr.FilterUnstagedFiles, + Label: self.c.Tr.FilterUnstagedFiles, OnPress: func() error { return self.setStatusFiltering(filetree.DisplayUnstaged) }, }, { - DisplayString: self.c.Tr.ResetCommitFilterState, + Label: self.c.Tr.ResetCommitFilterState, OnPress: func() error { return self.setStatusFiltering(filetree.DisplayAll) }, @@ -557,14 +557,14 @@ func (self *FilesController) createStashMenu() error { Title: self.c.Tr.LcStashOptions, Items: []*types.MenuItem{ { - DisplayString: self.c.Tr.LcStashAllChanges, + Label: self.c.Tr.LcStashAllChanges, OnPress: func() error { return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoFilesToStash) }, Key: 'a', }, { - DisplayString: self.c.Tr.LcStashAllChangesKeepIndex, + Label: self.c.Tr.LcStashAllChangesKeepIndex, OnPress: func() error { // if there are no staged files it behaves the same as Stash.Save return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex, self.c.Tr.NoFilesToStash) @@ -572,7 +572,7 @@ func (self *FilesController) createStashMenu() error { Key: 'i', }, { - DisplayString: self.c.Tr.LcStashStagedChanges, + Label: self.c.Tr.LcStashStagedChanges, OnPress: func() error { // there must be something in staging otherwise the current implementation mucks the stash up if !self.helpers.WorkingTree.AnyStagedFiles() { @@ -583,7 +583,7 @@ func (self *FilesController) createStashMenu() error { Key: 's', }, { - DisplayString: self.c.Tr.LcStashUnstagedChanges, + Label: self.c.Tr.LcStashUnstagedChanges, OnPress: func() error { if self.helpers.WorkingTree.AnyStagedFiles() { return self.handleStashSave(self.git.Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash) diff --git a/pkg/gui/controllers/files_remove_controller.go b/pkg/gui/controllers/files_remove_controller.go index 54af72fa0..73449f1ec 100644 --- a/pkg/gui/controllers/files_remove_controller.go +++ b/pkg/gui/controllers/files_remove_controller.go @@ -43,7 +43,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error { if node.File == nil { menuItems = []*types.MenuItem{ { - DisplayString: self.c.Tr.LcDiscardAllChanges, + Label: self.c.Tr.LcDiscardAllChanges, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInDirectory) if err := self.git.WorkingTree.DiscardAllDirChanges(node); err != nil { @@ -57,7 +57,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error { if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() { menuItems = append(menuItems, &types.MenuItem{ - DisplayString: self.c.Tr.LcDiscardUnstagedChanges, + Label: self.c.Tr.LcDiscardUnstagedChanges, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedChangesInDirectory) if err := self.git.WorkingTree.DiscardUnstagedDirChanges(node); err != nil { @@ -78,7 +78,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error { menuItems = []*types.MenuItem{ { - DisplayString: self.c.Tr.LcSubmoduleStashAndReset, + Label: self.c.Tr.LcSubmoduleStashAndReset, OnPress: func() error { return self.ResetSubmodule(submodule) }, @@ -87,7 +87,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error { } else { menuItems = []*types.MenuItem{ { - DisplayString: self.c.Tr.LcDiscardAllChanges, + Label: self.c.Tr.LcDiscardAllChanges, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile) if err := self.git.WorkingTree.DiscardAllFileChanges(file); err != nil { @@ -101,7 +101,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error { if file.HasStagedChanges && file.HasUnstagedChanges { menuItems = append(menuItems, &types.MenuItem{ - DisplayString: self.c.Tr.LcDiscardUnstagedChanges, + Label: self.c.Tr.LcDiscardUnstagedChanges, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile) if err := self.git.WorkingTree.DiscardUnstagedFileChanges(file); err != nil { diff --git a/pkg/gui/controllers/git_flow_controller.go b/pkg/gui/controllers/git_flow_controller.go index a0b0f3074..2504ad2dd 100644 --- a/pkg/gui/controllers/git_flow_controller.go +++ b/pkg/gui/controllers/git_flow_controller.go @@ -64,30 +64,30 @@ func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) er Items: []*types.MenuItem{ { // not localising here because it's one to one with the actual git flow commands - DisplayString: fmt.Sprintf("finish branch '%s'", branch.Name), + Label: fmt.Sprintf("finish branch '%s'", branch.Name), OnPress: func() error { return self.gitFlowFinishBranch(branch.Name) }, }, { - DisplayString: "start feature", - OnPress: startHandler("feature"), - Key: 'f', + Label: "start feature", + OnPress: startHandler("feature"), + Key: 'f', }, { - DisplayString: "start hotfix", - OnPress: startHandler("hotfix"), - Key: 'h', + Label: "start hotfix", + OnPress: startHandler("hotfix"), + Key: 'h', }, { - DisplayString: "start bugfix", - OnPress: startHandler("bugfix"), - Key: 'b', + Label: "start bugfix", + OnPress: startHandler("bugfix"), + Key: 'b', }, { - DisplayString: "start release", - OnPress: startHandler("release"), - Key: 'r', + Label: "start release", + OnPress: startHandler("release"), + Key: 'r', }, }, }) diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 4484e4fc8..ef9dd76a2 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -64,7 +64,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { menuItems := slices.Map(options, func(row optionAndKey) *types.MenuItem { return &types.MenuItem{ - DisplayString: row.option, + Label: row.option, OnPress: func() error { return self.genericMergeCommand(row.option) }, diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index d96fa795b..7630349ec 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -146,7 +146,7 @@ func (self *RefsHelper) CreateGitResetMenu(ref string) error { menuItems := slices.Map(strengths, func(row strengthWithKey) *types.MenuItem { return &types.MenuItem{ - DisplayStrings: []string{ + LabelColumns: []string{ fmt.Sprintf("%s reset", row.strength), style.FgRed.Sprintf("reset --%s %s", row.strength, ref), }, diff --git a/pkg/gui/controllers/helpers/tags_helper.go b/pkg/gui/controllers/helpers/tags_helper.go index d2e92cd24..4683ffd0d 100644 --- a/pkg/gui/controllers/helpers/tags_helper.go +++ b/pkg/gui/controllers/helpers/tags_helper.go @@ -26,13 +26,13 @@ func (self *TagsHelper) CreateTagMenu(commitSha string, onCreate func()) error { Title: self.c.Tr.TagMenuTitle, Items: []*types.MenuItem{ { - DisplayString: self.c.Tr.LcLightweightTag, + Label: self.c.Tr.LcLightweightTag, OnPress: func() error { return self.handleCreateLightweightTag(commitSha, onCreate) }, }, { - DisplayString: self.c.Tr.LcAnnotatedTag, + Label: self.c.Tr.LcAnnotatedTag, OnPress: func() error { return self.handleCreateAnnotatedTag(commitSha, onCreate) }, diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 7684d6469..7d0f144cd 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -470,7 +470,7 @@ func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.C } menuItems[i] = &types.MenuItem{ - DisplayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message), + Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message), OnPress: func() error { parentNumber := i + 1 self.c.LogAction(self.c.Tr.Actions.RevertCommit) @@ -570,7 +570,7 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { Title: self.c.Tr.LogMenuTitle, Items: []*types.MenuItem{ { - DisplayString: self.c.Tr.ToggleShowGitGraphAll, + Label: self.c.Tr.ToggleShowGitGraphAll, OnPress: func() error { self.context().SetShowWholeGitGraph(!self.context().GetShowWholeGitGraph()) @@ -586,8 +586,8 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { }, }, { - DisplayString: self.c.Tr.ShowGitGraph, - OpensMenu: true, + Label: self.c.Tr.ShowGitGraph, + OpensMenu: true, OnPress: func() error { onPress := func(value string) func() error { return func() error { @@ -599,24 +599,24 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { Title: self.c.Tr.LogMenuTitle, Items: []*types.MenuItem{ { - DisplayString: "always", - OnPress: onPress("always"), + Label: "always", + OnPress: onPress("always"), }, { - DisplayString: "never", - OnPress: onPress("never"), + Label: "never", + OnPress: onPress("never"), }, { - DisplayString: "when maximised", - OnPress: onPress("when-maximised"), + Label: "when maximised", + OnPress: onPress("when-maximised"), }, }, }) }, }, { - DisplayString: self.c.Tr.SortCommits, - OpensMenu: true, + Label: self.c.Tr.SortCommits, + OpensMenu: true, OnPress: func() error { onPress := func(value string) func() error { return func() error { @@ -636,16 +636,16 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { Title: self.c.Tr.LogMenuTitle, Items: []*types.MenuItem{ { - DisplayString: "topological (topo-order)", - OnPress: onPress("topo-order"), + Label: "topological (topo-order)", + OnPress: onPress("topo-order"), }, { - DisplayString: "date-order", - OnPress: onPress("date-order"), + Label: "date-order", + OnPress: onPress("date-order"), }, { - DisplayString: "author-date-order", - OnPress: onPress("author-date-order"), + Label: "author-date-order", + OnPress: onPress("author-date-order"), }, }, }) diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index b0a8f6116..5bd7ce088 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -146,7 +146,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error { Title: self.c.Tr.LcBulkSubmoduleOptions, Items: []*types.MenuItem{ { - DisplayStrings: []string{self.c.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(self.git.Submodule.BulkInitCmdObj().ToString())}, + LabelColumns: []string{self.c.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(self.git.Submodule.BulkInitCmdObj().ToString())}, OnPress: func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { self.c.LogAction(self.c.Tr.Actions.BulkInitialiseSubmodules) @@ -161,7 +161,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error { Key: 'i', }, { - DisplayStrings: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())}, + LabelColumns: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())}, OnPress: func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { self.c.LogAction(self.c.Tr.Actions.BulkUpdateSubmodules) @@ -175,7 +175,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error { Key: 'u', }, { - DisplayStrings: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())}, + LabelColumns: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())}, OnPress: func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { self.c.LogAction(self.c.Tr.Actions.BulkDeinitialiseSubmodules) diff --git a/pkg/gui/controllers/workspace_reset_controller.go b/pkg/gui/controllers/workspace_reset_controller.go index bd5f47195..dc830b3ba 100644 --- a/pkg/gui/controllers/workspace_reset_controller.go +++ b/pkg/gui/controllers/workspace_reset_controller.go @@ -19,7 +19,7 @@ func (self *FilesController) createResetMenu() error { menuItems := []*types.MenuItem{ { - DisplayStrings: []string{ + LabelColumns: []string{ self.c.Tr.LcDiscardAllChangesToAllFiles, red.Sprint(nukeStr), }, @@ -35,7 +35,7 @@ func (self *FilesController) createResetMenu() error { Tooltip: self.c.Tr.NukeDescription, }, { - DisplayStrings: []string{ + LabelColumns: []string{ self.c.Tr.LcDiscardAnyUnstagedChanges, red.Sprint("git checkout -- ."), }, @@ -50,7 +50,7 @@ func (self *FilesController) createResetMenu() error { Key: 'u', }, { - DisplayStrings: []string{ + LabelColumns: []string{ self.c.Tr.LcDiscardUntrackedFiles, red.Sprint("git clean -fd"), }, @@ -65,7 +65,7 @@ func (self *FilesController) createResetMenu() error { Key: 'c', }, { - DisplayStrings: []string{ + LabelColumns: []string{ self.c.Tr.LcSoftReset, red.Sprint("git reset --soft HEAD"), }, @@ -80,7 +80,7 @@ func (self *FilesController) createResetMenu() error { Key: 's', }, { - DisplayStrings: []string{ + LabelColumns: []string{ "mixed reset", red.Sprint("git reset --mixed HEAD"), }, @@ -95,7 +95,7 @@ func (self *FilesController) createResetMenu() error { Key: 'm', }, { - DisplayStrings: []string{ + LabelColumns: []string{ self.c.Tr.LcHardReset, red.Sprint("git reset --hard HEAD"), }, diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 6e1b2bdeb..7653550de 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -112,7 +112,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error { name := name menuItems = append(menuItems, []*types.MenuItem{ { - DisplayString: fmt.Sprintf("%s %s", gui.c.Tr.LcDiff, name), + Label: fmt.Sprintf("%s %s", gui.c.Tr.LcDiff, name), OnPress: func() error { gui.State.Modes.Diffing.Ref = name // can scope this down based on current view but too lazy right now @@ -124,7 +124,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error { menuItems = append(menuItems, []*types.MenuItem{ { - DisplayString: gui.c.Tr.LcEnterRefToDiff, + Label: gui.c.Tr.LcEnterRefToDiff, OnPress: func() error { return gui.c.Prompt(types.PromptOpts{ Title: gui.c.Tr.LcEnteRefName, @@ -141,14 +141,14 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error { if gui.State.Modes.Diffing.Active() { menuItems = append(menuItems, []*types.MenuItem{ { - DisplayString: gui.c.Tr.LcSwapDiff, + Label: gui.c.Tr.LcSwapDiff, OnPress: func() error { gui.State.Modes.Diffing.Reverse = !gui.State.Modes.Diffing.Reverse return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) }, }, { - DisplayString: gui.c.Tr.LcExitDiffMode, + Label: gui.c.Tr.LcExitDiffMode, OnPress: func() error { gui.State.Modes.Diffing = diffing.New() return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go index 6033f8516..c36f12a66 100644 --- a/pkg/gui/extras_panel.go +++ b/pkg/gui/extras_panel.go @@ -13,7 +13,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error { Title: gui.c.Tr.CommandLog, Items: []*types.MenuItem{ { - DisplayString: gui.c.Tr.ToggleShowCommandLog, + Label: gui.c.Tr.ToggleShowCommandLog, OnPress: func() error { currentContext := gui.currentStaticContext() if gui.ShowExtrasWindow && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY { @@ -29,8 +29,8 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error { }, }, { - DisplayString: gui.c.Tr.FocusCommandLog, - OnPress: gui.handleFocusCommandLog, + Label: gui.c.Tr.FocusCommandLog, + OnPress: gui.handleFocusCommandLog, }, }, }) diff --git a/pkg/gui/filtering_menu_panel.go b/pkg/gui/filtering_menu_panel.go index 7bcc26363..97327324e 100644 --- a/pkg/gui/filtering_menu_panel.go +++ b/pkg/gui/filtering_menu_panel.go @@ -26,7 +26,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { if fileName != "" { menuItems = append(menuItems, &types.MenuItem{ - DisplayString: fmt.Sprintf("%s '%s'", gui.c.Tr.LcFilterBy, fileName), + Label: fmt.Sprintf("%s '%s'", gui.c.Tr.LcFilterBy, fileName), OnPress: func() error { return gui.setFiltering(fileName) }, @@ -34,7 +34,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { } menuItems = append(menuItems, &types.MenuItem{ - DisplayString: gui.c.Tr.LcFilterPathOption, + Label: gui.c.Tr.LcFilterPathOption, OnPress: func() error { return gui.c.Prompt(types.PromptOpts{ FindSuggestionsFunc: gui.helpers.Suggestions.GetFilePathSuggestionsFunc(), @@ -48,8 +48,8 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { if gui.State.Modes.Filtering.Active() { menuItems = append(menuItems, &types.MenuItem{ - DisplayString: gui.c.Tr.LcExitFilterMode, - OnPress: gui.clearFiltering, + Label: gui.c.Tr.LcExitFilterMode, + OnPress: gui.clearFiltering, }) } diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 459fd60ce..59dd6b3a5 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -23,7 +23,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { if !opts.HideCancel { // this is mutative but I'm okay with that for now opts.Items = append(opts.Items, &types.MenuItem{ - DisplayStrings: []string{gui.c.Tr.LcCancel}, + LabelColumns: []string{gui.c.Tr.LcCancel}, OnPress: func() error { return nil }, @@ -31,7 +31,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { } for _, item := range opts.Items { - if item.OpensMenu && item.DisplayStrings != nil { + if item.OpensMenu && item.LabelColumns != nil { return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user") } } diff --git a/pkg/gui/options_menu_panel.go b/pkg/gui/options_menu_panel.go index f7baf10ad..539d3f4d7 100644 --- a/pkg/gui/options_menu_panel.go +++ b/pkg/gui/options_menu_panel.go @@ -65,7 +65,7 @@ func (gui *Gui) handleCreateOptionsMenu() error { menuItems := slices.Map(bindings, func(binding *types.Binding) *types.MenuItem { return &types.MenuItem{ - DisplayString: gui.displayDescription(binding), + Label: gui.displayDescription(binding), OnPress: func() error { if binding.Key == nil { return nil diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 30074f8d7..0ab300a40 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -15,38 +15,38 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error { menuItems := []*types.MenuItem{ { - DisplayString: "reset patch", - OnPress: gui.handleResetPatch, - Key: 'c', + Label: "reset patch", + OnPress: gui.handleResetPatch, + Key: 'c', }, { - DisplayString: "apply patch", - OnPress: func() error { return gui.handleApplyPatch(false) }, - Key: 'a', + Label: "apply patch", + OnPress: func() error { return gui.handleApplyPatch(false) }, + Key: 'a', }, { - DisplayString: "apply patch in reverse", - OnPress: func() error { return gui.handleApplyPatch(true) }, - Key: 'r', + Label: "apply patch in reverse", + OnPress: func() error { return gui.handleApplyPatch(true) }, + Key: 'r', }, } if gui.git.Patch.PatchManager.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE { menuItems = append(menuItems, []*types.MenuItem{ { - DisplayString: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To), - OnPress: gui.handleDeletePatchFromCommit, - Key: 'd', + Label: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To), + OnPress: gui.handleDeletePatchFromCommit, + Key: 'd', }, { - DisplayString: "move patch out into index", - OnPress: gui.handleMovePatchIntoWorkingTree, - Key: 'i', + Label: "move patch out into index", + OnPress: gui.handleMovePatchIntoWorkingTree, + Key: 'i', }, { - DisplayString: "move patch into new commit", - OnPress: gui.handlePullPatchIntoNewCommit, - Key: 'n', + Label: "move patch into new commit", + OnPress: gui.handlePullPatchIntoNewCommit, + Key: 'n', }, }...) @@ -59,9 +59,9 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error { append( []*types.MenuItem{ { - DisplayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), - OnPress: gui.handleMovePatchToSelectedCommit, - Key: 'm', + Label: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), + OnPress: gui.handleMovePatchToSelectedCommit, + Key: 'm', }, }, menuItems[1:]..., )..., diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 38684809b..86f1bd6ab 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -17,7 +17,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error { // we won't show the current repo hence the -1 menuItems := slices.Map(recentRepoPaths[1:], func(path string) *types.MenuItem { return &types.MenuItem{ - DisplayStrings: []string{ + LabelColumns: []string{ filepath.Base(path), style.FgMagenta.Sprint(path), }, diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go index dbae84de7..446ac95f4 100644 --- a/pkg/gui/services/custom_commands/handler_creator.go +++ b/pkg/gui/services/custom_commands/handler_creator.go @@ -102,7 +102,7 @@ func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrap func (self *HandlerCreator) menuPrompt(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error { menuItems := slices.Map(prompt.Options, func(option config.CustomCommandMenuOption) *types.MenuItem { return &types.MenuItem{ - DisplayStrings: []string{option.Name, style.FgYellow.Sprint(option.Description)}, + LabelColumns: []string{option.Name, style.FgYellow.Sprint(option.Description)}, OnPress: func() error { return wrappedF(option.Value) }, @@ -127,7 +127,7 @@ func (self *HandlerCreator) menuPromptFromCommand(prompt *config.CustomCommandPr menuItems := slices.Map(candidates, func(candidate *commandMenuEntry) *types.MenuItem { return &types.MenuItem{ - DisplayStrings: []string{candidate.label}, + LabelColumns: []string{candidate.label}, OnPress: func() error { return wrappedF(candidate.value) }, diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index cde535cd9..394fd2ed2 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -105,7 +105,7 @@ func (gui *Gui) askForConfigFile(action func(file string) error) error { default: menuItems := slices.Map(confPaths, func(path string) *types.MenuItem { return &types.MenuItem{ - DisplayString: path, + Label: path, OnPress: func() error { return action(path) }, diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index fc2eebf59..9272317f9 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -109,17 +109,21 @@ type PromptOpts struct { } type MenuItem struct { - DisplayString string - DisplayStrings []string - OnPress func() error - // only applies when displayString is used + Label string + + // alternative to Label. Allows specifying columns which will be auto-aligned + LabelColumns []string + + OnPress func() error + + // Only applies when Label is used OpensMenu bool - // if Key is defined it allows the user to press the key to invoke the menu + // If Key is defined it allows the user to press the key to invoke the menu // item, as opposed to having to navigate to it Key Key - // the tooltip will be displayed upon highlighting the menu item + // The tooltip will be displayed upon highlighting the menu item Tooltip string } From e67fef776bbc52626fb9551b3292a615b44bfacb Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 8 May 2022 14:23:29 +1000 Subject: [PATCH 2/2] add author email to commits --- pkg/commands/loaders/commits.go | 17 +++++---- pkg/commands/loaders/commits_test.go | 44 ++++++++++++++---------- pkg/commands/models/commit.go | 3 +- pkg/gui/presentation/commits.go | 4 +-- pkg/gui/presentation/graph/graph_test.go | 8 ++--- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/pkg/commands/loaders/commits.go b/pkg/commands/loaders/commits.go index fd6ce64a8..4a870643b 100644 --- a/pkg/commands/loaders/commits.go +++ b/pkg/commands/loaders/commits.go @@ -157,14 +157,15 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod // example input: // 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag func (self *CommitLoader) extractCommitFromLine(line string) *models.Commit { - split := strings.SplitN(line, "\x00", 6) + split := strings.SplitN(line, "\x00", 7) sha := split[0] unixTimestamp := split[1] - author := split[2] - extraInfo := strings.TrimSpace(split[3]) - parentHashes := split[4] - message := split[5] + authorName := split[2] + authorEmail := split[3] + extraInfo := strings.TrimSpace(split[4]) + parentHashes := split[5] + message := split[6] tags := []string{} @@ -189,7 +190,8 @@ func (self *CommitLoader) extractCommitFromLine(line string) *models.Commit { Tags: tags, ExtraInfo: extraInfo, UnixTimestamp: int64(unitTimestampInt), - Author: author, + AuthorName: authorName, + AuthorEmail: authorEmail, Parents: parents, } } @@ -446,7 +448,8 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj { } var prettyFormat = fmt.Sprintf( - "--pretty=format:\"%%H%s%%at%s%%aN%s%%d%s%%p%s%%s\"", + "--pretty=format:\"%%H%s%%at%s%%aN%s%%ae%s%%d%s%%p%s%%s\"", + NULL_CODE, NULL_CODE, NULL_CODE, NULL_CODE, diff --git a/pkg/commands/loaders/commits_test.go b/pkg/commands/loaders/commits_test.go index 5c1509287..e0e8fbad6 100644 --- a/pkg/commands/loaders/commits_test.go +++ b/pkg/commands/loaders/commits_test.go @@ -12,14 +12,14 @@ import ( "github.com/stretchr/testify/assert" ) -var commitsOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield| (HEAD -> better-tests)|b21997d6b4cbdf84b149|better typing for rebase mode -b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164|1640824515|Jesse Duffield| (origin/better-tests)|e94e8fc5b6fab4cb755f|fix logging -e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c|1640823749|Jesse Duffield||d8084cd558925eb7c9c3|refactor -d8084cd558925eb7c9c38afeed5725c21653ab90|1640821426|Jesse Duffield||65f910ebd85283b5cce9|WIP -65f910ebd85283b5cce9bf67d03d3f1a9ea3813a|1640821275|Jesse Duffield||26c07b1ab33860a1a759|WIP -26c07b1ab33860a1a7591a0638f9925ccf497ffa|1640750752|Jesse Duffield||3d4470a6c072208722e5|WIP -3d4470a6c072208722e5ae9a54bcb9634959a1c5|1640748818|Jesse Duffield||053a66a7be3da43aacdc|WIP -053a66a7be3da43aacdc7aa78e1fe757b82c4dd2|1640739815|Jesse Duffield||985fe482e806b172aea4|refactoring the config struct`, "|", "\x00", -1) +var commitsOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com| (HEAD -> better-tests)|b21997d6b4cbdf84b149|better typing for rebase mode +b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164|1640824515|Jesse Duffield|jessedduffield@gmail.com| (origin/better-tests)|e94e8fc5b6fab4cb755f|fix logging +e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c|1640823749|Jesse Duffield|jessedduffield@gmail.com||d8084cd558925eb7c9c3|refactor +d8084cd558925eb7c9c38afeed5725c21653ab90|1640821426|Jesse Duffield|jessedduffield@gmail.com||65f910ebd85283b5cce9|WIP +65f910ebd85283b5cce9bf67d03d3f1a9ea3813a|1640821275|Jesse Duffield|jessedduffield@gmail.com||26c07b1ab33860a1a759|WIP +26c07b1ab33860a1a7591a0638f9925ccf497ffa|1640750752|Jesse Duffield|jessedduffield@gmail.com||3d4470a6c072208722e5|WIP +3d4470a6c072208722e5ae9a54bcb9634959a1c5|1640748818|Jesse Duffield|jessedduffield@gmail.com||053a66a7be3da43aacdc|WIP +053a66a7be3da43aacdc7aa78e1fe757b82c4dd2|1640739815|Jesse Duffield|jessedduffield@gmail.com||985fe482e806b172aea4|refactoring the config struct`, "|", "\x00", -1) func TestGetCommits(t *testing.T) { type scenario struct { @@ -40,7 +40,7 @@ func TestGetCommits(t *testing.T) { opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, runner: oscommands.NewFakeRunner(t). Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). - Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%d%x00%p%x00%s" --abbrev=40`, "", nil), + Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, "", nil), expectedCommits: []*models.Commit{}, expectedError: nil, @@ -54,7 +54,7 @@ func TestGetCommits(t *testing.T) { // here it's seeing which commits are yet to be pushed Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). // here it's actually getting all the commits in a formatted form, one per line - Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%d%x00%p%x00%s" --abbrev=40`, commitsOutput, nil). + Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, commitsOutput, nil). // here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged' Expect(`git merge-base "HEAD" "master"`, "26c07b1ab33860a1a7591a0638f9925ccf497ffa", nil), @@ -66,7 +66,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "(HEAD -> better-tests)", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640826609, Parents: []string{ "b21997d6b4cbdf84b149", @@ -79,7 +80,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "(origin/better-tests)", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640824515, Parents: []string{ "e94e8fc5b6fab4cb755f", @@ -92,7 +94,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640823749, Parents: []string{ "d8084cd558925eb7c9c3", @@ -105,7 +108,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640821426, Parents: []string{ "65f910ebd85283b5cce9", @@ -118,7 +122,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640821275, Parents: []string{ "26c07b1ab33860a1a759", @@ -131,7 +136,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640750752, Parents: []string{ "3d4470a6c072208722e5", @@ -144,7 +150,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640748818, Parents: []string{ "053a66a7be3da43aacdc", @@ -157,7 +164,8 @@ func TestGetCommits(t *testing.T) { Action: "", Tags: []string{}, ExtraInfo: "", - Author: "Jesse Duffield", + AuthorName: "Jesse Duffield", + AuthorEmail: "jessedduffield@gmail.com", UnixTimestamp: 1640739815, Parents: []string{ "985fe482e806b172aea4", diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 641cc4242..0ca6a4365 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -17,7 +17,8 @@ type Commit struct { Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup" Tags []string ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2' - Author string // something like 'Jesse Duffield ' + AuthorName string // something like 'Jesse Duffield' + AuthorEmail string // something like 'jessedduffield@gmail.com' UnixTimestamp int64 // SHAs of parent commits (will be multiple if it's a merge commit) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 59802dabf..693b46337 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -156,7 +156,7 @@ func loadPipesets(commits []*models.Commit) [][]*graph.Pipe { // pipe sets are unique to a commit head. and a commit count. Sometimes we haven't loaded everything for that. // so let's just cache it based on that. getStyle := func(commit *models.Commit) style.TextStyle { - return authors.AuthorStyle(commit.Author) + return authors.AuthorStyle(commit.AuthorName) } pipeSets = graph.GetPipeSets(commits, getStyle) pipeSetCache[cacheKey] = pipeSets @@ -288,7 +288,7 @@ func displayCommit( cols = append( cols, actionString, - authorFunc(commit.Author), + authorFunc(commit.AuthorName), graphLine+tagString+theme.DefaultTextColor.Sprint(name), ) diff --git a/pkg/gui/presentation/graph/graph_test.go b/pkg/gui/presentation/graph/graph_test.go index 300042558..a6c60acf5 100644 --- a/pkg/gui/presentation/graph/graph_test.go +++ b/pkg/gui/presentation/graph/graph_test.go @@ -528,7 +528,7 @@ func TestGetNextPipes(t *testing.T) { func BenchmarkRenderCommitGraph(b *testing.B) { commits := generateCommits(50) getStyle := func(commit *models.Commit) style.TextStyle { - return authors.AuthorStyle(commit.Author) + return authors.AuthorStyle(commit.AuthorName) } b.ResetTimer() for i := 0; i < b.N; i++ { @@ -538,7 +538,7 @@ func BenchmarkRenderCommitGraph(b *testing.B) { func generateCommits(count int) []*models.Commit { rand.Seed(1234) - pool := []*models.Commit{{Sha: "a", Author: "A"}} + pool := []*models.Commit{{Sha: "a", AuthorName: "A"}} commits := make([]*models.Commit, 0, count) authorPool := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} for len(commits) < count { @@ -555,8 +555,8 @@ func generateCommits(count int) []*models.Commit { newParent = pool[j] } else { newParent = &models.Commit{ - Sha: fmt.Sprintf("%s%d", currentCommit.Sha, j), - Author: authorPool[rand.Intn(len(authorPool))], + Sha: fmt.Sprintf("%s%d", currentCommit.Sha, j), + AuthorName: authorPool[rand.Intn(len(authorPool))], } pool = append(pool, newParent) }