Skip to content

Commit eaf5e6d

Browse files
committed
avoid to create uncessary temporary cat file sub process
1 parent 0fee4f1 commit eaf5e6d

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

modules/git/repo_base_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bu
7676
}
7777

7878
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
79+
panic("lllllll")
7980
tempBatch, err := repo.NewBatch(ctx)
8081
if err != nil {
8182
return nil, nil, nil, err

modules/git/repo_commit_nogogit.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
8181

8282
_, _ = wr.Write([]byte(id.String() + "\n"))
8383

84-
return repo.getCommitFromBatchReader(rd, id)
84+
return repo.getCommitFromBatchReader(wr, rd, id)
8585
}
8686

87-
func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id ObjectID) (*Commit, error) {
87+
func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.Reader, id ObjectID) (*Commit, error) {
8888
_, typ, size, err := ReadBatchLine(rd)
8989
if err != nil {
9090
if errors.Is(err, io.EOF) || IsErrNotExist(err) {
@@ -112,7 +112,11 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id ObjectID)
112112
return nil, err
113113
}
114114

115-
commit, err := tag.Commit(repo)
115+
if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
116+
return nil, err
117+
}
118+
119+
commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
116120
if err != nil {
117121
return nil, err
118122
}

modules/git/repo_tag_nogogit.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ func (repo *Repository) GetTagType(id ObjectID) (string, error) {
4141
return "", err
4242
}
4343
_, typ, _, err := ReadBatchLine(rd)
44-
if IsErrNotExist(err) {
45-
return "", ErrNotExist{ID: id.String()}
44+
if err != nil {
45+
if IsErrNotExist(err) {
46+
return "", ErrNotExist{ID: id.String()}
47+
}
48+
return "", err
4649
}
4750
return typ, nil
4851
}

routers/web/repo/view_file.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,26 @@ import (
3030
"github.com/nektos/act/pkg/model"
3131
)
3232

33+
func prepareLatestCommitInfo(ctx *context.Context) {
34+
commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
35+
if err != nil {
36+
ctx.ServerError("GetCommitByPath", err)
37+
return
38+
}
39+
40+
if !loadLatestCommitData(ctx, commit) {
41+
return
42+
}
43+
}
44+
3345
func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
3446
ctx.Data["IsViewFile"] = true
3547
ctx.Data["HideRepoInfo"] = true
48+
49+
prepareLatestCommitInfo(ctx)
50+
51+
// Don't call any other repository functions until the dataRc closed to
52+
// avoid create unnecessary temporary cat file.
3653
blob := entry.Blob()
3754
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob)
3855
if err != nil {
@@ -46,16 +63,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
4663
ctx.Data["FileName"] = blob.Name()
4764
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
4865

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-
5966
if ctx.Repo.TreePath == ".editorconfig" {
6067
_, editorconfigWarning, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
6168
if editorconfigWarning != nil {

0 commit comments

Comments
 (0)