1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

Remove the PatchOptions.Reverse option

All callers pass false now (except for the tests, which we simply remove), so we
don't need the option any more.
This commit is contained in:
Stefan Haller
2023-03-07 09:31:38 +01:00
parent e4659145e8
commit 45cf993982
5 changed files with 12 additions and 201 deletions

View File

@@ -45,7 +45,7 @@ func headerInfo(header string) (int, int, string) {
return oldStart, newStart, heading
}
func (hunk *PatchHunk) updatedLines(lineIndices []int, reverse bool, willBeAppliedReverse bool) []string {
func (hunk *PatchHunk) updatedLines(lineIndices []int, willBeAppliedReverse bool) []string {
skippedNewlineMessageIndex := -1
newLines := []string{}
@@ -58,7 +58,7 @@ func (hunk *PatchHunk) updatedLines(lineIndices []int, reverse bool, willBeAppli
isLineSelected := lo.Contains(lineIndices, lineIdx)
firstChar, content := line[:1], line[1:]
transformedFirstChar := transformedFirstChar(firstChar, reverse, willBeAppliedReverse, isLineSelected)
transformedFirstChar := transformedFirstChar(firstChar, willBeAppliedReverse, isLineSelected)
if isLineSelected || (transformedFirstChar == "\\" && skippedNewlineMessageIndex != lineIdx) || transformedFirstChar == " " {
newLines = append(newLines, transformedFirstChar+content)
@@ -74,19 +74,7 @@ func (hunk *PatchHunk) updatedLines(lineIndices []int, reverse bool, willBeAppli
return newLines
}
func transformedFirstChar(firstChar string, reverse bool, willBeAppliedReverse bool, isLineSelected bool) string {
if reverse {
if !isLineSelected && firstChar == "+" {
return " "
} else if firstChar == "-" {
return "+"
} else if firstChar == "+" {
return "-"
} else {
return firstChar
}
}
func transformedFirstChar(firstChar string, willBeAppliedReverse bool, isLineSelected bool) string {
linesToKeepInPatchContext := "-"
if willBeAppliedReverse {
linesToKeepInPatchContext = "+"
@@ -102,16 +90,16 @@ func (hunk *PatchHunk) formatHeader(oldStart int, oldLength int, newStart int, n
return fmt.Sprintf("@@ -%d,%d +%d,%d @@%s\n", oldStart, oldLength, newStart, newLength, heading)
}
func (hunk *PatchHunk) formatWithChanges(lineIndices []int, reverse bool, willBeAppliedReverse bool, startOffset int) (int, string) {
bodyLines := hunk.updatedLines(lineIndices, reverse, willBeAppliedReverse)
startOffset, header, ok := hunk.updatedHeader(bodyLines, startOffset, reverse)
func (hunk *PatchHunk) formatWithChanges(lineIndices []int, willBeAppliedReverse bool, startOffset int) (int, string) {
bodyLines := hunk.updatedLines(lineIndices, willBeAppliedReverse)
startOffset, header, ok := hunk.updatedHeader(bodyLines, startOffset)
if !ok {
return startOffset, ""
}
return startOffset, header + strings.Join(bodyLines, "")
}
func (hunk *PatchHunk) updatedHeader(newBodyLines []string, startOffset int, reverse bool) (int, string, bool) {
func (hunk *PatchHunk) updatedHeader(newBodyLines []string, startOffset int) (int, string, bool) {
changeCount := nLinesWithPrefix(newBodyLines, []string{"+", "-"})
oldLength := nLinesWithPrefix(newBodyLines, []string{" ", "-"})
newLength := nLinesWithPrefix(newBodyLines, []string{"+", " "})
@@ -121,12 +109,7 @@ func (hunk *PatchHunk) updatedHeader(newBodyLines []string, startOffset int, rev
return startOffset, "", false
}
var oldStart int
if reverse {
oldStart = hunk.newStart
} else {
oldStart = hunk.oldStart
}
oldStart := hunk.oldStart
var newStartOffset int
// if the hunk went from zero to positive length, we need to increment the starting point by one