14
"code.gitea.io/gitea/modules/log"
15
"code.gitea.io/gitea/modules/util"
23
type Repository struct {
28
gpgSettings *GPGSettings
31
batchCancel context.CancelFunc
32
batchReader *bufio.Reader
33
batchWriter WriteCloserError
36
checkCancel context.CancelFunc
37
checkReader *bufio.Reader
38
checkWriter WriteCloserError
41
LastCommitCache *LastCommitCache
43
objectFormat ObjectFormat
47
func openRepositoryWithDefaultContext(repoPath string) (*Repository, error) {
48
return OpenRepository(DefaultContext, repoPath)
52
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
53
repoPath, err := filepath.Abs(repoPath)
56
} else if !isDir(repoPath) {
57
return nil, util.NewNotExistErrorf("no such file or directory")
61
if err := EnsureValidGitRepository(ctx, repoPath); err != nil {
67
tagCache: newObjectCache(),
71
repo.batchWriter, repo.batchReader, repo.batchCancel = CatFileBatch(ctx, repoPath)
72
repo.checkWriter, repo.checkReader, repo.checkCancel = CatFileBatchCheck(ctx, repoPath)
78
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
79
if repo.batchCancel == nil || repo.batchInUse {
80
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
81
return CatFileBatch(ctx, repo.Path)
83
repo.batchInUse = true
84
return repo.batchWriter, repo.batchReader, func() {
85
repo.batchInUse = false
90
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
91
if repo.checkCancel == nil || repo.checkInUse {
92
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
93
return CatFileBatchCheck(ctx, repo.Path)
95
repo.checkInUse = true
96
return repo.checkWriter, repo.checkReader, func() {
97
repo.checkInUse = false
101
func (repo *Repository) Close() error {
105
if repo.batchCancel != nil {
107
repo.batchReader = nil
108
repo.batchWriter = nil
109
repo.batchCancel = nil
110
repo.batchInUse = false
112
if repo.checkCancel != nil {
114
repo.checkCancel = nil
115
repo.checkReader = nil
116
repo.checkWriter = nil
117
repo.checkInUse = false
119
repo.LastCommitCache = nil