mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-06 18:35:23 +02:00
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
This commit is contained in:
parent
fb8166c6c6
commit
719bddcd76
301 changed files with 3193 additions and 2919 deletions
|
@ -8,7 +8,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
|
@ -59,7 +59,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
|
|||
|
||||
handler := func(idx int, bean interface{}, limit int) error {
|
||||
var item SyncRequest
|
||||
if m, ok := bean.(*models.Mirror); ok {
|
||||
if m, ok := bean.(*repo_model.Mirror); ok {
|
||||
if m.Repo == nil {
|
||||
log.Error("Disconnected mirror found: %d", m.ID)
|
||||
return nil
|
||||
|
@ -68,7 +68,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
|
|||
Type: PullMirrorType,
|
||||
RepoID: m.RepoID,
|
||||
}
|
||||
} else if m, ok := bean.(*models.PushMirror); ok {
|
||||
} else if m, ok := bean.(*repo_model.PushMirror); ok {
|
||||
if m.Repo == nil {
|
||||
log.Error("Disconnected push-mirror found: %d", m.ID)
|
||||
return nil
|
||||
|
@ -111,7 +111,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
|
|||
}
|
||||
|
||||
if pullLimit != 0 {
|
||||
if err := models.MirrorsIterate(func(idx int, bean interface{}) error {
|
||||
if err := repo_model.MirrorsIterate(func(idx int, bean interface{}) error {
|
||||
return handler(idx, bean, pullLimit)
|
||||
}); err != nil && err != errLimit {
|
||||
log.Error("MirrorsIterate: %v", err)
|
||||
|
@ -119,7 +119,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
|
|||
}
|
||||
}
|
||||
if pushLimit != 0 {
|
||||
if err := models.PushMirrorsIterate(func(idx int, bean interface{}) error {
|
||||
if err := repo_model.PushMirrorsIterate(func(idx int, bean interface{}) error {
|
||||
return handler(idx, bean, pushLimit)
|
||||
}); err != nil && err != errLimit {
|
||||
log.Error("PushMirrorsIterate: %v", err)
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/models"
|
||||
admin_model "code.gitea.io/gitea/models/admin"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
|
@ -29,7 +30,7 @@ import (
|
|||
const gitShortEmptySha = "0000000"
|
||||
|
||||
// UpdateAddress writes new address to Git repository and database
|
||||
func UpdateAddress(m *models.Mirror, addr string) error {
|
||||
func UpdateAddress(m *repo_model.Mirror, addr string) error {
|
||||
remoteName := m.GetRemoteName()
|
||||
repoPath := m.Repo.RepoPath()
|
||||
// Remove old remote
|
||||
|
@ -144,7 +145,7 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
|
|||
}
|
||||
|
||||
func pruneBrokenReferences(ctx context.Context,
|
||||
m *models.Mirror,
|
||||
m *repo_model.Mirror,
|
||||
repoPath string,
|
||||
timeout time.Duration,
|
||||
stdoutBuilder, stderrBuilder *strings.Builder,
|
||||
|
@ -181,7 +182,7 @@ func pruneBrokenReferences(ctx context.Context,
|
|||
}
|
||||
|
||||
// runSync returns true if sync finished without error.
|
||||
func runSync(ctx context.Context, m *models.Mirror) ([]*mirrorSyncResult, bool) {
|
||||
func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bool) {
|
||||
repoPath := m.Repo.RepoPath()
|
||||
wikiPath := m.Repo.WikiPath()
|
||||
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
|
||||
|
@ -271,7 +272,7 @@ func runSync(ctx context.Context, m *models.Mirror) ([]*mirrorSyncResult, bool)
|
|||
gitRepo.Close()
|
||||
|
||||
log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo)
|
||||
if err := m.Repo.UpdateSize(db.DefaultContext); err != nil {
|
||||
if err := models.UpdateRepoSize(db.DefaultContext, m.Repo); err != nil {
|
||||
log.Error("Failed to update size for mirror repository: %v", err)
|
||||
}
|
||||
|
||||
|
@ -362,7 +363,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||
log.Error("PANIC whilst syncMirrors[%d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2))
|
||||
}()
|
||||
|
||||
m, err := models.GetMirrorByRepoID(repoID)
|
||||
m, err := repo_model.GetMirrorByRepoID(repoID)
|
||||
if err != nil {
|
||||
log.Error("GetMirrorByRepoID [%d]: %v", repoID, err)
|
||||
return false
|
||||
|
@ -379,7 +380,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||
|
||||
log.Trace("SyncMirrors [repo: %-v]: Scheduling next update", m.Repo)
|
||||
m.ScheduleNextUpdate()
|
||||
if err = models.UpdateMirror(m); err != nil {
|
||||
if err = repo_model.UpdateMirror(m); err != nil {
|
||||
log.Error("UpdateMirror [%d]: %v", m.RepoID, err)
|
||||
return false
|
||||
}
|
||||
|
@ -485,7 +486,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool {
|
||||
func checkAndUpdateEmptyRepository(m *repo_model.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool {
|
||||
if !m.Repo.IsEmpty {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"regexp"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
@ -26,7 +26,7 @@ import (
|
|||
var stripExitStatus = regexp.MustCompile(`exit status \d+ - `)
|
||||
|
||||
// AddPushMirrorRemote registers the push mirror remote.
|
||||
func AddPushMirrorRemote(m *models.PushMirror, addr string) error {
|
||||
func AddPushMirrorRemote(m *repo_model.PushMirror, addr string) error {
|
||||
addRemoteAndConfig := func(addr, path string) error {
|
||||
if _, err := git.NewCommand("remote", "add", "--mirror=push", m.RemoteName, addr).RunInDir(path); err != nil {
|
||||
return err
|
||||
|
@ -57,7 +57,7 @@ func AddPushMirrorRemote(m *models.PushMirror, addr string) error {
|
|||
}
|
||||
|
||||
// RemovePushMirrorRemote removes the push mirror remote.
|
||||
func RemovePushMirrorRemote(m *models.PushMirror) error {
|
||||
func RemovePushMirrorRemote(m *repo_model.PushMirror) error {
|
||||
cmd := git.NewCommand("remote", "rm", m.RemoteName)
|
||||
|
||||
if _, err := cmd.RunInDir(m.Repo.RepoPath()); err != nil {
|
||||
|
@ -86,7 +86,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
|
|||
log.Error("PANIC whilst syncPushMirror[%d] Panic: %v\nStacktrace: %s", mirrorID, err, log.Stack(2))
|
||||
}()
|
||||
|
||||
m, err := models.GetPushMirrorByID(mirrorID)
|
||||
m, err := repo_model.GetPushMirrorByID(mirrorID)
|
||||
if err != nil {
|
||||
log.Error("GetPushMirrorByID [%d]: %v", mirrorID, err)
|
||||
return false
|
||||
|
@ -106,7 +106,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
|
|||
|
||||
m.LastUpdateUnix = timeutil.TimeStampNow()
|
||||
|
||||
if err := models.UpdatePushMirror(m); err != nil {
|
||||
if err := repo_model.UpdatePushMirror(m); err != nil {
|
||||
log.Error("UpdatePushMirror [%d]: %v", m.ID, err)
|
||||
|
||||
return false
|
||||
|
@ -117,7 +117,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
|
|||
return err == nil
|
||||
}
|
||||
|
||||
func runPushSync(ctx context.Context, m *models.PushMirror) error {
|
||||
func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
||||
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
|
||||
|
||||
performPush := func(path string) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue