Skip to content
10 changes: 7 additions & 3 deletions modules/git/repo_commit_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {

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

return repo.getCommitFromBatchReader(rd, id)
return repo.getCommitFromBatchReader(wr, rd, id)
}

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

commit, err := tag.Commit(repo)
if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
return nil, err
}

commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions modules/git/repo_tag_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ func (repo *Repository) GetTagType(id ObjectID) (string, error) {
return "", err
}
_, typ, _, err := ReadBatchLine(rd)
if IsErrNotExist(err) {
return "", ErrNotExist{ID: id.String()}
if err != nil {
if IsErrNotExist(err) {
return "", ErrNotExist{ID: id.String()}
}
return "", err
}
return typ, nil
}
Expand Down
6 changes: 5 additions & 1 deletion modules/git/repo_tree_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
if err != nil {
return nil, err
}
commit, err := tag.Commit(repo)

if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
return nil, err
}
commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
if err != nil {
return nil, err
}
Expand Down
5 changes: 0 additions & 5 deletions modules/git/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ type Tag struct {
Signature *CommitSignature
}

// Commit return the commit of the tag reference
func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
return gitRepo.getCommit(tag.Object)
}

func parsePayloadSignature(data []byte, messageStart int) (payload, msg, sign string) {
pos := messageStart
signStart, signEnd := -1, -1
Expand Down
2 changes: 1 addition & 1 deletion modules/repository/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func PushUpdateAddTag(ctx context.Context, repo *repo_model.Repository, gitRepo
if err != nil {
return fmt.Errorf("unable to GetTag: %w", err)
}
commit, err := tag.Commit(gitRepo)
commit, err := gitRepo.GetTagCommit(tag.Name)
if err != nil {
return fmt.Errorf("unable to get tag Commit: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
ctx.APIError(http.StatusBadRequest, err)
} else {
commit, err := tag.Commit(ctx.Repo.GitRepo)
commit, err := ctx.Repo.GitRepo.GetTagCommit(tag.Name)
if err != nil {
ctx.APIError(http.StatusBadRequest, err)
}
Expand Down
27 changes: 17 additions & 10 deletions routers/web/repo/view_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,26 @@ import (
"github.com/nektos/act/pkg/model"
)

func prepareLatestCommitInfo(ctx *context.Context) bool {
commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
if err != nil {
ctx.ServerError("GetCommitByPath", err)
return false
}

return loadLatestCommitData(ctx, commit)
}

func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
ctx.Data["IsViewFile"] = true
ctx.Data["HideRepoInfo"] = true

if !prepareLatestCommitInfo(ctx) {
return
}

// Don't call any other repository functions until the dataRc closed to
// avoid create unnecessary temporary cat file.
blob := entry.Blob()
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob)
if err != nil {
Expand All @@ -46,16 +63,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
ctx.Data["FileName"] = blob.Name()
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)

commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
if err != nil {
ctx.ServerError("GetCommitByPath", err)
return
}

if !loadLatestCommitData(ctx, commit) {
return
}

if ctx.Repo.TreePath == ".editorconfig" {
_, editorconfigWarning, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
if editorconfigWarning != nil {
Expand Down
2 changes: 1 addition & 1 deletion services/repository/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
if err != nil {
return fmt.Errorf("GetTag: %w", err)
}
commit, err := tag.Commit(gitRepo)
commit, err := gitRepo.GetTagCommit(tag.Name)
if err != nil {
return fmt.Errorf("Commit: %w", err)
}
Expand Down