summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/graph_test.go1
-rw-r--r--models/migrations/v39.go1
-rw-r--r--models/migrations/v82.go1
-rw-r--r--models/pull.go4
-rw-r--r--models/repo.go1
-rw-r--r--models/repo_activity.go4
-rw-r--r--models/repo_branch.go4
-rw-r--r--models/repo_sign.go5
-rw-r--r--models/repo_tag.go24
-rw-r--r--models/wiki.go2
-rw-r--r--models/wiki_test.go3
11 files changed, 26 insertions, 24 deletions
diff --git a/models/graph_test.go b/models/graph_test.go
index c1f0bc90d9..78bfcb27ec 100644
--- a/models/graph_test.go
+++ b/models/graph_test.go
@@ -17,6 +17,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
if err != nil {
b.Error("Could not open repository")
}
+ defer currentRepo.Close()
for i := 0; i < b.N; i++ {
graph, err := GetCommitGraph(currentRepo, 1)
diff --git a/models/migrations/v39.go b/models/migrations/v39.go
index f3b32ea873..dc5f6ee091 100644
--- a/models/migrations/v39.go
+++ b/models/migrations/v39.go
@@ -47,6 +47,7 @@ func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error {
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Warn("SyncReleasesWithTags: %v", err)
}
+ gitRepo.Close()
}
if len(repos) < pageSize {
break
diff --git a/models/migrations/v82.go b/models/migrations/v82.go
index 3fb4b6c59e..2daa86ab07 100644
--- a/models/migrations/v82.go
+++ b/models/migrations/v82.go
@@ -91,6 +91,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error {
if err != nil {
return err
}
+ defer gitRepo.Close()
gitRepoCache[release.RepoID] = gitRepo
}
diff --git a/models/pull.go b/models/pull.go
index 45a1daac46..b25c52571d 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -380,6 +380,7 @@ func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) {
if err != nil {
return nil, err
}
+ defer headGitRepo.Close()
lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch)
if err != nil {
@@ -569,6 +570,7 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(mergeCommit[:40])
if err != nil {
@@ -870,6 +872,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer headGitRepo.Close()
// Add a temporary remote.
tmpRemote := com.ToStr(time.Now().UnixNano())
@@ -911,6 +914,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer headGitRepo.Close()
tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil {
diff --git a/models/repo.go b/models/repo.go
index ccecfe2fdf..a340a391a1 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1047,6 +1047,7 @@ func MigrateRepositoryGitData(doer, u *User, repo *Repository, opts api.MigrateR
if err != nil {
return repo, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
repo.IsEmpty, err = gitRepo.IsEmpty()
if err != nil {
diff --git a/models/repo_activity.go b/models/repo_activity.go
index aa5c2217e0..d25524c057 100644
--- a/models/repo_activity.go
+++ b/models/repo_activity.go
@@ -64,6 +64,8 @@ func GetActivityStats(repo *Repository, timeFrom time.Time, releases, issues, pr
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
+
code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch)
if err != nil {
return nil, fmt.Errorf("FillFromGit: %v", err)
@@ -79,6 +81,8 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
+
code, err := gitRepo.GetCodeActivityStats(timeFrom, "")
if err != nil {
return nil, fmt.Errorf("FillFromGit: %v", err)
diff --git a/models/repo_branch.go b/models/repo_branch.go
index dee6ef3d7e..c513231836 100644
--- a/models/repo_branch.go
+++ b/models/repo_branch.go
@@ -23,6 +23,7 @@ func (repo *Repository) GetBranch(branch string) (*git.Branch, error) {
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
return gitRepo.GetBranch(branch)
}
@@ -38,6 +39,7 @@ func (repo *Repository) CheckBranchName(name string) error {
if err != nil {
return err
}
+ defer gitRepo.Close()
branches, err := repo.GetBranches()
if err != nil {
@@ -94,6 +96,7 @@ func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName st
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
}
+ defer gitRepo.Close()
if err = gitRepo.CreateBranch(branchName, oldBranchName); err != nil {
log.Error("Unable to create branch: %s from %s. (%v)", branchName, oldBranchName, err)
@@ -140,6 +143,7 @@ func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
}
+ defer gitRepo.Close()
if err = gitRepo.CreateBranch(branchName, commit); err != nil {
log.Error("Unable to create branch: %s from %s. (%v)", branchName, commit, err)
diff --git a/models/repo_sign.go b/models/repo_sign.go
index bac69f76a8..a02b027f89 100644
--- a/models/repo_sign.go
+++ b/models/repo_sign.go
@@ -149,6 +149,7 @@ func (repo *Repository) SignWikiCommit(u *User) (bool, string) {
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit("HEAD")
if err != nil {
return false, ""
@@ -194,6 +195,7 @@ func (repo *Repository) SignCRUDAction(u *User, tmpBasePath, parentCommit string
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(parentCommit)
if err != nil {
return false, ""
@@ -242,6 +244,7 @@ func (repo *Repository) SignMerge(u *User, tmpBasePath, baseCommit, headCommit s
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(baseCommit)
if err != nil {
@@ -257,6 +260,7 @@ func (repo *Repository) SignMerge(u *User, tmpBasePath, baseCommit, headCommit s
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(headCommit)
if err != nil {
@@ -272,6 +276,7 @@ func (repo *Repository) SignMerge(u *User, tmpBasePath, baseCommit, headCommit s
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(headCommit)
if err != nil {
diff --git a/models/repo_tag.go b/models/repo_tag.go
deleted file mode 100644
index 3864b7a12a..0000000000
--- a/models/repo_tag.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package models
-
-import (
- "code.gitea.io/gitea/modules/git"
-)
-
-// GetTagsByPath returns repo tags by its path
-func GetTagsByPath(path string) ([]*git.Tag, error) {
- gitRepo, err := git.OpenRepository(path)
- if err != nil {
- return nil, err
- }
-
- return gitRepo.GetTagInfos()
-}
-
-// GetTags return repo's tags
-func (repo *Repository) GetTags() ([]*git.Tag, error) {
- return GetTagsByPath(repo.RepoPath())
-}
diff --git a/models/wiki.go b/models/wiki.go
index 858fe1d6d0..8b63716afa 100644
--- a/models/wiki.go
+++ b/models/wiki.go
@@ -140,6 +140,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldWikiName, newWikiName, con
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
}
+ defer gitRepo.Close()
if hasMasterBranch {
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
@@ -283,6 +284,7 @@ func (repo *Repository) DeleteWikiPage(doer *User, wikiName string) (err error)
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
}
+ defer gitRepo.Close()
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
diff --git a/models/wiki_test.go b/models/wiki_test.go
index 991a3d95b9..37c0a86635 100644
--- a/models/wiki_test.go
+++ b/models/wiki_test.go
@@ -161,6 +161,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
// Now need to show that the page has been added:
gitRepo, err := git.OpenRepository(repo.WikiPath())
assert.NoError(t, err)
+ defer gitRepo.Close()
masterTree, err := gitRepo.GetTree("master")
assert.NoError(t, err)
wikiPath := WikiNameToFilename(wikiName)
@@ -214,6 +215,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
_, err := masterTree.GetTreeEntryByPath("Home.md")
assert.Error(t, err)
}
+ gitRepo.Close()
}
}
@@ -226,6 +228,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
// Now need to show that the page has been added:
gitRepo, err := git.OpenRepository(repo.WikiPath())
assert.NoError(t, err)
+ defer gitRepo.Close()
masterTree, err := gitRepo.GetTree("master")
assert.NoError(t, err)
wikiPath := WikiNameToFilename("Home")