Skip to content

Commit e702411

Browse files
committed
fixup! Factor out CommitLoader.mainBranches into its own class, and store it in Model
1 parent 9de4d45 commit e702411

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type GetCommitsOptions struct {
6666
All bool
6767
// If non-empty, show divergence from this ref (left-right log)
6868
RefToShowDivergenceFrom string
69-
ExistingMainBranches *ExistingMainBranches
69+
MainBranches *MainBranches
7070
}
7171

7272
// GetCommits obtains the commits of the current branch
@@ -103,9 +103,9 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
103103
go utils.Safe(func() {
104104
defer wg.Done()
105105

106-
ancestor = opts.ExistingMainBranches.GetMergeBase(opts.RefName)
106+
ancestor = opts.MainBranches.GetMergeBase(opts.RefName)
107107
if opts.RefToShowDivergenceFrom != "" {
108-
remoteAncestor = opts.ExistingMainBranches.GetMergeBase(opts.RefToShowDivergenceFrom)
108+
remoteAncestor = opts.MainBranches.GetMergeBase(opts.RefToShowDivergenceFrom)
109109
}
110110
})
111111

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestGetCommits(t *testing.T) {
324324

325325
common.UserConfig.Git.MainBranches = scenario.mainBranches
326326
opts := scenario.opts
327-
opts.ExistingMainBranches = NewExistingMainBranches(scenario.mainBranches, cmd)
327+
opts.MainBranches = NewMainBranches(scenario.mainBranches, cmd)
328328
commits, err := builder.GetCommits(opts)
329329

330330
assert.Equal(t, scenario.expectedCommits, commits)

pkg/commands/git_commands/existing_main_branches.go renamed to pkg/commands/git_commands/main_branches.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,45 @@ import (
1010
"github.com/sasha-s/go-deadlock"
1111
)
1212

13-
type ExistingMainBranches struct {
13+
type MainBranches struct {
14+
// List of main branches configured by the user. Just the bare names.
1415
configuredMainBranches []string
15-
existingBranches []string
16+
// Which of these actually exist in the repository. Full ref names, and it
17+
// could be either "refs/heads/..." or "refs/remotes/origin/..." depending
18+
// on which one exists for a given bare name.
19+
existingMainBranches []string
1620

1721
cmd oscommands.ICmdObjBuilder
1822
mutex *deadlock.Mutex
1923
}
2024

21-
func NewExistingMainBranches(
25+
func NewMainBranches(
2226
configuredMainBranches []string,
2327
cmd oscommands.ICmdObjBuilder,
24-
) *ExistingMainBranches {
25-
return &ExistingMainBranches{
28+
) *MainBranches {
29+
return &MainBranches{
2630
configuredMainBranches: configuredMainBranches,
27-
existingBranches: nil,
31+
existingMainBranches: nil,
2832
cmd: cmd,
2933
mutex: &deadlock.Mutex{},
3034
}
3135
}
3236

33-
func (self *ExistingMainBranches) Get() []string {
37+
// Get the list of main branches that exist in the repository. This is a list of
38+
// full ref names.
39+
func (self *MainBranches) Get() []string {
3440
self.mutex.Lock()
3541
defer self.mutex.Unlock()
3642

37-
if self.existingBranches == nil {
38-
self.existingBranches = self.determineMainBranches()
43+
if self.existingMainBranches == nil {
44+
self.existingMainBranches = self.determineMainBranches()
3945
}
4046

41-
return self.existingBranches
47+
return self.existingMainBranches
4248
}
4349

4450
// Return the merge base of the given refName with the closest main branch.
45-
func (self *ExistingMainBranches) GetMergeBase(refName string) string {
51+
func (self *MainBranches) GetMergeBase(refName string) string {
4652
mainBranches := self.Get()
4753
if len(mainBranches) == 0 {
4854
return ""
@@ -65,7 +71,7 @@ func (self *ExistingMainBranches) GetMergeBase(refName string) string {
6571
return ignoringWarnings(output)
6672
}
6773

68-
func (self *ExistingMainBranches) determineMainBranches() []string {
74+
func (self *MainBranches) determineMainBranches() []string {
6975
var existingBranches []string
7076
var wg sync.WaitGroup
7177

pkg/gui/controllers/helpers/refresh_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
331331
RefName: self.refForLog(),
332332
RefForPushedStatus: checkedOutBranchName,
333333
All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(),
334-
ExistingMainBranches: self.c.Model().ExistingMainBranches,
334+
MainBranches: self.c.Model().MainBranches,
335335
},
336336
)
337337
if err != nil {
@@ -358,7 +358,7 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
358358
RefName: self.c.Contexts().SubCommits.GetRef().FullRefName(),
359359
RefToShowDivergenceFrom: self.c.Contexts().SubCommits.GetRefToShowDivergenceFrom(),
360360
RefForPushedStatus: self.c.Contexts().SubCommits.GetRef().FullRefName(),
361-
ExistingMainBranches: self.c.Model().ExistingMainBranches,
361+
MainBranches: self.c.Model().MainBranches,
362362
},
363363
)
364364
if err != nil {

pkg/gui/controllers/helpers/sub_commits_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
4444
RefName: opts.Ref.FullRefName(),
4545
RefForPushedStatus: opts.Ref.FullRefName(),
4646
RefToShowDivergenceFrom: opts.RefToShowDivergenceFrom,
47-
ExistingMainBranches: self.c.Model().ExistingMainBranches,
47+
MainBranches: self.c.Model().MainBranches,
4848
},
4949
)
5050
if err != nil {

pkg/gui/gui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
379379
BisectInfo: git_commands.NewNullBisectInfo(),
380380
FilesTrie: patricia.NewTrie(),
381381
Authors: map[string]*models.Author{},
382-
ExistingMainBranches: git_commands.NewExistingMainBranches(gui.UserConfig.Git.MainBranches, gui.os.Cmd),
382+
MainBranches: git_commands.NewMainBranches(gui.UserConfig.Git.MainBranches, gui.os.Cmd),
383383
},
384384
Modes: &types.Modes{
385385
Filtering: filtering.New(startArgs.FilterPath, ""),

pkg/gui/types/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ type Model struct {
281281
// we're on a detached head because we're rebasing or bisecting.
282282
CheckedOutBranch string
283283

284-
ExistingMainBranches *git_commands.ExistingMainBranches
284+
MainBranches *git_commands.MainBranches
285285

286286
// for displaying suggestions while typing in a file name
287287
FilesTrie *patricia.Trie

0 commit comments

Comments
 (0)