summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-03-11 11:44:58 +0800
committerGitHub <noreply@github.com>2019-03-11 11:44:58 +0800
commit4334fe754e4a338a13073f649707acd26d1f4a12 (patch)
treecea77d699b0af6b9d3c3fab591514a889c869a4c /models
parent2315019fefb07dfe08e4ecefa199fd947c0c79b8 (diff)
downloadgitea-4334fe754e4a338a13073f649707acd26d1f4a12.tar.gz
gitea-4334fe754e4a338a13073f649707acd26d1f4a12.zip
update git vendor to fix wrong release commit id and add migrations (#6224)
* update git vendor to fix wrong release commit id and add migrations * fix count * fix migration release * fix tests
Diffstat (limited to 'models')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v82.go87
-rw-r--r--models/repo_branch.go9
3 files changed, 94 insertions, 4 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 1fde096fbe..2807de78b1 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -217,6 +217,8 @@ var migrations = []Migration{
NewMigration("add is locked to issues", addIsLockedToIssues),
// v81 -> v82
NewMigration("update U2F counter type", changeU2FCounterType),
+ // v82 -> v83
+ NewMigration("hot fix for wrong release sha1 on release table", fixReleaseSha1OnReleaseTable),
}
// Migrate database to current version
diff --git a/models/migrations/v82.go b/models/migrations/v82.go
new file mode 100644
index 0000000000..6c62a8e24a
--- /dev/null
+++ b/models/migrations/v82.go
@@ -0,0 +1,87 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "code.gitea.io/git"
+ "code.gitea.io/gitea/models"
+ "github.com/go-xorm/xorm"
+)
+
+func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error {
+ type Release struct {
+ ID int64
+ RepoID int64
+ Sha1 string
+ TagName string
+ }
+
+ // Update release sha1
+ const batchSize = 100
+ sess := x.NewSession()
+ defer sess.Close()
+
+ var (
+ err error
+ count int
+ gitRepoCache = make(map[int64]*git.Repository)
+ repoCache = make(map[int64]*models.Repository)
+ )
+
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ for start := 0; ; start += batchSize {
+ releases := make([]*Release, 0, batchSize)
+ if err = sess.Limit(batchSize, start).Asc("id").Where("is_tag=?", false).Find(&releases); err != nil {
+ return err
+ }
+ if len(releases) == 0 {
+ break
+ }
+
+ for _, release := range releases {
+ gitRepo, ok := gitRepoCache[release.RepoID]
+ if !ok {
+ repo, ok := repoCache[release.RepoID]
+ if !ok {
+ repo, err = models.GetRepositoryByID(release.RepoID)
+ if err != nil {
+ return err
+ }
+ repoCache[release.RepoID] = repo
+ }
+
+ gitRepo, err = git.OpenRepository(repo.RepoPath())
+ if err != nil {
+ return err
+ }
+ gitRepoCache[release.RepoID] = gitRepo
+ }
+
+ release.Sha1, err = gitRepo.GetTagCommitID(release.TagName)
+ if err != nil {
+ return err
+ }
+
+ if _, err = sess.ID(release.ID).Cols("sha1").Update(release); err != nil {
+ return err
+ }
+
+ count++
+ if count >= 1000 {
+ if err = sess.Commit(); err != nil {
+ return err
+ }
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+ count = 0
+ }
+ }
+ }
+ return sess.Commit()
+}
diff --git a/models/repo_branch.go b/models/repo_branch.go
index 88417cbd36..c4013dfb82 100644
--- a/models/repo_branch.go
+++ b/models/repo_branch.go
@@ -110,10 +110,6 @@ func (repo *Repository) CheckBranchName(name string) error {
return err
}
- if _, err := gitRepo.GetTag(name); err == nil {
- return ErrTagAlreadyExists{name}
- }
-
branches, err := repo.GetBranches()
if err != nil {
return err
@@ -127,6 +123,11 @@ func (repo *Repository) CheckBranchName(name string) error {
return ErrBranchNameConflict{branch.Name}
}
}
+
+ if _, err := gitRepo.GetTag(name); err == nil {
+ return ErrTagAlreadyExists{name}
+ }
+
return nil
}