fix(diff): load both blobs of renamed files for diff rendering (#39969)

When opening a pull request that renamed a CSV file:
the compare page fails with a 500.

Fix: load the left blob for every file that was not added, and the right blob
(from `Name`) for every file that was not deleted. That matches what the
templates did before #38517.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-10-24 08:44:16 +00:00
1 parent 1d8474ee1f
commit 497e169398
2 files changed
+40 -3

No files matched your search

+3 -3
View File
@@ -522,13 +522,13 @@ func (diffFile *DiffFile) prepareDiffRenderDetail(ctx context.Context, gitRepo *
// * for "text" type: need to read up to "highlight limit size" to do full-file-highlighting
contentLimit := util.Iif(diffFile.IsBin, typesniffer.SniffContentSize, MaxFullFileHighlightSizeLimit)
var leftBlobType, rightBlobType typesniffer.SniffedType
if (diffFile.Type == DiffFileDel || diffFile.Type == DiffFileChange) && leftCommit != nil {
if diffFile.Type != DiffFileAdd && leftCommit != nil {
c := getCommitFileBlobAndLimitedContent(ctx, gitRepo, leftCommit, diffFile.OldName, contentLimit)
diffFile.LeftBlob, diffFile.LeftBlobSize, ret.leftLineCount, ret.leftContent = c.gitBlob, c.blobSize, c.lineCount, c.limitedContent
leftBlobType = typesniffer.DetectContentType(ret.leftContent.buf.Bytes())
}
if (diffFile.Type == DiffFileAdd || diffFile.Type == DiffFileChange) && rightCommit != nil {
c := getCommitFileBlobAndLimitedContent(ctx, gitRepo, rightCommit, diffFile.OldName, contentLimit)
if diffFile.Type != DiffFileDel && rightCommit != nil {
c := getCommitFileBlobAndLimitedContent(ctx, gitRepo, rightCommit, diffFile.Name, contentLimit)
diffFile.RightBlob, diffFile.RightBlobSize, ret.rightLineCount, ret.rightContent = c.gitBlob, c.blobSize, c.lineCount, c.limitedContent
rightBlobType = typesniffer.DetectContentType(ret.rightContent.buf.Bytes())
}