0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 23:53:11 +02:00
This commit is contained in:
wxiaoguang 2025-07-12 00:40:36 +08:00
parent 0ed2e89b14
commit 76118813ba

View File

@ -120,11 +120,9 @@ func ParseDiffHunkString(diffHunk string) (leftLine, leftHunk, rightLine, rightH
rightHunk = leftHunk
}
if rightLine == 0 {
// "git diff" outputs 2 different formats for the same change "OLD" => "A\nB\nC"
// * "@@ -1 +1,3 @@": the expected result
// * "@@ -1,1 +0,4 @@": the "0" means "insert before the first line"
// FIXME: GIT-DIFF-CUT-BUG search this tag to see details
// this is only a hacky patch, the rightLine&rightHunk might still be incorrect in some cases.
rightLine++
rightHunk--
}
return leftLine, leftHunk, rightLine, rightHunk
}
@ -277,6 +275,11 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
oldNumOfLines++
}
}
// "git diff" outputs "@@ -1 +1,3 @@" for "OLD" => "A\nB\nC"
// FIXME: GIT-DIFF-CUT-BUG But there is a bug in CutDiffAroundLine, then the "Patch" stored in the comment model becomes "@@ -1,1 +0,4 @@"
// It may generate incorrect results for difference cases, for example: delete 2 line add 1 line, delete 2 line add 2 line etc, need to double check.
// construct the new hunk header
newHunk[headerLines] = fmt.Sprintf("@@ -%d,%d +%d,%d @@",
oldBegin, oldNumOfLines, newBegin, newNumOfLines)