mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
Refactor commit loading and reflog commit loading to extract shared code
These are very similar in that they call RunAndProcessLines on a git log command and then process lines to create commits. Extract this into a common helper function. At the moment this doesn't gain us much, but in the next commit we will extend this helper function considerably with filter path logic, which would otherwise have to be duplicated in both places.
This commit is contained in:
23
pkg/commands/git_commands/commit_loading_shared.go
Normal file
23
pkg/commands/git_commands/commit_loading_shared.go
Normal file
@ -0,0 +1,23 @@
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
)
|
||||
|
||||
func loadCommits(
|
||||
cmd *oscommands.CmdObj,
|
||||
parseLogLine func(string) (*models.Commit, bool),
|
||||
) ([]*models.Commit, error) {
|
||||
commits := []*models.Commit{}
|
||||
|
||||
err := cmd.RunAndProcessLines(func(line string) (bool, error) {
|
||||
commit, stop := parseLogLine(line)
|
||||
if stop {
|
||||
return true, nil
|
||||
}
|
||||
commits = append(commits, commit)
|
||||
return false, nil
|
||||
})
|
||||
return commits, err
|
||||
}
|
Reference in New Issue
Block a user