aboutsummaryrefslogtreecommitdiffstats
path: root/models/branches.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-21 23:41:00 +0800
committerGitHub <noreply@github.com>2021-11-21 23:41:00 +0800
commitd710af6669654f27f02b69d7ef1ba563e7d58a90 (patch)
tree9727f468a570106293dc90beb70035180bbb7e8e /models/branches.go
parent0add627182388ac63fd04b94cdf912fb87fd0326 (diff)
downloadgitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.tar.gz
gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.zip
Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface * Fix bug * Some improvements * Fix bug * Fix test * Use XXXBean instead of XXXExample
Diffstat (limited to 'models/branches.go')
-rw-r--r--models/branches.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/models/branches.go b/models/branches.go
index 50de52a277..fc0da58e38 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -614,12 +614,13 @@ func FindRenamedBranch(repoID int64, from string) (branch *RenamedBranch, exist
// RenameBranch rename a branch
func (repo *Repository) RenameBranch(from, to string, gitAction func(isDefault bool) error) (err error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
// 1. update default branch if needed
isDefault := repo.DefaultBranch == from
if isDefault {
@@ -663,10 +664,10 @@ func (repo *Repository) RenameBranch(from, to string, gitAction func(isDefault b
From: from,
To: to,
}
- _, err = sess.Insert(renamedBranch)
+ err = db.Insert(ctx, renamedBranch)
if err != nil {
return err
}
- return sess.Commit()
+ return committer.Commit()
}