1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Bundle the reverse and keepOriginalHeader flags into a PatchOptions struct

We are going to add one more flag in the next commit.

Note that we are not using the struct inside patch_manager.go; we keep passing
the individual flags there. The reason for this will become more obvious later
in this branch.
This commit is contained in:
Stefan Haller
2023-02-26 13:20:10 +01:00
parent 5a50bfd179
commit f76cc27956
4 changed files with 29 additions and 14 deletions

View File

@ -181,7 +181,8 @@ func (self *StagingController) applySelection(reverse bool) error {
}
firstLineIdx, lastLineIdx := state.SelectedRange()
patch := patch.ModifiedPatchForRange(self.c.Log, path, state.GetDiff(), firstLineIdx, lastLineIdx, reverse, false)
patch := patch.ModifiedPatchForRange(self.c.Log, path, state.GetDiff(), firstLineIdx, lastLineIdx,
patch.PatchOptions{Reverse: reverse, KeepOriginalHeader: false})
if patch == "" {
return nil
@ -227,7 +228,8 @@ func (self *StagingController) editHunk() error {
hunk := state.CurrentHunk()
patchText := patch.ModifiedPatchForRange(
self.c.Log, path, state.GetDiff(), hunk.FirstLineIdx, hunk.LastLineIdx(), self.staged, false,
self.c.Log, path, state.GetDiff(), hunk.FirstLineIdx, hunk.LastLineIdx(),
patch.PatchOptions{Reverse: self.staged, KeepOriginalHeader: false},
)
patchFilepath, err := self.git.WorkingTree.SaveTemporaryPatch(patchText)
if err != nil {
@ -249,7 +251,8 @@ func (self *StagingController) editHunk() error {
lineCount := strings.Count(editedPatchText, "\n") + 1
newPatchText := patch.ModifiedPatchForRange(
self.c.Log, path, editedPatchText, 0, lineCount, false, false,
self.c.Log, path, editedPatchText, 0, lineCount,
patch.PatchOptions{Reverse: false, KeepOriginalHeader: false},
)
if err := self.git.WorkingTree.ApplyPatch(newPatchText, "cached"); err != nil {
return self.c.Error(err)