From 76118813ba00dd92ae234807a38a0461cf0f867d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 12 Jul 2025 00:40:36 +0800 Subject: [PATCH] correct --- modules/git/diff.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/git/diff.go b/modules/git/diff.go index 5ec21761ed..d4a3902727 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -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)