1
1
mirror of https://github.com/go-gitea/gitea synced 2025-12-06 21:08:25 +00:00

Fix diff blob excerpt expansion (#35922)

And add comments and tests
This commit is contained in:
wxiaoguang
2025-11-14 12:50:48 +08:00
committed by GitHub
parent d6dc531d4b
commit 0fb3be7f0e
3 changed files with 171 additions and 33 deletions

View File

@@ -9,7 +9,6 @@ import (
"encoding/csv"
"errors"
"fmt"
"html"
"io"
"net/http"
"net/url"
@@ -957,30 +956,26 @@ func ExcerptBlob(ctx *context.Context) {
ctx.HTTPError(http.StatusInternalServerError, "getExcerptLines")
return
}
if idxRight > lastRight {
lineText := " "
if rightHunkSize > 0 || leftHunkSize > 0 {
lineText = fmt.Sprintf("@@ -%d,%d +%d,%d @@\n", idxLeft, leftHunkSize, idxRight, rightHunkSize)
}
lineText = html.EscapeString(lineText)
lineSection := &gitdiff.DiffLine{
Type: gitdiff.DiffLineSection,
Content: lineText,
SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: filePath,
LastLeftIdx: lastLeft,
LastRightIdx: lastRight,
LeftIdx: idxLeft,
RightIdx: idxRight,
LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize,
},
}
newLineSection := &gitdiff.DiffLine{
Type: gitdiff.DiffLineSection,
SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: filePath,
LastLeftIdx: lastLeft,
LastRightIdx: lastRight,
LeftIdx: idxLeft,
RightIdx: idxRight,
LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize,
},
}
if newLineSection.GetExpandDirection() != "" {
newLineSection.Content = fmt.Sprintf("@@ -%d,%d +%d,%d @@\n", idxLeft, leftHunkSize, idxRight, rightHunkSize)
switch direction {
case "up":
section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
section.Lines = append([]*gitdiff.DiffLine{newLineSection}, section.Lines...)
case "down":
section.Lines = append(section.Lines, lineSection)
section.Lines = append(section.Lines, newLineSection)
}
}