In investigating #7947 it has become clear that the storage component of go-git repositories needs closing.
This PR adds this Close function and adds the Close functions as necessary.
In TransferOwnership the ctx.Repo.GitRepo is closed if it is open to help prevent the risk of multiple open files.
Fixes #7947
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Warn(" SyncReleasesWithTags: %v", err)
+ gitRepo.Close()
continue
}
count, err = getReleaseCount(repo.ID)
if err != nil {
log.Warn(" GetReleaseCountByRepoID: %v", err)
+ gitRepo.Close()
continue
}
log.Trace(" repo %s releases synchronized to tags: from %d to %d",
repo.FullName(), oldnum, count)
+ gitRepo.Close()
}
}
CreateComment(issueNumber int64, comment *Comment) error
CreatePullRequest(pr *PullRequest) error
Rollback() error
+ Close()
}
-```
\ No newline at end of file
+```
gitRepo, err := git.OpenRepository(repo.RepoPath())
assert.NoError(t, err)
+ defer gitRepo.Close()
err = gitRepo.CreateTag("v0.0.1", "master")
assert.NoError(t, err)
gitRepo, err := git.OpenRepository(repo.RepoPath())
assert.NoError(t, err)
+ defer gitRepo.Close()
err = gitRepo.CreateTag("v0.0.1", "master")
assert.NoError(t, err)
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
+ gitRepo.Close()
}
// Test creating a file in a new branch
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
+ gitRepo.Close()
}
// Test updating a file in a new branch
repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
// Get the commit ID of the default branch
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
+ defer gitRepo.Close()
+
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
// Make a new tag in repo1
newTag := "test_tag"
repo1.CreateNewBranch(user2, repo1.DefaultBranch, newBranch)
// Get the commit ID of the default branch
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
+ defer gitRepo.Close()
+
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
// Make a new tag in repo1
newTag := "test_tag"
git.NewCommand("config", "user.email", user.Email).RunInDir(repo.RepoPath())
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
+
commit, _ := gitRepo.GetBranchCommit("master")
lTagName := "lightweightTag"
gitRepo.CreateTag(lTagName, commit.ID.String())
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
repo := ctx.Repo.Repository
doer := ctx.User
opts := getDeleteRepoFileOptions(repo)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
opts := getDeleteRepoFileOptions(repo)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
opts := getCreateRepoFileOptions(repo)
// asserts
assert.Nil(t, err)
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
+
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID)
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
opts := getUpdateRepoFileOptions(repo)
// asserts
assert.Nil(t, err)
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
+
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
opts := getUpdateRepoFileOptions(repo)
// asserts
assert.Nil(t, err)
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
+
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.TreePath)
// assert that the old file no longer exists in the last commit of the branch
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
opts := getUpdateRepoFileOptions(repo)
// asserts
assert.Nil(t, err)
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
+
commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commitID, opts.TreePath)
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
doer := ctx.User
if err != nil {
b.Error("Could not open repository")
}
+ defer currentRepo.Close()
for i := 0; i < b.N; i++ {
graph, err := GetCommitGraph(currentRepo, 1)
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Warn("SyncReleasesWithTags: %v", err)
}
+ gitRepo.Close()
}
if len(repos) < pageSize {
break
if err != nil {
return err
}
+ defer gitRepo.Close()
gitRepoCache[release.RepoID] = gitRepo
}
if err != nil {
return nil, err
}
+ defer headGitRepo.Close()
lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch)
if err != nil {
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(mergeCommit[:40])
if err != nil {
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer headGitRepo.Close()
// Add a temporary remote.
tmpRemote := com.ToStr(time.Now().UnixNano())
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 {
if err != nil {
return repo, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
repo.IsEmpty, err = gitRepo.IsEmpty()
if err != nil {
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)
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)
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
return gitRepo.GetBranch(branch)
}
if err != nil {
return err
}
+ defer gitRepo.Close()
branches, err := repo.GetBranches()
if err != nil {
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)
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)
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit("HEAD")
if err != nil {
return false, ""
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(parentCommit)
if err != nil {
return false, ""
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(baseCommit)
if err != nil {
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(headCommit)
if err != nil {
if err != nil {
return false, ""
}
+ defer gitRepo.Close()
}
commit, err := gitRepo.GetCommit(headCommit)
if err != nil {
+++ /dev/null
-// 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())
-}
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 {
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)
// 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)
_, err := masterTree.GetTreeEntryByPath("Home.md")
assert.Error(t, err)
}
+ gitRepo.Close()
}
}
// 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")
return
}
ctx.Repo.GitRepo = gitRepo
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
}
+
+ ctx.Next()
}
}
}
ctx.Repo.GitRepo = gitRepo
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
+
// Stop at this point when the repo is empty.
if ctx.Repo.Repository.IsEmpty {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
+ ctx.Next()
return
}
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
}
+ ctx.Next()
}
}
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
return
}
+ // We opened it, we should close it
+ defer func() {
+ // If it's been set to nil then assume someone else has closed it.
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ }
+ }()
}
// Get default branch.
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
+
+ ctx.Next()
}
}
// CreateBlameReader creates reader for given repository, commit and file
func CreateBlameReader(repoPath, commitID, file string) (*BlameReader, error) {
- _, err := OpenRepository(repoPath)
+ gitRepo, err := OpenRepository(repoPath)
if err != nil {
return nil, err
}
+ gitRepo.Close()
return createBlameReader(repoPath, GitExecutable, "blame", commitID, "--porcelain", "--", file)
}
`
repo, err := OpenRepository("../../.git")
assert.NoError(t, err)
+ defer repo.Close()
+
testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
assert.NoError(t, err)
if err != nil {
b.Fatal(err)
}
+ defer repo.Close()
+
testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
if err != nil {
b.Fatal(err)
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
+
testGetCommitsInfo(t, bareRepo1)
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo")
defer os.RemoveAll(clonedPath)
clonedRepo1, err := OpenRepository(clonedPath)
assert.NoError(t, err)
+ defer clonedRepo1.Close()
+
testGetCommitsInfo(t, clonedRepo1)
}
for _, benchmark := range benchmarks {
var commit *Commit
var entries Entries
+ var repo *Repository
if repoPath, err := cloneRepo(benchmark.url, benchmarkReposDir, benchmark.name); err != nil {
b.Fatal(err)
- } else if repo, err := OpenRepository(repoPath); err != nil {
+ } else if repo, err = OpenRepository(repoPath); err != nil {
b.Fatal(err)
} else if commit, err = repo.GetBranchCommit("master"); err != nil {
+ repo.Close()
b.Fatal(err)
} else if entries, err = commit.Tree.ListEntries(); err != nil {
+ repo.Close()
b.Fatal(err)
}
entries.Sort()
}
}
})
+ repo.Close()
}
}
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
note := Note{}
err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
repoPath := filepath.Join(testReposDir, "repo3_notes")
repo, err := OpenRepository(repoPath)
assert.NoError(t, err)
+ defer repo.Close()
note := Note{}
err = GetNote(repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
"strings"
"time"
+ gitealog "code.gitea.io/gitea/modules/log"
"github.com/unknwon/com"
"gopkg.in/src-d/go-billy.v4/osfs"
gogit "gopkg.in/src-d/go-git.v4"
}, nil
}
+// Close this repository, in particular close the underlying gogitStorage if this is not nil
+func (repo *Repository) Close() {
+ if repo == nil || repo.gogitStorage == nil {
+ return
+ }
+ if err := repo.gogitStorage.Close(); err != nil {
+ gitealog.Error("Error closing storage: %v", err)
+ }
+}
+
// GoGitRepo gets the go-git repo representation
func (repo *Repository) GoGitRepo() *gogit.Repository {
return repo.gogitRepo
repoPath := filepath.Join(testReposDir, "repo1_bare")
r, err := OpenRepository(repoPath)
assert.NoError(t, err)
+ defer r.Close()
testCases := []struct {
OID string
repoPath := filepath.Join(testReposDir, "repo1_bare")
r, err := OpenRepository(repoPath)
assert.NoError(t, err)
+ defer r.Close()
testCase := "0000000000000000000000000000000000000000"
testError := ErrNotExist{testCase, ""}
repoPath := filepath.Join(testReposDir, "repo1_bare")
r, err := OpenRepository(repoPath)
assert.NoError(t, err)
+ defer r.Close()
testCase := ""
testError := fmt.Errorf("Length must be 40: %s", testCase)
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
brs, err := gitRepo.GetBranches()
if err != nil {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
branches, err := bareRepo1.GetBranches()
if err != nil {
b.Fatal(err)
}
+ defer bareRepo1.Close()
for i := 0; i < b.N; i++ {
_, err := bareRepo1.GetBranches()
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
// these test case are specific to the repo1_bare test repo
testCases := []struct {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
assert.NoError(t, err)
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
commit, err := bareRepo1.GetCommit("bad_branch")
assert.Nil(t, commit)
defer os.RemoveAll(clonedPath)
repo, err := OpenRepository(clonedPath)
assert.NoError(t, err)
+ defer repo.Close()
rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
assert.NoError(t, err)
patchb, err := ioutil.ReadAll(rd)
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
refs, err := bareRepo1.GetRefs()
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
assert.NoError(t, err)
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)
+ defer bareRepo1.Close()
tags, err := bareRepo1.GetTagInfos()
assert.NoError(t, err)
bareRepo1, err := OpenRepository(clonedPath)
assert.NoError(t, err)
+ defer bareRepo1.Close()
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
lTagName := "lightweightTag"
bareRepo1, err := OpenRepository(clonedPath)
assert.NoError(t, err)
+ defer bareRepo1.Close()
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
lTagName := "lightweightTag"
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
repo, err := OpenRepository(emptyRepo2Path)
assert.NoError(t, err)
+ defer repo.Close()
isEmpty, err := repo.IsEmpty()
assert.NoError(t, err)
assert.True(t, isEmpty)
func TestFollowLink(t *testing.T) {
r, err := OpenRepository("tests/repos/repo1_bare")
assert.NoError(t, err)
+ defer r.Close()
commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123")
assert.NoError(t, err)
CreateComments(comments ...*Comment) error
CreatePullRequests(prs ...*PullRequest) error
Rollback() error
+ Close()
}
return err
}
+// Close closes this uploader
+func (g *GiteaLocalUploader) Close() {
+ if g.gitRepo != nil {
+ g.gitRepo.Close()
+ }
+}
+
// CreateTopics creates topics
func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
return models.SaveTopics(g.repo.ID, topics...)
if err := uploader.CreateRepo(repo, opts); err != nil {
return err
}
+ defer uploader.Close()
log.Trace("migrating topics")
topics, err := downloader.GetTopics()
shaSum, err := gitRepo.GetRefCommitID(refFullName)
if err != nil {
+ gitRepo.Close()
log.Error("GetRefCommitID[%s]: %v", refFullName, err)
return
}
+ gitRepo.Close()
if err = webhook_module.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
Ref: refName,
}
if err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
if !git.IsErrUnsupportedVersion(err) {
+ gitRepo.Close()
return err
}
}
+ gitRepo.Close()
}
}
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
gitBlob, err := gitRepo.GetBlob(sha)
if err != nil {
return nil, err
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
ctx.SetParams(":id", "1")
ctx.SetParams(":sha", sha)
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
}
if _, err := gitRepo.GetCommit(sha); err != nil {
+ gitRepo.Close()
return fmt.Errorf("GetCommit[%s]: %v", sha, err)
}
+ gitRepo.Close()
if err := models.NewCommitStatus(models.NewCommitStatusOptions{
Repo: repo,
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
// Get the commit object for the ref
commit, err := gitRepo.GetCommit(ref)
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
// Get the commit object for the ref
commit, err := gitRepo.GetCommit(ref)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "README.md"
ref := ctx.Repo.Repository.DefaultBranch
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "" // root dir
ref := ctx.Repo.Repository.DefaultBranch
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "README.md"
ref := ctx.Repo.Repository.DefaultBranch
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
treePath := "README.md"
ref := repo.DefaultBranch
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
treePath := "README.md"
ref := repo.DefaultBranch
test.LoadRepo(t, ctx, 15)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
t.Run("empty repo", func(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
branch := ctx.Repo.Repository.DefaultBranch
treePath := "README.md"
content := "# repo1\n\nDescription for repo1\nthis is a new line"
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
branch := ctx.Repo.Repository.DefaultBranch
treePath := "README.md"
content := "# repo1\n\nDescription for repo1\nthis is a new line"
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
treePath := "README.md"
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
expectedFileResponse := getExpectedFileResponse()
// Close the repository cleaning up all files
func (t *TemporaryUploadRepository) Close() {
+ defer t.gitRepo.Close()
if err := models.RemoveTemporaryPath(t.basePath); err != nil {
log.Error("Failed to remove temporary path %s: %v", t.basePath, err)
}
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
gitTree, err := gitRepo.GetTree(sha)
if err != nil || gitTree == nil {
return nil, models.ErrSHANotFound{
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
sha := ctx.Repo.Repository.DefaultBranch
page := 1
perPage := 10
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
if err = repo.UpdateSize(); err != nil {
log.Error("Failed to update size for repository: %v", err)
func LoadRepoCommit(t *testing.T, ctx *context.Context) {
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
assert.NoError(t, err)
+ defer gitRepo.Close()
branch, err := gitRepo.GetHEADBranch()
assert.NoError(t, err)
ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
}, reqRepoReader(models.UnitTypeCode))
m.Group("/tags", func() {
m.Get("", repo.ListTags)
- }, reqRepoReader(models.UnitTypeCode))
+ }, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
ctx.ServerError("OpenRepository", err)
return
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(ctx.Params(":sha"))
if err != nil {
ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
ctx.ServerError("OpenRepository", err)
return
}
+ defer gitRepo.Close()
page := ctx.QueryInt("page")
if page <= 0 {
return
}
ctx.Repo.GitRepo = gitRepo
+ defer gitRepo.Close()
repo.Download(ctx.Context)
}
if err != nil {
return nil, "OpenRepository", err
}
+ defer gitRepo.Close()
+
if len(filter) > 0 {
filter = "refs/" + filter
}
if ctx.Written() {
return
}
+ defer headGitRepo.Close()
// Check if another PR exists with the same targets
existingPr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch)
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
baseRepo,
permBase)
}
+ headGitRepo.Close()
ctx.NotFound("Can't read pulls or can't read UnitTypeCode")
return nil, nil, nil, nil, "", ""
}
// user should have permission to read headrepo's codes
permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
headRepo,
permHead)
}
+ headGitRepo.Close()
ctx.NotFound("Can't read headRepo UnitTypeCode")
return nil, nil, nil, nil, "", ""
}
// Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) {
+ headGitRepo.Close()
ctx.NotFound()
return nil, nil, nil, nil, "", ""
}
compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
if err != nil {
+ headGitRepo.Close()
ctx.Error(500, "GetCompareInfo", err)
return nil, nil, nil, nil, "", ""
}
// responses:
// "200":
// "$ref": "#/responses/TagList"
- tags, err := ctx.Repo.Repository.GetTags()
+ tags, err := ctx.Repo.GitRepo.GetTagInfos()
if err != nil {
ctx.Error(500, "GetTags", err)
return
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
baseRepo,
permBase)
}
+ headGitRepo.Close()
ctx.NotFound("ParseCompareInfo", nil)
return nil, nil, nil, nil, "", ""
}
// user should have permission to read headrepo's codes
permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
headRepo,
permHead)
}
+ headGitRepo.Close()
ctx.NotFound("ParseCompareInfo", nil)
return nil, nil, nil, nil, "", ""
}
ctx.Data["HeadBranch"] = headBranch
headIsCommit = true
} else {
+ headGitRepo.Close()
ctx.NotFound("IsRefExist", nil)
return nil, nil, nil, nil, "", ""
}
baseRepo,
permBase)
}
+ headGitRepo.Close()
ctx.NotFound("ParseCompareInfo", nil)
return nil, nil, nil, nil, "", ""
}
compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetCompareInfo", err)
return nil, nil, nil, nil, "", ""
}
if err != nil {
return err
}
+ defer baseGitRepo.Close()
+
ctx.Data["BaseRepoBranches"], err = baseGitRepo.GetBranches()
if err != nil {
return err
if ctx.Written() {
return
}
+ defer headGitRepo.Close()
+
if err := parseBaseRepoInfo(ctx, headRepo); err != nil {
ctx.ServerError("parseBaseRepoInfo", err)
return
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
expectedBranchName := "user2-patch-1"
branchName := GetUniquePatchBranchName(ctx)
assert.Equal(t, expectedBranchName, branchName)
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
expectedTreePath := ""
ctx.ServerError("OpenRepository", err)
return nil
}
+ defer headGitRepo.Close()
headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
ctx.ServerError("OpenRepository", err)
return
}
+ defer headGitRepo.Close()
headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
if err != nil {
if ctx.Written() {
return
}
+ defer headGitRepo.Close()
labelIDs, assigneeIDs, milestoneID := ValidateRepoMetas(ctx, form, true)
if ctx.Written() {
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
return
}
+ defer gitRepo.Close()
gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
if err != nil {
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
return
}
+ defer gitBaseRepo.Close()
defer func() {
ctx.JSON(200, map[string]interface{}{
ctx.ServerError("OpenRepository", err)
return
}
+ defer headGitRepo.Close()
patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch)
if err != nil {
Title: testCase.Form.Title,
Note: testCase.Form.Content,
}, models.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
+ ctx.Repo.GitRepo.Close()
}
}
// Check if repository name has been changed.
if repo.LowerName != strings.ToLower(newRepoName) {
isNameChanged = true
+ // Close the GitRepo if open
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ ctx.Repo.GitRepo = nil
+ }
if err := models.ChangeRepositoryName(ctx.Repo.Owner, repo.Name, newRepoName); err != nil {
ctx.Data["Err_RepoName"] = true
switch {
}
oldOwnerID := ctx.Repo.Owner.ID
+ // Close the GitRepo if open
+ if ctx.Repo.GitRepo != nil {
+ ctx.Repo.GitRepo.Close()
+ ctx.Repo.GitRepo = nil
+ }
if err = models.TransferOwnership(ctx.User, newOwner, repo); err != nil {
if models.IsErrRepoAlreadyExist(err) {
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil)
// Get page list.
entries, err := commit.ListEntries()
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("ListEntries", err)
return nil, nil
}
if models.IsErrWikiInvalidFileName(err) {
continue
}
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("WikiFilenameToName", err)
return nil, nil
} else if wikiName == "_Sidebar" || wikiName == "_Footer" {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
}
if entry == nil || ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar")
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer")
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
if !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommit", err)
}
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
}
if entry == nil || ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return nil, nil
}
// get Commit Count
commitsHistory, err := wikiRepo.CommitsByFileAndRangeNoFollow("master", pageFilename, page)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
ctx.ServerError("CommitsByFileAndRangeNoFollow", err)
return nil, nil
}
}
func renderEditPage(ctx *context.Context) {
- _, commit, err := findWikiRepoCommit(ctx)
+ wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
if !git.IsErrNotExist(err) {
ctx.ServerError("GetBranchCommit", err)
}
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
// get requested pagename
pageName := models.NormalizeWikiName(ctx.Params(":page"))
wikiRepo, entry := renderViewPage(ctx)
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
wikiRepo, entry := renderRevisionPage(ctx)
if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
return
}
entries, err := commit.ListEntries()
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("ListEntries", err)
return
}
}
c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("GetCommit", err)
return
}
if models.IsErrWikiInvalidFileName(err) {
continue
}
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+
ctx.ServerError("WikiFilenameToName", err)
return
}
}
ctx.Data["Pages"] = pages
+ defer func() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ }()
ctx.HTML(200, tplWikiPages)
}
func wikiEntry(t *testing.T, repo *models.Repository, wikiName string) *git.TreeEntry {
wikiRepo, err := git.OpenRepository(repo.WikiPath())
assert.NoError(t, err)
+ defer wikiRepo.Close()
commit, err := wikiRepo.GetBranchCommit("master")
assert.NoError(t, err)
entries, err := commit.ListEntries()
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
// FIXME validate treePath
// Get latest commit referencing the commented line
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(afterCommitID)
if err != nil {
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer repo.Close()
commit, err := repo.GetCommit(endCommit)
if err != nil {
return nil, false
}
if err = models.SyncReleasesWithTags(m.Repo, gitRepo); err != nil {
+ gitRepo.Close()
log.Error("Failed to synchronize tags to releases for repository: %v", err)
}
+ gitRepo.Close()
if err := m.Repo.UpdateSize(); err != nil {
log.Error("Failed to update size for mirror repository: %v", err)
func SyncMirrors() {
// Start listening on new sync requests.
for repoID := range mirrorQueue.Queue() {
- log.Trace("SyncMirrors [repo_id: %v]", repoID)
- mirrorQueue.Remove(repoID)
+ syncMirror(repoID)
+ }
+}
+
+func syncMirror(repoID string) {
+ log.Trace("SyncMirrors [repo_id: %v]", repoID)
+ mirrorQueue.Remove(repoID)
+
+ m, err := models.GetMirrorByRepoID(com.StrTo(repoID).MustInt64())
+ if err != nil {
+ log.Error("GetMirrorByRepoID [%s]: %v", repoID, err)
+ return
+
+ }
+
+ results, ok := runSync(m)
+ if !ok {
+ return
+ }
+
+ m.ScheduleNextUpdate()
+ if err = models.UpdateMirror(m); err != nil {
+ log.Error("UpdateMirror [%s]: %v", repoID, err)
+ return
+ }
- m, err := models.GetMirrorByRepoID(com.StrTo(repoID).MustInt64())
+ var gitRepo *git.Repository
+ if len(results) == 0 {
+ log.Trace("SyncMirrors [repo_id: %d]: no commits fetched", m.RepoID)
+ } else {
+ gitRepo, err = git.OpenRepository(m.Repo.RepoPath())
if err != nil {
- log.Error("GetMirrorByRepoID [%s]: %v", repoID, err)
- continue
+ log.Error("OpenRepository [%d]: %v", m.RepoID, err)
+ return
}
+ defer gitRepo.Close()
+ }
- results, ok := runSync(m)
- if !ok {
+ for _, result := range results {
+ // Discard GitHub pull requests, i.e. refs/pull/*
+ if strings.HasPrefix(result.refName, "refs/pull/") {
continue
}
- m.ScheduleNextUpdate()
- if err = models.UpdateMirror(m); err != nil {
- log.Error("UpdateMirror [%s]: %v", repoID, err)
+ // Create reference
+ if result.oldCommitID == gitShortEmptySha {
+ if err = SyncCreateAction(m.Repo, result.refName); err != nil {
+ log.Error("SyncCreateAction [repo_id: %d]: %v", m.RepoID, err)
+ }
continue
}
- var gitRepo *git.Repository
- if len(results) == 0 {
- log.Trace("SyncMirrors [repo_id: %d]: no commits fetched", m.RepoID)
- } else {
- gitRepo, err = git.OpenRepository(m.Repo.RepoPath())
- if err != nil {
- log.Error("OpenRepository [%d]: %v", m.RepoID, err)
- continue
+ // Delete reference
+ if result.newCommitID == gitShortEmptySha {
+ if err = SyncDeleteAction(m.Repo, result.refName); err != nil {
+ log.Error("SyncDeleteAction [repo_id: %d]: %v", m.RepoID, err)
}
+ continue
}
- for _, result := range results {
- // Discard GitHub pull requests, i.e. refs/pull/*
- if strings.HasPrefix(result.refName, "refs/pull/") {
- continue
- }
-
- // Create reference
- if result.oldCommitID == gitShortEmptySha {
- if err = SyncCreateAction(m.Repo, result.refName); err != nil {
- log.Error("SyncCreateAction [repo_id: %d]: %v", m.RepoID, err)
- }
- continue
- }
-
- // Delete reference
- if result.newCommitID == gitShortEmptySha {
- if err = SyncDeleteAction(m.Repo, result.refName); err != nil {
- log.Error("SyncDeleteAction [repo_id: %d]: %v", m.RepoID, err)
- }
- continue
- }
-
- // Push commits
- oldCommitID, err := git.GetFullCommitID(gitRepo.Path, result.oldCommitID)
- if err != nil {
- log.Error("GetFullCommitID [%d]: %v", m.RepoID, err)
- continue
- }
- newCommitID, err := git.GetFullCommitID(gitRepo.Path, result.newCommitID)
- if err != nil {
- log.Error("GetFullCommitID [%d]: %v", m.RepoID, err)
- continue
- }
- commits, err := gitRepo.CommitsBetweenIDs(newCommitID, oldCommitID)
- if err != nil {
- log.Error("CommitsBetweenIDs [repo_id: %d, new_commit_id: %s, old_commit_id: %s]: %v", m.RepoID, newCommitID, oldCommitID, err)
- continue
- }
- if err = SyncPushAction(m.Repo, SyncPushActionOptions{
- RefName: result.refName,
- OldCommitID: oldCommitID,
- NewCommitID: newCommitID,
- Commits: models.ListToPushCommits(commits),
- }); err != nil {
- log.Error("SyncPushAction [repo_id: %d]: %v", m.RepoID, err)
- continue
- }
+ // Push commits
+ oldCommitID, err := git.GetFullCommitID(gitRepo.Path, result.oldCommitID)
+ if err != nil {
+ log.Error("GetFullCommitID [%d]: %v", m.RepoID, err)
+ continue
}
-
- // Get latest commit date and update to current repository updated time
- commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
+ newCommitID, err := git.GetFullCommitID(gitRepo.Path, result.newCommitID)
if err != nil {
- log.Error("GetLatestCommitDate [%d]: %v", m.RepoID, err)
+ log.Error("GetFullCommitID [%d]: %v", m.RepoID, err)
continue
}
-
- if err = models.UpdateRepositoryUpdatedTime(m.RepoID, commitDate); err != nil {
- log.Error("Update repository 'updated_unix' [%d]: %v", m.RepoID, err)
+ commits, err := gitRepo.CommitsBetweenIDs(newCommitID, oldCommitID)
+ if err != nil {
+ log.Error("CommitsBetweenIDs [repo_id: %d, new_commit_id: %s, old_commit_id: %s]: %v", m.RepoID, newCommitID, oldCommitID, err)
continue
}
+ if err = SyncPushAction(m.Repo, SyncPushActionOptions{
+ RefName: result.refName,
+ OldCommitID: oldCommitID,
+ NewCommitID: newCommitID,
+ Commits: models.ListToPushCommits(commits),
+ }); err != nil {
+ log.Error("SyncPushAction [repo_id: %d]: %v", m.RepoID, err)
+ continue
+ }
+ }
+
+ // Get latest commit date and update to current repository updated time
+ commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
+ if err != nil {
+ log.Error("GetLatestCommitDate [%d]: %v", m.RepoID, err)
+ return
+ }
+
+ if err = models.UpdateRepositoryUpdatedTime(m.RepoID, commitDate); err != nil {
+ log.Error("Update repository 'updated_unix' [%d]: %v", m.RepoID, err)
+ return
}
}
gitRepo, err := git.OpenRepository(repoPath)
assert.NoError(t, err)
+ defer gitRepo.Close()
findOptions := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
initCount, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
if err != nil {
return false, errors.Wrap(err, "OpenRepository")
}
+ defer headGitRepo.Close()
if !headGitRepo.IsBranchExist(pr.HeadBranch) {
return false, errors.New("Head branch does not exist, can not merge")
if err != nil {
log.Error("PullRequestList.InvalidateCodeComments: %v", err)
}
+ gitRepo.Close()
}()
return nil
}
gitRepo, err := git.OpenRepository(repoPath)
assert.NoError(t, err)
+ defer gitRepo.Close()
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,