mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-25 10:11:52 +00:00
before: gitrepo vs git packages after: git package fully handle all git operations by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide path details. benefits: 1. remove all unnecessary wrappers, developers no need to struggle with "which package should be used" 2. simplify code, RepositoryFacade can (will) be used everywhere, all "path" details are (will be) hidden
33 lines
931 B
Go
33 lines
931 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/modules/cache"
|
|
"gitea.dev/modules/git"
|
|
)
|
|
|
|
// CacheRef cachhe last commit information of the branch or the tag
|
|
func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error {
|
|
commit, err := gitRepo.GetCommit(ctx, fullRefName.String())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if gitRepo.LastCommitCache == nil {
|
|
commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(fullRefName.ShortName(), true), func() (int64, error) {
|
|
return git.CommitsCountOfCommit(ctx, repo, commit.ID.String())
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache())
|
|
}
|
|
|
|
return commit.CacheCommit(ctx, gitRepo)
|
|
}
|