From f23beb0ecfaded69604aa5e5627b205ca0f3b492 Mon Sep 17 00:00:00 2001 From: Surya Purohit Date: Thu, 16 Oct 2025 10:30:51 +0530 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20(lfs)=20fixes=20filesize=20o?= =?UTF-8?q?f=20the=20LFS=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shows the main LFS filesize instead of the pointer filesize when viewing a file --- routers/web/repo/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e47bc56d081a6..5d1fca4d41b04 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -114,7 +114,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) (buf []b } buf = buf[:n] fi.st = typesniffer.DetectContentType(buf) - fi.fileSize = blob.Size() + fi.fileSize = meta.Pointer.Size fi.lfsMeta = &meta.Pointer return buf, dataRc, fi, nil } From bd0221887bb3c7bd70f51f43bb46eb23d83128c7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 16 Oct 2025 14:24:41 +0800 Subject: [PATCH 2/3] use blobOrLfsSize instead of fileSize --- routers/web/repo/editor.go | 4 ++-- routers/web/repo/view.go | 10 +++++----- routers/web/repo/view_file.go | 4 ++-- routers/web/repo/view_readme.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 2a5ac102824d9..8c630cb35f0a6 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -295,14 +295,14 @@ func EditFile(ctx *context.Context) { } defer dataRc.Close() - ctx.Data["FileSize"] = fInfo.fileSize + ctx.Data["FileSize"] = fInfo.blobOrLfsSize // Only some file types are editable online as text. if fInfo.isLFSFile() { ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_lfs_files") } else if !fInfo.st.IsRepresentableAsText() { ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_non_text_files") - } else if fInfo.fileSize >= setting.UI.MaxDisplayFileSize { + } else if fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize { ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_too_large_file") } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 5d1fca4d41b04..d294934622cbb 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -60,9 +60,9 @@ const ( ) type fileInfo struct { - fileSize int64 - lfsMeta *lfs.Pointer - st typesniffer.SniffedType + blobOrLfsSize int64 + lfsMeta *lfs.Pointer + st typesniffer.SniffedType } func (fi *fileInfo) isLFSFile() bool { @@ -81,7 +81,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) (buf []b n, _ := util.ReadAtMost(dataRc, buf) buf = buf[:n] - fi = &fileInfo{fileSize: blob.Size(), st: typesniffer.DetectContentType(buf)} + fi = &fileInfo{blobOrLfsSize: blob.Size(), st: typesniffer.DetectContentType(buf)} // FIXME: what happens when README file is an image? if !fi.st.IsText() || !setting.LFS.StartServer { @@ -114,7 +114,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) (buf []b } buf = buf[:n] fi.st = typesniffer.DetectContentType(buf) - fi.fileSize = meta.Pointer.Size + fi.blobOrLfsSize = meta.Pointer.Size fi.lfsMeta = &meta.Pointer return buf, dataRc, fi, nil } diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go index 2d5bddd939f10..8bb9fb62a786e 100644 --- a/routers/web/repo/view_file.go +++ b/routers/web/repo/view_file.go @@ -226,7 +226,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) { } ctx.Data["IsLFSFile"] = fInfo.isLFSFile() - ctx.Data["FileSize"] = fInfo.fileSize + ctx.Data["FileSize"] = fInfo.blobOrLfsSize ctx.Data["IsRepresentableAsText"] = fInfo.st.IsRepresentableAsText() ctx.Data["IsExecutable"] = entry.IsExecutable() ctx.Data["CanCopyContent"] = fInfo.st.IsRepresentableAsText() || fInfo.st.IsImage() @@ -243,7 +243,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) { utf8Reader := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{}) switch { - case fInfo.fileSize >= setting.UI.MaxDisplayFileSize: + case fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize: ctx.Data["IsFileTooLarge"] = true case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, utf8Reader): // it also sets ctx.Data["FileContent"] and more diff --git a/routers/web/repo/view_readme.go b/routers/web/repo/view_readme.go index ba03febff3ddf..edf38b7892523 100644 --- a/routers/web/repo/view_readme.go +++ b/routers/web/repo/view_readme.go @@ -170,7 +170,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil ctx.Data["FileIsText"] = fInfo.st.IsText() ctx.Data["FileTreePath"] = readmeFullPath - ctx.Data["FileSize"] = fInfo.fileSize + ctx.Data["FileSize"] = fInfo.blobOrLfsSize ctx.Data["IsLFSFile"] = fInfo.isLFSFile() if fInfo.isLFSFile() { @@ -182,7 +182,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil return } - if fInfo.fileSize >= setting.UI.MaxDisplayFileSize { + if fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize { // Pretend that this is a normal text file to display 'This file is too large to be shown' ctx.Data["IsFileTooLarge"] = true return From 7ddf3b2ffba3ce6f207ec5f9a4311180d64c822e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 16 Oct 2025 14:43:53 +0800 Subject: [PATCH 3/3] add more tests --- templates/repo/file_info.tmpl | 4 ++-- tests/integration/lfs_view_test.go | 2 ++ tests/integration/repo_test.go | 2 ++ web_src/css/repo.css | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/repo/file_info.tmpl b/templates/repo/file_info.tmpl index 38133bde2bd79..664f1442f9119 100644 --- a/templates/repo/file_info.tmpl +++ b/templates/repo/file_info.tmpl @@ -11,11 +11,11 @@ {{end}} {{if ne .FileSize nil}}
- {{FileSize .FileSize}}{{if .IsLFSFile}}LFS{{end}} + {{FileSize .FileSize}}{{if .IsLFSFile}}LFS{{end}}
{{end}} {{if .LFSLock}} -
+
{{svg "octicon-lock" 16 "tw-mr-1"}} {{.LFSLockOwner}}
diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go index 3140f491c9e43..bbfbb0e6ec0ff 100644 --- a/tests/integration/lfs_view_test.go +++ b/tests/integration/lfs_view_test.go @@ -72,6 +72,8 @@ func TestLFSRender(t *testing.T) { fileInfo := doc.Find("div.file-info-entry").First().Text() assert.Contains(t, fileInfo, "LFS") + fileSize := doc.Find("div.file-info-entry > .file-info-size").Text() + assert.Equal(t, "2.0 KiB", fileSize) // find new file view container fileViewContainer := doc.Find("[data-global-init=initRepoFileView]") diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index d12addb1275db..cd6b0df122206 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -257,10 +257,12 @@ func testViewFileInRepo(t *testing.T) { description := htmlDoc.doc.Find(".repo-description") repoTopics := htmlDoc.doc.Find("#repo-topics") repoSummary := htmlDoc.doc.Find(".repository-summary") + fileSize := htmlDoc.Find("div.file-info-entry > .file-info-size").Text() assert.Equal(t, 0, description.Length()) assert.Equal(t, 0, repoTopics.Length()) assert.Equal(t, 0, repoSummary.Length()) + assert.Equal(t, "30 B", fileSize) } // TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 9f4fa518819a7..c70937147a76d 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1582,6 +1582,7 @@ tbody.commit-list { display: flex; align-items: center; width: max-content; + gap: 0.25em; } .file-info-entry + .file-info-entry {