mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
Two things about a diff command follow from what its output is for: whether the diff renderer produces it, and whether it is coloured. That was a `plain` flag, which covers two of the three cases — the diff as configured, and git's own uncoloured diff for building patches out of — and leaves no room for the third, which is about to be needed: git's own diff, coloured, for showing where the renderer's version of it can't be acted on. So the flag becomes a mode. It also takes over deciding the colour, which each command spelled out for itself, and it settles a question the flag couldn't put: whether ignoring whitespace applies. It is about what the user wants to see, so it holds for anything shown, and not for a diff a patch is built from, which has to describe every change. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type ReflogCommitsController struct {
|
|
baseController
|
|
*ListControllerTrait[*models.Commit]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &ReflogCommitsController{}
|
|
|
|
func NewReflogCommitsController(
|
|
c *ControllerCommon,
|
|
) *ReflogCommitsController {
|
|
return &ReflogCommitsController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait(
|
|
c,
|
|
c.Contexts().ReflogCommits,
|
|
c.Contexts().ReflogCommits.GetSelected,
|
|
c.Contexts().ReflogCommits.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *ReflogCommitsController) Context() types.Context {
|
|
return self.context()
|
|
}
|
|
|
|
func (self *ReflogCommitsController) context() *context.ReflogCommitsContext {
|
|
return self.c.Contexts().ReflogCommits
|
|
}
|
|
|
|
func (self *ReflogCommitsController) GetFocusedMainViewDiffSource() types.FocusedMainViewDiffSource {
|
|
return self
|
|
}
|
|
|
|
// PlainDiff hands out the reflog entry's diff for the given files — the same diff its
|
|
// main view shows, only without the entry's message and stat above it.
|
|
func (self *ReflogCommitsController) PlainDiff(_ types.DiffPaneContext, paths []string) string {
|
|
commit := self.context().GetSelected()
|
|
if commit == nil {
|
|
return ""
|
|
}
|
|
return self.c.Helpers().Diff.PlainDiffBetweenRefs(commit.ParentRefName(), commit.RefName(), paths)
|
|
}
|
|
|
|
func (self *ReflogCommitsController) GetOnRenderToMain() func() {
|
|
return func() {
|
|
self.c.Helpers().Diff.WithDiffModeCheck(func() {
|
|
commit := self.context().GetSelected()
|
|
var task types.UpdateTask
|
|
if commit == nil {
|
|
task = types.NewRenderStringTask("No reflog history")
|
|
} else {
|
|
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.c.Helpers().Diff.FilterPathsForCommit(commit), git_commands.DiffModeRendered)
|
|
|
|
task = types.NewRunDiffRendererTask(cmdObj.GetCmd())
|
|
}
|
|
|
|
self.c.RenderToMainViews(types.RefreshMainOpts{
|
|
Pair: self.c.MainViewPairs().Normal,
|
|
Main: &types.ViewUpdateOpts{
|
|
Title: "Reflog Entry",
|
|
Task: task,
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|