-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix wrong xorm get usage on migration #27111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -41,6 +41,8 @@ func migratePullMirrors(x *xorm.Engine) error { | |||||||
ID int64 `xorm:"pk autoincr"` | ||||||||
RepoID int64 `xorm:"INDEX"` | ||||||||
RemoteAddress string `xorm:"VARCHAR(2048)"` | ||||||||
RepoOwner string | ||||||||
RepoName string | ||||||||
} | ||||||||
|
||||||||
sess := x.NewSession() | ||||||||
|
@@ -59,7 +61,9 @@ func migratePullMirrors(x *xorm.Engine) error { | |||||||
|
||||||||
for { | ||||||||
var mirrors []Mirror | ||||||||
if err := sess.Limit(limit, start).Find(&mirrors); err != nil { | ||||||||
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"). | ||||||||
Limit(limit, start).Find(&mirrors); err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
|
@@ -69,7 +73,7 @@ func migratePullMirrors(x *xorm.Engine) error { | |||||||
start += len(mirrors) | ||||||||
|
||||||||
for _, m := range mirrors { | ||||||||
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin") | ||||||||
remoteAddress, err := getRemoteAddress(m.RepoOwner, m.RepoName, "origin") | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
@@ -100,6 +104,8 @@ func migratePushMirrors(x *xorm.Engine) error { | |||||||
RepoID int64 `xorm:"INDEX"` | ||||||||
RemoteName string | ||||||||
RemoteAddress string `xorm:"VARCHAR(2048)"` | ||||||||
RepoOwner string | ||||||||
RepoName string | ||||||||
} | ||||||||
|
||||||||
sess := x.NewSession() | ||||||||
|
@@ -118,7 +124,9 @@ func migratePushMirrors(x *xorm.Engine) error { | |||||||
|
||||||||
for { | ||||||||
var mirrors []PushMirror | ||||||||
if err := sess.Limit(limit, start).Find(&mirrors); err != nil { | ||||||||
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"). | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are already at it, can we also use
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since remote_address is not an index column and the second update will not affect anything, I don't think it's necessary for this change. |
||||||||
Limit(limit, start).Find(&mirrors); err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
|
@@ -128,7 +136,7 @@ func migratePushMirrors(x *xorm.Engine) error { | |||||||
start += len(mirrors) | ||||||||
|
||||||||
for _, m := range mirrors { | ||||||||
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName) | ||||||||
remoteAddress, err := getRemoteAddress(m.RepoOwner, m.RepoName, m.RemoteName) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
@@ -153,25 +161,12 @@ func migratePushMirrors(x *xorm.Engine) error { | |||||||
return sess.Commit() | ||||||||
} | ||||||||
|
||||||||
func getRemoteAddress(sess *xorm.Session, repoID int64, remoteName string) (string, error) { | ||||||||
var ownerName string | ||||||||
var repoName string | ||||||||
has, err := sess. | ||||||||
Table("repository"). | ||||||||
Cols("owner_name", "lower_name"). | ||||||||
Where("id=?", repoID). | ||||||||
Get(&ownerName, &repoName) | ||||||||
if err != nil { | ||||||||
return "", err | ||||||||
} else if !has { | ||||||||
return "", fmt.Errorf("repository [%v] not found", repoID) | ||||||||
} | ||||||||
|
||||||||
func getRemoteAddress(ownerName, repoName, remoteName string) (string, error) { | ||||||||
repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git") | ||||||||
|
||||||||
remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName) | ||||||||
if err != nil { | ||||||||
return "", err | ||||||||
return "", fmt.Errorf("get remote %s's address of %s/%s failed: %v", remoteName, ownerName, repoName, err) | ||||||||
} | ||||||||
|
||||||||
u, err := giturl.Parse(remoteURL) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.