@@ -149,14 +149,9 @@ func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection {
149149 return DiffLineExpandSingle
150150}
151151
152- func getDiffLineSectionInfo (curFile * DiffFile , line string , lastLeftIdx , lastRightIdx int ) * DiffLineSectionInfo {
153- var (
154- leftLine int
155- leftHunk int
156- rightLine int
157- righHunk int
158- )
159- ss := strings .Split (line , "@@" )
152+ // ParseDiffHunkString parse the diffhunk content and return
153+ func ParseDiffHunkString (diffhunk string ) (leftLine , leftHunk , rightLine , righHunk int ) {
154+ ss := strings .Split (diffhunk , "@@" )
160155 ranges := strings .Split (ss [1 ][1 :], " " )
161156 leftRange := strings .Split (ranges [0 ], "," )
162157 leftLine , _ = com .StrTo (leftRange [0 ][1 :]).Int ()
@@ -170,12 +165,18 @@ func getDiffLineSectionInfo(curFile *DiffFile, line string, lastLeftIdx, lastRig
170165 righHunk , _ = com .StrTo (rightRange [1 ]).Int ()
171166 }
172167 } else {
173- log .Warn ("Parse line number failed: %v" , line )
168+ log .Warn ("Parse line number failed: %v" , diffhunk )
174169 rightLine = leftLine
175170 righHunk = leftHunk
176171 }
172+ return
173+ }
174+
175+ func getDiffLineSectionInfo (treePath , line string , lastLeftIdx , lastRightIdx int ) * DiffLineSectionInfo {
176+ leftLine , leftHunk , rightLine , righHunk := ParseDiffHunkString (line )
177+
177178 return & DiffLineSectionInfo {
178- Path : curFile . Name ,
179+ Path : treePath ,
179180 LastLeftIdx : lastLeftIdx ,
180181 LastRightIdx : lastRightIdx ,
181182 LeftIdx : leftLine ,
@@ -651,7 +652,7 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
651652 case line [0 ] == '@' :
652653 curSection = & DiffSection {}
653654 curFile .Sections = append (curFile .Sections , curSection )
654- lineSectionInfo := getDiffLineSectionInfo (curFile , line , leftLine - 1 , rightLine - 1 )
655+ lineSectionInfo := getDiffLineSectionInfo (curFile . Name , line , leftLine - 1 , rightLine - 1 )
655656 diffLine := & DiffLine {
656657 Type : DiffLineSection ,
657658 Content : line ,
0 commit comments