MCPcopy
hub / github.com/jesseduffield/lazygit / GetCommits

Method GetCommits

pkg/commands/git_commands/commit_loader.go:74–153  ·  view source on GitHub ↗

GetCommits obtains the commits of the current branch

(opts GetCommitsOptions)

Source from the content-addressed store, hash-verified

72
73// GetCommits obtains the commits of the current branch
74func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) {
75 commits := []*models.Commit{}
76
77 if opts.IncludeRebaseCommits && opts.FilterPath == "" {
78 var err error
79 commits, err = self.MergeRebasingCommits(opts.HashPool, commits)
80 if err != nil {
81 return nil, err
82 }
83 }
84
85 wg := sync.WaitGroup{}
86
87 wg.Add(2)
88
89 var logErr error
90 go utils.Safe(func() {
91 defer wg.Done()
92
93 var realCommits []*models.Commit
94 realCommits, logErr = loadCommits(self.getLogCmd(opts), opts.FilterPath, func(line string) (*models.Commit, bool) {
95 return self.extractCommitFromLine(opts.HashPool, line, opts.RefToShowDivergenceFrom != ""), false
96 })
97 if logErr == nil {
98 commits = append(commits, realCommits...)
99 }
100 })
101
102 var unmergedCommitHashes *set.Set[string]
103 var remoteUnmergedCommitHashes *set.Set[string]
104 mainBranches := opts.MainBranches.Get()
105
106 go utils.Safe(func() {
107 defer wg.Done()
108
109 if len(mainBranches) > 0 {
110 unmergedCommitHashes = self.getReachableHashes(opts.RefName, mainBranches)
111 if opts.RefToShowDivergenceFrom != "" {
112 remoteUnmergedCommitHashes = self.getReachableHashes(opts.RefToShowDivergenceFrom, mainBranches)
113 }
114 }
115 })
116
117 var unpushedCommitHashes *set.Set[string]
118 if opts.RefForPushedStatus != nil {
119 unpushedCommitHashes = self.getReachableHashes(opts.RefForPushedStatus.FullRefName(),
120 append([]string{opts.RefForPushedStatus.RefName() + "@{u}"}, mainBranches...))
121 }
122
123 wg.Wait()
124
125 if logErr != nil {
126 return nil, logErr
127 }
128
129 if len(commits) == 0 {
130 return commits, nil
131 }

Callers 1

TestGetCommitsFunction · 0.95

Calls 13

MergeRebasingCommitsMethod · 0.95
getLogCmdMethod · 0.95
extractCommitFromLineMethod · 0.95
getReachableHashesMethod · 0.95
SafeFunction · 0.92
loadCommitsFunction · 0.85
setCommitStatusesFunction · 0.85
DoneMethod · 0.65
GetMethod · 0.65
FullRefNameMethod · 0.65
RefNameMethod · 0.65
AddMethod · 0.45

Tested by 1

TestGetCommitsFunction · 0.76