mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
more efficient refreshing of rebase commits
This commit is contained in:
parent
f99d5f74d4
commit
40bec49de8
5 changed files with 74 additions and 34 deletions
|
@ -28,21 +28,19 @@ const SEPARATION_CHAR = "|"
|
||||||
|
|
||||||
// CommitListBuilder returns a list of Branch objects for the current repo
|
// CommitListBuilder returns a list of Branch objects for the current repo
|
||||||
type CommitListBuilder struct {
|
type CommitListBuilder struct {
|
||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
GitCommand *GitCommand
|
GitCommand *GitCommand
|
||||||
OSCommand *OSCommand
|
OSCommand *OSCommand
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
CherryPickedCommits []*Commit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommitListBuilder builds a new commit list builder
|
// NewCommitListBuilder builds a new commit list builder
|
||||||
func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *OSCommand, tr *i18n.Localizer, cherryPickedCommits []*Commit) *CommitListBuilder {
|
func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *OSCommand, tr *i18n.Localizer) *CommitListBuilder {
|
||||||
return &CommitListBuilder{
|
return &CommitListBuilder{
|
||||||
Log: log,
|
Log: log,
|
||||||
GitCommand: gitCommand,
|
GitCommand: gitCommand,
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: tr,
|
Tr: tr,
|
||||||
CherryPickedCommits: cherryPickedCommits,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,28 +92,53 @@ type GetCommitsOptions struct {
|
||||||
RefName string // e.g. "HEAD" or "my_branch"
|
RefName string // e.g. "HEAD" or "my_branch"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CommitListBuilder) MergeRebasingCommits(commits []*Commit) ([]*Commit, error) {
|
||||||
|
// chances are we have as many commits as last time so we'll set the capacity to be the old length
|
||||||
|
result := make([]*Commit, 0, len(commits))
|
||||||
|
for i, commit := range commits {
|
||||||
|
if commit.Status != "rebasing" { // removing the existing rebase commits so we can add the refreshed ones
|
||||||
|
result = append(result, commits[i:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rebaseMode, err := c.GitCommand.RebaseMode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if rebaseMode == "" {
|
||||||
|
// not in rebase mode so return original commits
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
rebasingCommits, err := c.getRebasingCommits(rebaseMode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(rebasingCommits) > 0 {
|
||||||
|
result = append(rebasingCommits, result...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetCommits obtains the commits of the current branch
|
// GetCommits obtains the commits of the current branch
|
||||||
func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error) {
|
func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error) {
|
||||||
commits := []*Commit{}
|
commits := []*Commit{}
|
||||||
var rebasingCommits []*Commit
|
var rebasingCommits []*Commit
|
||||||
rebaseMode := ""
|
rebaseMode, err := c.GitCommand.RebaseMode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if opts.IncludeRebaseCommits {
|
if opts.IncludeRebaseCommits && opts.FilterPath == "" {
|
||||||
var err error
|
var err error
|
||||||
rebaseMode, err = c.GitCommand.RebaseMode()
|
rebasingCommits, err = c.MergeRebasingCommits(commits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if rebaseMode != "" && opts.FilterPath == "" {
|
commits = append(commits, rebasingCommits...)
|
||||||
// here we want to also prepend the commits that we're in the process of rebasing
|
|
||||||
rebasingCommits, err = c.getRebasingCommits(rebaseMode)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(rebasingCommits) > 0 {
|
|
||||||
commits = append(commits, rebasingCommits...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
passedFirstPushedCommit := false
|
passedFirstPushedCommit := false
|
||||||
|
|
|
@ -13,11 +13,10 @@ func NewDummyCommitListBuilder() *CommitListBuilder {
|
||||||
osCommand := NewDummyOSCommand()
|
osCommand := NewDummyOSCommand()
|
||||||
|
|
||||||
return &CommitListBuilder{
|
return &CommitListBuilder{
|
||||||
Log: NewDummyLog(),
|
Log: NewDummyLog(),
|
||||||
GitCommand: NewDummyGitCommandWithOSCommand(osCommand),
|
GitCommand: NewDummyGitCommandWithOSCommand(osCommand),
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: i18n.NewLocalizer(NewDummyLog()),
|
Tr: i18n.NewLocalizer(NewDummyLog()),
|
||||||
CherryPickedCommits: []*Commit{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,10 @@ func (gui *Gui) refreshCommits() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshCommitsWithLimit() error {
|
func (gui *Gui) refreshCommitsWithLimit() error {
|
||||||
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.Modes.CherryPicking.CherryPickedCommits)
|
gui.State.BranchCommitsMutex.Lock()
|
||||||
|
defer gui.State.BranchCommitsMutex.Unlock()
|
||||||
|
|
||||||
|
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr)
|
||||||
|
|
||||||
commits, err := builder.GetCommits(
|
commits, err := builder.GetCommits(
|
||||||
commands.GetCommitsOptions{
|
commands.GetCommitsOptions{
|
||||||
|
@ -115,6 +118,21 @@ func (gui *Gui) refreshCommitsWithLimit() error {
|
||||||
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context)
|
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) refreshRebaseCommits() error {
|
||||||
|
gui.State.BranchCommitsMutex.Lock()
|
||||||
|
defer gui.State.BranchCommitsMutex.Unlock()
|
||||||
|
|
||||||
|
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr)
|
||||||
|
|
||||||
|
updatedCommits, err := builder.MergeRebasingCommits(gui.State.Commits)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
gui.State.Commits = updatedCommits
|
||||||
|
|
||||||
|
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context)
|
||||||
|
}
|
||||||
|
|
||||||
// specific functions
|
// specific functions
|
||||||
|
|
||||||
func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
@ -256,9 +274,8 @@ func (gui *Gui) handleMidRebaseCommand(action string) (bool, error) {
|
||||||
if err := gui.GitCommand.EditRebaseTodo(gui.State.Panels.Commits.SelectedLineIdx, action); err != nil {
|
if err := gui.GitCommand.EditRebaseTodo(gui.State.Panels.Commits.SelectedLineIdx, action); err != nil {
|
||||||
return false, gui.surfaceError(err)
|
return false, gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
// TODO: consider doing this in a way that is less expensive. We don't actually
|
|
||||||
// need to reload all the commits, just the TODO commits.
|
return true, gui.refreshRebaseCommits()
|
||||||
return true, gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS}})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
|
|
@ -297,6 +297,7 @@ type guiState struct {
|
||||||
RefreshingFilesMutex sync.Mutex
|
RefreshingFilesMutex sync.Mutex
|
||||||
RefreshingStatusMutex sync.Mutex
|
RefreshingStatusMutex sync.Mutex
|
||||||
FetchMutex sync.Mutex
|
FetchMutex sync.Mutex
|
||||||
|
BranchCommitsMutex sync.Mutex
|
||||||
Searching searchingState
|
Searching searchingState
|
||||||
ScreenMode int
|
ScreenMode int
|
||||||
SideView *gocui.View
|
SideView *gocui.View
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (gui *Gui) handleViewSubCommitFiles() error {
|
||||||
|
|
||||||
func (gui *Gui) switchToSubCommitsContext(refName string) error {
|
func (gui *Gui) switchToSubCommitsContext(refName string) error {
|
||||||
// need to populate my sub commits
|
// need to populate my sub commits
|
||||||
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.Modes.CherryPicking.CherryPickedCommits)
|
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr)
|
||||||
|
|
||||||
commits, err := builder.GetCommits(
|
commits, err := builder.GetCommits(
|
||||||
commands.GetCommitsOptions{
|
commands.GetCommitsOptions{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue