Skip to content

Only migrate mirrors containing commits in migration v276 #27132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions models/migrations/v1_21/v276.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
giturl "code.gitea.io/gitea/modules/git/url"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -63,6 +64,8 @@ func migratePullMirrors(x *xorm.Engine) error {
var mirrors []Mirror
if err := sess.Select("mirror.id, mirror.repo_id, mirror.remote_address, repository.owner_name as repo_owner, repository.name as repo_name").
Join("INNER", "repository", "repository.id = mirror.repo_id").
Where("repository.status = ?", repo_model.RepositoryReady).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repositories with status = RepositoryPendingTransfer could have mirrors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for migrations, it may/may not have the mirrors. So we cannot assume it always have when the status = RepositoryPendingTransfer. We can only assume when status = RepositoryPendingReady, the git data have the remote.

And("repository.is_empty = ?", false).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. If you migrate an empty repository, you still have a pull mirror in the database. This would not update the RemoteAddress then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my above comment, I think they should be updated when the first mirroring.

Limit(limit, start).Find(&mirrors); err != nil {
return err
}
Expand Down Expand Up @@ -126,6 +129,8 @@ func migratePushMirrors(x *xorm.Engine) error {
var mirrors []PushMirror
if err := sess.Select("push_mirror.id, push_mirror.repo_id, push_mirror.remote_name, push_mirror.remote_address, repository.owner_name as repo_owner, repository.name as repo_name").
Join("INNER", "repository", "repository.id = push_mirror.repo_id").
Where("repository.status = ?", repo_model.RepositoryReady).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repositories with status = RepositoryPendingTransfer could have mirrors.

And("repository.is_empty = ?", false).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. An empty repository can contain push mirrors. This would not update the RemoteAddress then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty repository should have no any git data. So this will avoid read git data here failure. Maybe we can update the remote_address when the first mirror successfully?

Limit(limit, start).Find(&mirrors); err != nil {
return err
}
Expand Down