summaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/commits_test.go4
-rw-r--r--modules/repository/create.go11
-rw-r--r--modules/repository/generate.go19
-rw-r--r--modules/repository/init.go13
-rw-r--r--modules/repository/push.go4
-rw-r--r--modules/repository/repo.go29
6 files changed, 42 insertions, 38 deletions
diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go
index b6a63dc127..30edf3362e 100644
--- a/modules/repository/commits_test.go
+++ b/modules/repository/commits_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
@@ -49,7 +49,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
}
pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"}
- repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16}).(*repo_model.Repository)
payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16")
assert.NoError(t, err)
assert.Len(t, payloadCommits, 3)
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 850f7488bd..ddc001d600 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -19,7 +20,7 @@ import (
)
// CreateRepository creates a repository for the user/organization.
-func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*repo_model.Repository, error) {
if !doer.IsAdmin && !u.CanCreateRepo() {
return nil, models.ErrReachLimitOfRepo{
Limit: u.MaxRepoCreation,
@@ -37,7 +38,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (
}
}
- repo := &models.Repository{
+ repo := &repo_model.Repository{
OwnerID: u.ID,
Owner: u,
OwnerName: u.Name,
@@ -55,7 +56,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (
TrustModel: opts.TrustModel,
}
- var rollbackRepo *models.Repository
+ var rollbackRepo *repo_model.Repository
if err := db.WithTx(func(ctx context.Context) error {
if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil {
@@ -67,7 +68,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (
return nil
}
- repoPath := models.RepoPath(u.Name, repo.Name)
+ repoPath := repo_model.RepoPath(u.Name, repo.Name)
isExist, err := util.IsExist(repoPath)
if err != nil {
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -106,7 +107,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (
}
}
- if err := repo.CheckDaemonExportOK(ctx); err != nil {
+ if err := models.CheckDaemonExportOK(ctx, repo); err != nil {
return fmt.Errorf("checkDaemonExportOK: %v", err)
}
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index 61a8b0d111..756cfe227e 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -45,7 +46,7 @@ var defaultTransformers = []transformer{
{Name: "TITLE", Transform: strings.Title},
}
-func generateExpansion(src string, templateRepo, generateRepo *models.Repository) string {
+func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string {
expansions := []expansion{
{Name: "REPO_NAME", Value: generateRepo.Name, Transformers: defaultTransformers},
{Name: "TEMPLATE_NAME", Value: templateRepo.Name, Transformers: defaultTransformers},
@@ -98,7 +99,7 @@ func checkGiteaTemplate(tmpDir string) (*models.GiteaTemplate, error) {
return gt, nil
}
-func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmpDir string) error {
+func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository, tmpDir string) error {
commitTimeStr := time.Now().Format(time.RFC3339)
authorSig := repo.Owner.NewGitSig()
@@ -186,7 +187,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
}
-func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *models.Repository) (err error) {
+func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name)
if err != nil {
return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
@@ -203,7 +204,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *m
}
// re-fetch repo
- if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
+ if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
return fmt.Errorf("getRepositoryByID: %v", err)
}
@@ -224,12 +225,12 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *m
}
// GenerateGitContent generates git content from a template repository
-func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.Repository) error {
+func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
if err := generateGitContent(ctx, generateRepo, templateRepo, generateRepo); err != nil {
return err
}
- if err := generateRepo.UpdateSize(ctx); err != nil {
+ if err := models.UpdateRepoSize(ctx, generateRepo); err != nil {
return fmt.Errorf("failed to update size for repository: %v", err)
}
@@ -240,8 +241,8 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.
}
// GenerateRepository generates a repository from a template
-func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
- generateRepo := &models.Repository{
+func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *repo_model.Repository, opts models.GenerateRepoOptions) (_ *repo_model.Repository, err error) {
+ generateRepo := &repo_model.Repository{
OwnerID: owner.ID,
Owner: owner,
OwnerName: owner.Name,
@@ -276,7 +277,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
return generateRepo, err
}
- if err = generateRepo.CheckDaemonExportOK(ctx); err != nil {
+ if err = models.CheckDaemonExportOK(ctx, generateRepo); err != nil {
return generateRepo, fmt.Errorf("checkDaemonExportOK: %v", err)
}
diff --git a/modules/repository/init.go b/modules/repository/init.go
index d7f31fabde..cfee1a3215 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -23,7 +24,7 @@ import (
"github.com/unknwon/com"
)
-func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
+func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
commitTimeStr := time.Now().Format(time.RFC3339)
authorSig := repo.Owner.NewGitSig()
@@ -101,7 +102,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep
}
// initRepoCommit temporarily changes with work directory.
-func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) {
+func initRepoCommit(tmpPath string, repo *repo_model.Repository, u *user_model.User, defaultBranch string) (err error) {
commitTimeStr := time.Now().Format(time.RFC3339)
sig := u.NewGitSig()
@@ -137,7 +138,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User,
if sign {
args = append(args, "-S"+keyID)
- if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel {
+ if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
// need to set the committer to the KeyID owner
committerName = signer.Name
committerEmail = signer.Email
@@ -175,7 +176,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User,
func checkInitRepository(owner, name string) (err error) {
// Somehow the directory could exist.
- repoPath := models.RepoPath(owner, name)
+ repoPath := repo_model.RepoPath(owner, name)
isExist, err := util.IsExist(repoPath)
if err != nil {
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -198,7 +199,7 @@ func checkInitRepository(owner, name string) (err error) {
}
// InitRepository initializes README and .gitignore if needed.
-func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts models.CreateRepoOptions) (err error) {
if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
return err
}
@@ -227,7 +228,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
// Re-fetch the repository from database before updating it (else it would
// override changes that were done earlier with sql)
- if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
+ if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
return fmt.Errorf("getRepositoryByID: %v", err)
}
diff --git a/modules/repository/push.go b/modules/repository/push.go
index 11272f883d..038735f585 100644
--- a/modules/repository/push.go
+++ b/modules/repository/push.go
@@ -7,7 +7,7 @@ package repository
import (
"strings"
- "code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
)
@@ -104,7 +104,7 @@ func IsForcePush(opts *PushUpdateOptions) (bool, error) {
}
output, err := git.NewCommand("rev-list", "--max-count=1", opts.OldCommitID, "^"+opts.NewCommitID).
- RunInDir(models.RepoPath(opts.RepoUserName, opts.RepoName))
+ RunInDir(repo_model.RepoPath(opts.RepoUserName, opts.RepoName))
if err != nil {
return false, err
} else if len(output) > 0 {
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index c7145658f8..d04cd28a59 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
@@ -48,10 +49,10 @@ func WikiRemoteURL(remote string) string {
// MigrateRepositoryGitData starts migrating git related data after created migrating repository
func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
- repo *models.Repository, opts migration.MigrateOptions,
+ repo *repo_model.Repository, opts migration.MigrateOptions,
httpTransport *http.Transport,
-) (*models.Repository, error) {
- repoPath := models.RepoPath(u.Name, opts.RepoName)
+) (*repo_model.Repository, error) {
+ repoPath := repo_model.RepoPath(u.Name, opts.RepoName)
if u.IsOrganization() {
t, err := models.OrgFromUser(u).GetOwnerTeam()
@@ -79,7 +80,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
if opts.Wiki {
- wikiPath := models.WikiPath(u.Name, opts.RepoName)
+ wikiPath := repo_model.WikiPath(u.Name, opts.RepoName)
wikiRemotePath := WikiRemoteURL(opts.CloneAddr)
if len(wikiRemotePath) > 0 {
if err := util.RemoveAll(wikiPath); err != nil {
@@ -104,7 +105,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
repo.Owner = u
}
- if err = repo.CheckDaemonExportOK(ctx); err != nil {
+ if err = models.CheckDaemonExportOK(ctx, repo); err != nil {
return repo, fmt.Errorf("checkDaemonExportOK: %v", err)
}
@@ -153,12 +154,12 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
}
- if err = repo.UpdateSize(db.DefaultContext); err != nil {
+ if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
log.Error("Failed to update size for repository: %v", err)
}
if opts.Mirror {
- mirrorModel := models.Mirror{
+ mirrorModel := repo_model.Mirror{
RepoID: repo.ID,
Interval: setting.Mirror.DefaultInterval,
EnablePrune: true,
@@ -188,7 +189,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
}
- if err = models.InsertMirror(&mirrorModel); err != nil {
+ if err = repo_model.InsertMirror(&mirrorModel); err != nil {
return repo, fmt.Errorf("InsertOne: %v", err)
}
@@ -216,7 +217,7 @@ func cleanUpMigrateGitConfig(configPath string) error {
}
// CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
-func CleanUpMigrateInfo(repo *models.Repository) (*models.Repository, error) {
+func CleanUpMigrateInfo(repo *repo_model.Repository) (*repo_model.Repository, error) {
repoPath := repo.RepoPath()
if err := createDelegateHooks(repoPath); err != nil {
return repo, fmt.Errorf("createDelegateHooks: %v", err)
@@ -242,7 +243,7 @@ func CleanUpMigrateInfo(repo *models.Repository) (*models.Repository, error) {
}
// SyncReleasesWithTags synchronizes release table with repository tags
-func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) error {
+func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository) error {
existingRelTags := make(map[string]struct{})
opts := models.FindReleasesOptions{
IncludeDrafts: true,
@@ -290,7 +291,7 @@ func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) erro
}
// PushUpdateAddTag must be called for any push actions to add tag
-func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName string) error {
+func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagName string) error {
tag, err := gitRepo.GetTag(tagName)
if err != nil {
return fmt.Errorf("GetTag: %v", err)
@@ -341,7 +342,7 @@ func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName
}
// StoreMissingLfsObjectsInRepository downloads missing LFS objects
-func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Repository, gitRepo *git.Repository, lfsClient lfs.Client) error {
+func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, lfsClient lfs.Client) error {
contentStore := lfs.NewContentStore()
pointerChan := make(chan lfs.PointerBlob)
@@ -364,7 +365,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Reposi
if err := contentStore.Put(p, content); err != nil {
log.Error("Error storing content for LFS meta object %v: %v", p, err)
- if _, err2 := repo.RemoveLFSMetaObjectByOid(p.Oid); err2 != nil {
+ if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil {
log.Error("Error removing LFS meta object %v: %v", p, err2)
}
return err
@@ -383,7 +384,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Reposi
var batch []lfs.Pointer
for pointerBlob := range pointerChan {
- meta, err := repo.GetLFSMetaObjectByOid(pointerBlob.Oid)
+ meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid)
if err != nil && err != models.ErrLFSObjectNotExist {
log.Error("Error querying LFS meta object %v: %v", pointerBlob.Pointer, err)
return err