diff options
author | zeripath <art27@cantab.net> | 2019-01-18 00:01:04 +0000 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2019-01-17 19:01:04 -0500 |
commit | 07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8 (patch) | |
tree | 87ced90635366b09e7e5f2634acfe2cbec2bc9f6 /models | |
parent | 9edc829c1758b436f8f52ebe61479af087940d60 (diff) | |
download | gitea-07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8.tar.gz gitea-07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8.zip |
Refactor repo.isBare to repo.isEmpty #5629 (#5714)
* Refactor repo.isBare to repo.isEmpty #5629
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Remove Sync call
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 8 | ||||
-rw-r--r-- | models/fixtures/repository.yml | 2 | ||||
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v78.go | 42 | ||||
-rw-r--r-- | models/repo.go | 18 |
5 files changed, 58 insertions, 14 deletions
diff --git a/models/action.go b/models/action.go index d917c37746..5dc0eb18e6 100644 --- a/models/action.go +++ b/models/action.go @@ -574,13 +574,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { refName := git.RefEndName(opts.RefFullName) - // Change default branch and bare status only if pushed ref is non-empty branch. - if repo.IsBare && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) { + // Change default branch and empty status only if pushed ref is non-empty branch. + if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) { repo.DefaultBranch = refName - repo.IsBare = false + repo.IsEmpty = false } - // Change repository bare status and update last updated time. + // Change repository empty status and update last updated time. if err = UpdateRepository(repo, false); err != nil { return fmt.Errorf("UpdateRepository: %v", err) } diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index aa96656530..d412e52d8e 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -175,7 +175,7 @@ owner_id: 2 lower_name: repo15 name: repo15 - is_bare: true + is_empty: true - id: 16 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4c6b6d64bc..533ff90738 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -208,6 +208,8 @@ var migrations = []Migration{ NewMigration("add pull request rebase with merge commit", addPullRequestRebaseWithMerge), // v77 -> v78 NewMigration("add theme to users", addUserDefaultTheme), + // v78 -> v79 + NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty), } // Migrate database to current version diff --git a/models/migrations/v78.go b/models/migrations/v78.go new file mode 100644 index 0000000000..d2b637da5e --- /dev/null +++ b/models/migrations/v78.go @@ -0,0 +1,42 @@ +// 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 ( + "fmt" + "strings" + + "code.gitea.io/gitea/models" + + "github.com/go-xorm/xorm" +) + +func renameRepoIsBareToIsEmpty(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + IsBare bool + IsEmpty bool `xorm:"INDEX"` + } + + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + var err error + if models.DbCfg.Type == "mssql" { + _, err = sess.Query("EXEC sp_rename 'repository.is_bare', 'is_empty', 'COLUMN'") + } else { + _, err = sess.Query("ALTER TABLE \"repository\" RENAME COLUMN \"is_bare\" TO \"is_empty\";") + } + if err != nil { + if strings.Contains(err.Error(), "no such column") { + return nil + } + return fmt.Errorf("select repositories: %v", err) + } + + return sess.Commit() +} diff --git a/models/repo.go b/models/repo.go index 86d3e44a1f..d2b163ff65 100644 --- a/models/repo.go +++ b/models/repo.go @@ -187,7 +187,7 @@ type Repository struct { NumReleases int `xorm:"-"` IsPrivate bool `xorm:"INDEX"` - IsBare bool `xorm:"INDEX"` + IsEmpty bool `xorm:"INDEX"` IsMirror bool `xorm:"INDEX"` *Mirror `xorm:"-"` @@ -291,7 +291,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool) FullName: repo.FullName(), Description: repo.Description, Private: repo.IsPrivate, - Empty: repo.IsBare, + Empty: repo.IsEmpty, Size: int(repo.Size / 1024), Fork: repo.IsFork, Parent: parent, @@ -656,7 +656,7 @@ func (repo *Repository) CanUserFork(user *User) (bool, error) { // CanEnablePulls returns true if repository meets the requirements of accepting pulls. func (repo *Repository) CanEnablePulls() bool { - return !repo.IsMirror && !repo.IsBare + return !repo.IsMirror && !repo.IsEmpty } // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled. @@ -954,13 +954,13 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1") if err != nil { if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") { - repo.IsBare = true + repo.IsEmpty = true } else { - return repo, fmt.Errorf("check bare: %v - %s", err, stderr) + return repo, fmt.Errorf("check empty: %v - %s", err, stderr) } } - if !repo.IsBare { + if !repo.IsEmpty { // Try to get HEAD branch and set it as default branch. gitRepo, err := git.OpenRepository(repoPath) if err != nil { @@ -999,7 +999,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err repo, err = CleanUpMigrateInfo(repo) } - if err != nil && !repo.IsBare { + if err != nil && !repo.IsEmpty { UpdateRepoIndexer(repo) } @@ -1214,7 +1214,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C return fmt.Errorf("initRepository: path already exists: %s", repoPath) } - // Init bare new repository. + // Init git bare new repository. if err = git.InitRepository(repoPath, true); err != nil { return fmt.Errorf("InitRepository: %v", err) } else if err = createDelegateHooks(repoPath); err != nil { @@ -1249,7 +1249,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C } if !opts.AutoInit { - repo.IsBare = true + repo.IsEmpty = true } repo.DefaultBranch = "master" |