diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-10 09:27:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 09:27:50 +0800 |
commit | 719bddcd76610a63dadc8555760072957a11cf30 (patch) | |
tree | 0df26092fba7e3e21444fe493e6b349473b6b0cb /modules/repository/repo.go | |
parent | fb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff) | |
download | gitea-719bddcd76610a63dadc8555760072957a11cf30.tar.gz gitea-719bddcd76610a63dadc8555760072957a11cf30.zip |
Move repository model into models/repo (#17933)
* Some refactors related repository model
* Move more methods out of repository
* Move repository into models/repo
* Fix test
* Fix test
* some improvements
* Remove unnecessary function
Diffstat (limited to 'modules/repository/repo.go')
-rw-r--r-- | modules/repository/repo.go | 29 |
1 files changed, 15 insertions, 14 deletions
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 |