@@ -30,32 +30,31 @@ import (
3030 "github.com/nektos/act/pkg/model"
3131)
3232
33+ func prepareLatestCommitInfo (ctx * context.Context ) bool {
34+ commit , err := ctx .Repo .Commit .GetCommitByPath (ctx .Repo .TreePath )
35+ if err != nil {
36+ ctx .ServerError ("GetCommitByPath" , err )
37+ return false
38+ }
39+
40+ return loadLatestCommitData (ctx , commit )
41+ }
42+
3343func prepareToRenderFile (ctx * context.Context , entry * git.TreeEntry ) {
3444 ctx .Data ["IsViewFile" ] = true
3545 ctx .Data ["HideRepoInfo" ] = true
36- blob := entry .Blob ()
37- buf , dataRc , fInfo , err := getFileReader (ctx , ctx .Repo .Repository .ID , blob )
38- if err != nil {
39- ctx .ServerError ("getFileReader" , err )
46+
47+ if ! prepareLatestCommitInfo (ctx ) {
4048 return
4149 }
42- defer dataRc .Close ()
50+
51+ blob := entry .Blob ()
4352
4453 ctx .Data ["Title" ] = ctx .Tr ("repo.file.title" , ctx .Repo .Repository .Name + "/" + path .Base (ctx .Repo .TreePath ), ctx .Repo .RefFullName .ShortName ())
4554 ctx .Data ["FileIsSymlink" ] = entry .IsLink ()
4655 ctx .Data ["FileName" ] = blob .Name ()
4756 ctx .Data ["RawFileLink" ] = ctx .Repo .RepoLink + "/raw/" + ctx .Repo .RefTypeNameSubURL () + "/" + util .PathEscapeSegments (ctx .Repo .TreePath )
4857
49- commit , err := ctx .Repo .Commit .GetCommitByPath (ctx .Repo .TreePath )
50- if err != nil {
51- ctx .ServerError ("GetCommitByPath" , err )
52- return
53- }
54-
55- if ! loadLatestCommitData (ctx , commit ) {
56- return
57- }
58-
5958 if ctx .Repo .TreePath == ".editorconfig" {
6059 _ , editorconfigWarning , editorconfigErr := ctx .Repo .GetEditorconfig (ctx .Repo .Commit )
6160 if editorconfigWarning != nil {
@@ -90,6 +89,15 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
9089 isDisplayingSource := ctx .FormString ("display" ) == "source"
9190 isDisplayingRendered := ! isDisplayingSource
9291
92+ // Don't call any other repository functions depends on git.Repository until the dataRc closed to
93+ // avoid create unnecessary temporary cat file.
94+ buf , dataRc , fInfo , err := getFileReader (ctx , ctx .Repo .Repository .ID , blob )
95+ if err != nil {
96+ ctx .ServerError ("getFileReader" , err )
97+ return
98+ }
99+ defer dataRc .Close ()
100+
93101 if fInfo .isLFSFile {
94102 ctx .Data ["RawFileLink" ] = ctx .Repo .RepoLink + "/media/" + ctx .Repo .RefTypeNameSubURL () + "/" + util .PathEscapeSegments (ctx .Repo .TreePath )
95103 }
0 commit comments