@@ -99,9 +99,9 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
9999 return nil
100100}
101101
102- // ParseDiffHunkString parse the diffhunk content and return
103- func ParseDiffHunkString (diffhunk string ) (leftLine , leftHunk , rightLine , righHunk int ) {
104- ss := strings .Split (diffhunk , "@@" )
102+ // ParseDiffHunkString parse the diff hunk content and return
103+ func ParseDiffHunkString (diffHunk string ) (leftLine , leftHunk , rightLine , rightHunk int ) {
104+ ss := strings .Split (diffHunk , "@@" )
105105 ranges := strings .Split (ss [1 ][1 :], " " )
106106 leftRange := strings .Split (ranges [0 ], "," )
107107 leftLine , _ = strconv .Atoi (leftRange [0 ][1 :])
@@ -112,14 +112,19 @@ func ParseDiffHunkString(diffhunk string) (leftLine, leftHunk, rightLine, righHu
112112 rightRange := strings .Split (ranges [1 ], "," )
113113 rightLine , _ = strconv .Atoi (rightRange [0 ])
114114 if len (rightRange ) > 1 {
115- righHunk , _ = strconv .Atoi (rightRange [1 ])
115+ rightHunk , _ = strconv .Atoi (rightRange [1 ])
116116 }
117117 } else {
118- log .Debug ("Parse line number failed: %v" , diffhunk )
118+ log .Debug ("Parse line number failed: %v" , diffHunk )
119119 rightLine = leftLine
120- righHunk = leftHunk
120+ rightHunk = leftHunk
121121 }
122- return leftLine , leftHunk , rightLine , righHunk
122+ if rightLine == 0 {
123+ // FIXME: GIT-DIFF-CUT-BUG search this tag to see details
124+ // this is only a hacky patch, the rightLine&rightHunk might still be incorrect in some cases.
125+ rightLine ++
126+ }
127+ return leftLine , leftHunk , rightLine , rightHunk
123128}
124129
125130// Example: @@ -1,8 +1,9 @@ => [..., 1, 8, 1, 9]
@@ -270,6 +275,12 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
270275 oldNumOfLines ++
271276 }
272277 }
278+
279+ // "git diff" outputs "@@ -1 +1,3 @@" for "OLD" => "A\nB\nC"
280+ // 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 @@"
281+ // 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.
282+ // For example: "L1\nL2" => "A\nB", then the patch shows "L2" as line 1 on the left (deleted part)
283+
273284 // construct the new hunk header
274285 newHunk [headerLines ] = fmt .Sprintf ("@@ -%d,%d +%d,%d @@" ,
275286 oldBegin , oldNumOfLines , newBegin , newNumOfLines )
0 commit comments