History

Move some code into models/git (#19879)

* Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh

Lunny Xiao committed 4 years ago

Commit 110fc571 parent a9dc9b067 files · +549 −495Browse files

Unified · Split

67 files
  1. cmd/migrate_storage.go +2 −2
  2. cmd/serv.go +2 −2
  3. integrations/api_repo_lfs_test.go +11 −11
  4. integrations/lfs_getobject_test.go +3 −3
  5. integrations/repo_tag_test.go +5 −4
  6. models/branch.go +80 −0
  7. models/commit.go +0 −26
  8. models/error.go +0 −78
  9. models/git/branches.go +7 −73
  10. models/git/branches_test.go +26 −24
  11. models/git/commit_status.go +17 −2
  12. models/git/commit_status_test.go +3 −2
  13. models/git/lfs.go +73 −2
  14. models/git/lfs_lock.go +1 −1
  15. models/git/main_test.go +18 −0
  16. models/git/protected_tag.go +1 −1
  17. models/git/protected_tag_test.go +17 −16
  18. models/issue_comment.go +7 −6
  19. models/org_team.go +2 −1
  20. models/pull.go +5 −4
  21. models/repo.go +9 −11
  22. models/repo/collaboration.go +21 −0
  23. models/repo_collaboration.go +0 −22
  24. models/review.go +2 −1
  25. models/user.go +2 −1
  26. modules/context/repo.go +3 −2
  27. modules/convert/convert.go +5 −4
  28. modules/convert/status.go +4 −4
  29. modules/gitgraph/graph_models.go +5 −5
  30. modules/lfs/content_store.go +1 −1
  31. modules/repository/create.go +2 −1
  32. modules/repository/generate.go +2 −1
  33. modules/repository/repo.go +6 −5
  34. modules/setting/repository.go +3 −0
  35. routers/api/v1/repo/branch.go +15 −14
  36. routers/api/v1/repo/file.go +3 −2
  37. routers/api/v1/repo/status.go +4 −4
  38. routers/private/hook_pre_receive.go +5 −4
  39. routers/web/repo/branch.go +6 −5
  40. routers/web/repo/commit.go +8 −7
  41. routers/web/repo/compare.go +2 −1
  42. routers/web/repo/download.go +2 −2
  43. routers/web/repo/editor.go +5 −4
  44. routers/web/repo/issue.go +7 −6
  45. routers/web/repo/lfs.go +18 −18
  46. routers/web/repo/pull.go +8 −7
  47. routers/web/repo/setting_protected_branch.go +9 −9
  48. routers/web/repo/tag.go +8 −8
  49. routers/web/repo/view.go +13 −12
  50. routers/web/repo/wiki.go +2 −1
  51. services/asymkey/sign.go +3 −2
  52. services/cron/tasks_basic.go +2 −1
  53. services/gitdiff/gitdiff.go +2 −1
  54. services/lfs/locks.go +14 −14
  55. services/lfs/server.go +10 −10
  56. services/pull/commit_status.go +7 −6
  57. services/pull/lfs.go +5 −4
  58. services/pull/merge.go +7 −6
  59. services/pull/pull.go +8 −7
  60. services/release/release.go +3 −2
  61. services/repository/branch.go +4 −3
  62. services/repository/files/commit.go +3 −3
  63. services/repository/files/patch.go +2 −1
  64. services/repository/files/update.go +8 −7
  65. services/repository/files/upload.go +7 −6
  66. services/repository/fork.go +2 −1
  67. services/repository/push.go +2 −1
cmd/migrate_storage.go+2−2
@@ -9,8 +9,8 @@ import ( · 8 unmodified lines
99 "fmt"
1010 "strings"
1111
12− "code.gitea.io/gitea/models"
1312 "code.gitea.io/gitea/models/db"
13+ git_model "code.gitea.io/gitea/models/git"
1414 "code.gitea.io/gitea/models/migrations"
1515 repo_model "code.gitea.io/gitea/models/repo"
1616 user_model "code.gitea.io/gitea/models/user"
@@ -88,7 +88,7 @@ func migrateAttachments(dstStorage storage.ObjectStorage) error { · 71 unmodified lines
8888 }
8989
9090 func migrateLFS(dstStorage storage.ObjectStorage) error {
91− return models.IterateLFS(func(mo *models.LFSMetaObject) error {
91+ return git_model.IterateLFS(func(mo *git_model.LFSMetaObject) error {
9292 _, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath())
9393 return err
9494 })
cmd/serv.go+2−2
@@ -17,8 +17,8 @@ import ( · 16 unmodified lines
1717 "strings"
1818 "time"
1919
20− "code.gitea.io/gitea/models"
2120 asymkey_model "code.gitea.io/gitea/models/asymkey"
21+ git_model "code.gitea.io/gitea/models/git"
2222 "code.gitea.io/gitea/models/perm"
2323 "code.gitea.io/gitea/modules/git"
2424 "code.gitea.io/gitea/modules/json"
@@ -276,7 +276,7 @@ func runServ(c *cli.Context) error { · 251 unmodified lines
276276 return fail("Internal error", "Failed to sign JWT token: %v", err)
277277 }
278278
279− tokenAuthentication := &models.LFSTokenResponse{
279+ tokenAuthentication := &git_model.LFSTokenResponse{
280280 Header: make(map[string]string),
281281 Href: url,
282282 }
integrations/api_repo_lfs_test.go+11−11
@@ -12,7 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313 "testing"
1414
15− "code.gitea.io/gitea/models"
15+ git_model "code.gitea.io/gitea/models/git"
1616 repo_model "code.gitea.io/gitea/models/repo"
1717 "code.gitea.io/gitea/models/unittest"
1818 user_model "code.gitea.io/gitea/models/user"
@@ -76,7 +76,7 @@ func TestAPILFSBatch(t *testing.T) { · 57 unmodified lines
7676
7777 content := []byte("dummy1")
7878 oid := storeObjectInRepo(t, repo.ID, &content)
79− defer models.RemoveLFSMetaObjectByOid(repo.ID, oid)
79+ defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid)
8080
8181 session := loginUser(t, "user2")
8282
@@ -260,9 +260,9 @@ func TestAPILFSBatch(t *testing.T) { · 177 unmodified lines
260260 content := []byte("dummy0")
261261 storeObjectInRepo(t, repo2.ID, &content)
262262
263− meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid)
263+ meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid)
264264 assert.Nil(t, meta)
265− assert.Equal(t, models.ErrLFSObjectNotExist, err)
265+ assert.Equal(t, git_model.ErrLFSObjectNotExist, err)
266266
267267 req := newRequest(t, &lfs.BatchRequest{
268268 Operation: "upload",
@@ -275,7 +275,7 @@ func TestAPILFSBatch(t *testing.T) { · 6 unmodified lines
275275 assert.Nil(t, br.Objects[0].Error)
276276 assert.Empty(t, br.Objects[0].Actions)
277277
278− meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid)
278+ meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid)
279279 assert.NoError(t, err)
280280 assert.NotNil(t, meta)
281281
@@ -336,7 +336,7 @@ func TestAPILFSUpload(t *testing.T) { · 54 unmodified lines
336336
337337 content := []byte("dummy3")
338338 oid := storeObjectInRepo(t, repo.ID, &content)
339− defer models.RemoveLFSMetaObjectByOid(repo.ID, oid)
339+ defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid)
340340
341341 session := loginUser(t, "user2")
342342
@@ -365,9 +365,9 @@ func TestAPILFSUpload(t *testing.T) { · 22 unmodified lines
365365 err = contentStore.Put(p, bytes.NewReader([]byte("dummy5")))
366366 assert.NoError(t, err)
367367
368− meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid)
368+ meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid)
369369 assert.Nil(t, meta)
370− assert.Equal(t, models.ErrLFSObjectNotExist, err)
370+ assert.Equal(t, git_model.ErrLFSObjectNotExist, err)
371371
372372 t.Run("InvalidAccess", func(t *testing.T) {
373373 req := newRequest(t, p, "invalid")
@@ -378,7 +378,7 @@ func TestAPILFSUpload(t *testing.T) { · 4 unmodified lines
378378 req := newRequest(t, p, "dummy5")
379379
380380 session.MakeRequest(t, req, http.StatusOK)
381− meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid)
381+ meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid)
382382 assert.NoError(t, err)
383383 assert.NotNil(t, meta)
384384 })
@@ -426,7 +426,7 @@ func TestAPILFSUpload(t *testing.T) { · 41 unmodified lines
426426 assert.NoError(t, err)
427427 assert.True(t, exist)
428428
429− meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid)
429+ meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid)
430430 assert.NoError(t, err)
431431 assert.NotNil(t, meta)
432432 })
@@ -441,7 +441,7 @@ func TestAPILFSVerify(t *testing.T) { · 8 unmodified lines
441441
442442 content := []byte("dummy3")
443443 oid := storeObjectInRepo(t, repo.ID, &content)
444− defer models.RemoveLFSMetaObjectByOid(repo.ID, oid)
444+ defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid)
445445
446446 session := loginUser(t, "user2")
447447
integrations/lfs_getobject_test.go+3−3
@@ -12,7 +12,7 @@ import ( · 11 unmodified lines
1212 "net/http/httptest"
1313 "testing"
1414
15− "code.gitea.io/gitea/models"
15+ git_model "code.gitea.io/gitea/models/git"
1616 repo_model "code.gitea.io/gitea/models/repo"
1717 "code.gitea.io/gitea/modules/git"
1818 "code.gitea.io/gitea/modules/json"
@@ -28,7 +28,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string · 9 unmodified lines
2828 pointer, err := lfs.GeneratePointer(bytes.NewReader(*content))
2929 assert.NoError(t, err)
3030
31− _, err = models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID})
31+ _, err = git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID})
3232 assert.NoError(t, err)
3333 contentStore := lfs.NewContentStore()
3434 exist, err := contentStore.Exists(pointer)
@@ -44,7 +44,7 @@ func storeAndGetLfs(t *testing.T, content *[]byte, extraHeader *http.Header, exp · 9 unmodified lines
4444 repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "repo1")
4545 assert.NoError(t, err)
4646 oid := storeObjectInRepo(t, repo.ID, content)
47− defer models.RemoveLFSMetaObjectByOid(repo.ID, oid)
47+ defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid)
4848
4949 session := loginUser(t, "user2")
5050
integrations/repo_tag_test.go+5−4
@@ -10,6 +10,7 @@ import ( · 9 unmodified lines
1010 "testing"
1111
1212 "code.gitea.io/gitea/models"
13+ git_model "code.gitea.io/gitea/models/git"
1314 repo_model "code.gitea.io/gitea/models/repo"
1415 "code.gitea.io/gitea/models/unittest"
1516 user_model "code.gitea.io/gitea/models/user"
@@ -32,12 +33,12 @@ func TestCreateNewTagProtected(t *testing.T) { · 16 unmodified lines
3233 err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "v-1", "first tag")
3334 assert.NoError(t, err)
3435
35− err = models.InsertProtectedTag(&models.ProtectedTag{
36+ err = git_model.InsertProtectedTag(&git_model.ProtectedTag{
3637 RepoID: repo.ID,
3738 NamePattern: "v-*",
3839 })
3940 assert.NoError(t, err)
40− err = models.InsertProtectedTag(&models.ProtectedTag{
41+ err = git_model.InsertProtectedTag(&git_model.ProtectedTag{
4142 RepoID: repo.ID,
4243 NamePattern: "v-1.1",
4344 AllowlistUserIDs: []int64{repo.OwnerID},
@@ -87,11 +88,11 @@ func TestCreateNewTagProtected(t *testing.T) { · 43 unmodified lines
8788 assert.NoError(t, err)
8889 }
8990
90− protectedTags, err := models.GetProtectedTags(repo.ID)
91+ protectedTags, err := git_model.GetProtectedTags(repo.ID)
9192 assert.NoError(t, err)
9293
9394 for _, protectedTag := range protectedTags {
94− err = models.DeleteProtectedTag(protectedTag)
95+ err = git_model.DeleteProtectedTag(protectedTag)
9596 assert.NoError(t, err)
9697 }
9798 }
models/branch.go+80−0
@@ -0,0 +1,80 @@
1+// Copyright 2022 The Gitea Authors. All rights reserved.
2+// Use of this source code is governed by a MIT-style
3+// license that can be found in the LICENSE file.
4+
5+package models
6+
7+import (
8+ "context"
9+
10+ "code.gitea.io/gitea/models/db"
11+ git_model "code.gitea.io/gitea/models/git"
12+ "code.gitea.io/gitea/modules/log"
13+)
14+
15+// HasEnoughApprovals returns true if pr has enough granted approvals.
16+func HasEnoughApprovals(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool {
17+ if protectBranch.RequiredApprovals == 0 {
18+ return true
19+ }
20+ return GetGrantedApprovalsCount(ctx, protectBranch, pr) >= protectBranch.RequiredApprovals
21+}
22+
23+// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
24+func GetGrantedApprovalsCount(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) int64 {
25+ sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
26+ And("type = ?", ReviewTypeApprove).
27+ And("official = ?", true).
28+ And("dismissed = ?", false)
29+ if protectBranch.DismissStaleApprovals {
30+ sess = sess.And("stale = ?", false)
31+ }
32+ approvals, err := sess.Count(new(Review))
33+ if err != nil {
34+ log.Error("GetGrantedApprovalsCount: %v", err)
35+ return 0
36+ }
37+
38+ return approvals
39+}
40+
41+// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews
42+func MergeBlockedByRejectedReview(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool {
43+ if !protectBranch.BlockOnRejectedReviews {
44+ return false
45+ }
46+ rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
47+ And("type = ?", ReviewTypeReject).
48+ And("official = ?", true).
49+ And("dismissed = ?", false).
50+ Exist(new(Review))
51+ if err != nil {
52+ log.Error("MergeBlockedByRejectedReview: %v", err)
53+ return true
54+ }
55+
56+ return rejectExist
57+}
58+
59+// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer
60+// of from official review
61+func MergeBlockedByOfficialReviewRequests(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool {
62+ if !protectBranch.BlockOnOfficialReviewRequests {
63+ return false
64+ }
65+ has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
66+ And("type = ?", ReviewTypeRequest).
67+ And("official = ?", true).
68+ Exist(new(Review))
69+ if err != nil {
70+ log.Error("MergeBlockedByOfficialReviewRequests: %v", err)
71+ return true
72+ }
73+
74+ return has
75+}
76+
77+// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
78+func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool {
79+ return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
80+}
models/commit.go+0−26
@@ -1,26 +0,0 @@
1−// Copyright 2021 Gitea. All rights reserved.
2−// Use of this source code is governed by a MIT-style
3−// license that can be found in the LICENSE file.
4−
5−package models
6−
7−import (
8− asymkey_model "code.gitea.io/gitea/models/asymkey"
9− repo_model "code.gitea.io/gitea/models/repo"
10− user_model "code.gitea.io/gitea/models/user"
11− "code.gitea.io/gitea/modules/git"
12−)
13−
14−// ConvertFromGitCommit converts git commits into SignCommitWithStatuses
15−func ConvertFromGitCommit(commits []*git.Commit, repo *repo_model.Repository) []*SignCommitWithStatuses {
16− return ParseCommitsWithStatus(
17− asymkey_model.ParseCommitsWithSignature(
18− user_model.ValidateCommitsWithEmails(commits),
19− repo.GetTrustModel(),
20− func(user *user_model.User) (bool, error) {
21− return IsOwnerMemberCollaborator(repo, user.ID)
22− },
23− ),
24− repo,
25− )
26−}
models/error.go+0−78
@@ -8,7 +8,6 @@ package models · 7 unmodified lines
88 import (
99 "fmt"
1010
11− "code.gitea.io/gitea/models/perm"
1211 repo_model "code.gitea.io/gitea/models/repo"
1312 "code.gitea.io/gitea/modules/git"
1413 )
@@ -145,83 +144,6 @@ func (err ErrAccessTokenEmpty) Error() string { · 130 unmodified lines
145144 return "access token is empty"
146145 }
147146
148−//.____ ____________________
149−//| | \_ _____/ _____/
150−//| | | __) \_____ \
151−//| |___| \ / \
152−//|_______ \___ / /_______ /
153−// \/ \/ \/
154−
155−// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
156−type ErrLFSLockNotExist struct {
157− ID int64
158− RepoID int64
159− Path string
160−}
161−
162−// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
163−func IsErrLFSLockNotExist(err error) bool {
164− _, ok := err.(ErrLFSLockNotExist)
165− return ok
166−}
167−
168−func (err ErrLFSLockNotExist) Error() string {
169− return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
170−}
171−
172−// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
173−type ErrLFSUnauthorizedAction struct {
174− RepoID int64
175− UserName string
176− Mode perm.AccessMode
177−}
178−
179−// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
180−func IsErrLFSUnauthorizedAction(err error) bool {
181− _, ok := err.(ErrLFSUnauthorizedAction)
182− return ok
183−}
184−
185−func (err ErrLFSUnauthorizedAction) Error() string {
186− if err.Mode == perm.AccessModeWrite {
187− return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
188− }
189− return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
190−}
191−
192−// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
193−type ErrLFSLockAlreadyExist struct {
194− RepoID int64
195− Path string
196−}
197−
198−// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
199−func IsErrLFSLockAlreadyExist(err error) bool {
200− _, ok := err.(ErrLFSLockAlreadyExist)
201− return ok
202−}
203−
204−func (err ErrLFSLockAlreadyExist) Error() string {
205− return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
206−}
207−
208−// ErrLFSFileLocked represents a "LFSFileLocked" kind of error.
209−type ErrLFSFileLocked struct {
210− RepoID int64
211− Path string
212− UserName string
213−}
214−
215−// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked.
216−func IsErrLFSFileLocked(err error) bool {
217− _, ok := err.(ErrLFSFileLocked)
218− return ok
219−}
220−
221−func (err ErrLFSFileLocked) Error() string {
222− return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path)
223−}
224−
225147 // ErrNoPendingRepoTransfer is an error type for repositories without a pending
226148 // transfer request
227149 type ErrNoPendingRepoTransfer struct {
models/git/branches.gorenamed from models/branches.go+7−73
@@ -2,7 +2,7 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git
66
77 import (
88 "context"
@@ -129,10 +129,11 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch, · 120 unmodified lines
129129
130130 // IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
131131 func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
132− return isUserOfficialReviewer(db.DefaultContext, protectBranch, user)
132+ return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user)
133133 }
134134
135−func isUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
135+// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals)
136+func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
136137 repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID)
137138 if err != nil {
138139 return false, err
@@ -159,73 +160,6 @@ func isUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, · 20 unmodified lines
159160 return inTeam, nil
160161 }
161162
162−// HasEnoughApprovals returns true if pr has enough granted approvals.
163−func (protectBranch *ProtectedBranch) HasEnoughApprovals(ctx context.Context, pr *PullRequest) bool {
164− if protectBranch.RequiredApprovals == 0 {
165− return true
166− }
167− return protectBranch.GetGrantedApprovalsCount(ctx, pr) >= protectBranch.RequiredApprovals
168−}
169−
170−// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
171−func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(ctx context.Context, pr *PullRequest) int64 {
172− sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
173− And("type = ?", ReviewTypeApprove).
174− And("official = ?", true).
175− And("dismissed = ?", false)
176− if protectBranch.DismissStaleApprovals {
177− sess = sess.And("stale = ?", false)
178− }
179− approvals, err := sess.Count(new(Review))
180− if err != nil {
181− log.Error("GetGrantedApprovalsCount: %v", err)
182− return 0
183− }
184−
185− return approvals
186−}
187−
188−// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews
189−func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(ctx context.Context, pr *PullRequest) bool {
190− if !protectBranch.BlockOnRejectedReviews {
191− return false
192− }
193− rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
194− And("type = ?", ReviewTypeReject).
195− And("official = ?", true).
196− And("dismissed = ?", false).
197− Exist(new(Review))
198− if err != nil {
199− log.Error("MergeBlockedByRejectedReview: %v", err)
200− return true
201− }
202−
203− return rejectExist
204−}
205−
206−// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer
207−// of from official review
208−func (protectBranch *ProtectedBranch) MergeBlockedByOfficialReviewRequests(ctx context.Context, pr *PullRequest) bool {
209− if !protectBranch.BlockOnOfficialReviewRequests {
210− return false
211− }
212− has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
213− And("type = ?", ReviewTypeRequest).
214− And("official = ?", true).
215− Exist(new(Review))
216− if err != nil {
217− log.Error("MergeBlockedByOfficialReviewRequests: %v", err)
218− return true
219− }
220−
221− return has
222−}
223−
224−// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
225−func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(pr *PullRequest) bool {
226− return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
227−}
228−
229163 // GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice
230164 func (protectBranch *ProtectedBranch) GetProtectedFilePatterns() []glob.Glob {
231165 return getFilePatterns(protectBranch.ProtectedFilePatterns)
@@ -252,13 +186,13 @@ func getFilePatterns(filePatterns string) []glob.Glob { · 20 unmodified lines
252186 }
253187
254188 // MergeBlockedByProtectedFiles returns true if merge is blocked by protected files change
255−func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(pr *PullRequest) bool {
189+func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(changedProtectedFiles []string) bool {
256190 glob := protectBranch.GetProtectedFilePatterns()
257191 if len(glob) == 0 {
258192 return false
259193 }
260194
261− return len(pr.ChangedProtectedFiles) > 0
195+ return len(changedProtectedFiles) > 0
262196 }
263197
264198 // IsProtectedFile return if path is protected
@@ -642,7 +576,7 @@ func RenameBranch(repo *repo_model.Repository, from, to string, gitAction func(i · 377 unmodified lines
642576 }
643577
644578 // 3. Update all not merged pull request base branch name
645− _, err = sess.Table(new(PullRequest)).Where("base_repo_id=? AND base_branch=? AND has_merged=?",
579+ _, err = sess.Table("pull_request").Where("base_repo_id=? AND base_branch=? AND has_merged=?",
646580 repo.ID, from, false).
647581 Update(map[string]interface{}{"base_branch": to})
648582 if err != nil {
models/git/branches_test.gorenamed from models/branches_test.go+26−24
@@ -2,12 +2,14 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git_test
66
77 import (
88 "testing"
99
10+ "code.gitea.io/gitea/models"
1011 "code.gitea.io/gitea/models/db"
12+ git_model "code.gitea.io/gitea/models/git"
1113 repo_model "code.gitea.io/gitea/models/repo"
1214 "code.gitea.io/gitea/models/unittest"
1315
@@ -17,24 +19,24 @@ import ( · 3 unmodified lines
1719 func TestAddDeletedBranch(t *testing.T) {
1820 assert.NoError(t, unittest.PrepareTestDatabase())
1921 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
20− firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
22+ firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch)
2123
22− assert.Error(t, AddDeletedBranch(repo.ID, firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
23− assert.NoError(t, AddDeletedBranch(repo.ID, "test", "5655464564554545466464656", int64(1)))
24+ assert.Error(t, git_model.AddDeletedBranch(repo.ID, firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
25+ assert.NoError(t, git_model.AddDeletedBranch(repo.ID, "test", "5655464564554545466464656", int64(1)))
2426 }
2527
2628 func TestGetDeletedBranches(t *testing.T) {
2729 assert.NoError(t, unittest.PrepareTestDatabase())
2830 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
2931
30− branches, err := GetDeletedBranches(repo.ID)
32+ branches, err := git_model.GetDeletedBranches(repo.ID)
3133 assert.NoError(t, err)
3234 assert.Len(t, branches, 2)
3335 }
3436
3537 func TestGetDeletedBranch(t *testing.T) {
3638 assert.NoError(t, unittest.PrepareTestDatabase())
37− firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
39+ firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch)
3840
3941 assert.NotNil(t, getDeletedBranch(t, firstBranch))
4042 }
@@ -42,8 +44,8 @@ func TestGetDeletedBranch(t *testing.T) { · 1 unmodified line
4244 func TestDeletedBranchLoadUser(t *testing.T) {
4345 assert.NoError(t, unittest.PrepareTestDatabase())
4446
45− firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
46− secondBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch)
47+ firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch)
48+ secondBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 2}).(*git_model.DeletedBranch)
4749
4850 branch := getDeletedBranch(t, firstBranch)
4951 assert.Nil(t, branch.DeletedBy)
@@ -62,18 +64,18 @@ func TestRemoveDeletedBranch(t *testing.T) { · 12 unmodified lines
6264 assert.NoError(t, unittest.PrepareTestDatabase())
6365 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
6466
65− firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
67+ firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch)
6668
67− err := RemoveDeletedBranchByID(repo.ID, 1)
69+ err := git_model.RemoveDeletedBranchByID(repo.ID, 1)
6870 assert.NoError(t, err)
6971 unittest.AssertNotExistsBean(t, firstBranch)
70− unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2})
72+ unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 2})
7173 }
7274
73−func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch {
75+func getDeletedBranch(t *testing.T, branch *git_model.DeletedBranch) *git_model.DeletedBranch {
7476 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
7577
76− deletedBranch, err := GetDeletedBranchByID(repo.ID, branch.ID)
78+ deletedBranch, err := git_model.GetDeletedBranchByID(repo.ID, branch.ID)
7779 assert.NoError(t, err)
7880 assert.Equal(t, branch.ID, deletedBranch.ID)
7981 assert.Equal(t, branch.Name, deletedBranch.Name)
@@ -85,12 +87,12 @@ func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch { · 5 unmodified lines
8587
8688 func TestFindRenamedBranch(t *testing.T) {
8789 assert.NoError(t, unittest.PrepareTestDatabase())
88− branch, exist, err := FindRenamedBranch(1, "dev")
90+ branch, exist, err := git_model.FindRenamedBranch(1, "dev")
8991 assert.NoError(t, err)
9092 assert.Equal(t, true, exist)
9193 assert.Equal(t, "master", branch.To)
9294
93− _, exist, err = FindRenamedBranch(1, "unknow")
95+ _, exist, err = git_model.FindRenamedBranch(1, "unknow")
9496 assert.NoError(t, err)
9597 assert.Equal(t, false, exist)
9698 }
@@ -103,13 +105,13 @@ func TestRenameBranch(t *testing.T) { · 6 unmodified lines
103105 ctx, committer, err := db.TxContext()
104106 defer committer.Close()
105107 assert.NoError(t, err)
106− assert.NoError(t, UpdateProtectBranch(ctx, repo1, &ProtectedBranch{
108+ assert.NoError(t, git_model.UpdateProtectBranch(ctx, repo1, &git_model.ProtectedBranch{
107109 RepoID: repo1.ID,
108110 BranchName: "master",
109− }, WhitelistOptions{}))
111+ }, git_model.WhitelistOptions{}))
110112 assert.NoError(t, committer.Commit())
111113
112− assert.NoError(t, RenameBranch(repo1, "master", "main", func(isDefault bool) error {
114+ assert.NoError(t, git_model.RenameBranch(repo1, "master", "main", func(isDefault bool) error {
113115 _isDefault = isDefault
114116 return nil
115117 }))
@@ -118,18 +120,18 @@ func TestRenameBranch(t *testing.T) { · 2 unmodified lines
118120 repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
119121 assert.Equal(t, "main", repo1.DefaultBranch)
120122
121− pull := unittest.AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest) // merged
123+ pull := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) // merged
122124 assert.Equal(t, "master", pull.BaseBranch)
123125
124− pull = unittest.AssertExistsAndLoadBean(t, &PullRequest{ID: 2}).(*PullRequest) // open
126+ pull = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest) // open
125127 assert.Equal(t, "main", pull.BaseBranch)
126128
127− renamedBranch := unittest.AssertExistsAndLoadBean(t, &RenamedBranch{ID: 2}).(*RenamedBranch)
129+ renamedBranch := unittest.AssertExistsAndLoadBean(t, &git_model.RenamedBranch{ID: 2}).(*git_model.RenamedBranch)
128130 assert.Equal(t, "master", renamedBranch.From)
129131 assert.Equal(t, "main", renamedBranch.To)
130132 assert.Equal(t, int64(1), renamedBranch.RepoID)
131133
132− unittest.AssertExistsAndLoadBean(t, &ProtectedBranch{
134+ unittest.AssertExistsAndLoadBean(t, &git_model.ProtectedBranch{
133135 RepoID: repo1.ID,
134136 BranchName: "main",
135137 })
@@ -143,7 +145,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { · 7 unmodified lines
143145 // is actually on repo with ID 1.
144146 repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
145147
146− deletedBranch, err := GetDeletedBranchByID(repo2.ID, 1)
148+ deletedBranch, err := git_model.GetDeletedBranchByID(repo2.ID, 1)
147149
148150 // Expect no error, and the returned branch is nil.
149151 assert.NoError(t, err)
@@ -153,7 +155,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { · 3 unmodified lines
153155 // This should return the deletedBranch.
154156 repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
155157
156− deletedBranch, err = GetDeletedBranchByID(repo1.ID, 1)
158+ deletedBranch, err = git_model.GetDeletedBranchByID(repo1.ID, 1)
157159
158160 // Expect no error, and the returned branch to be not nil.
159161 assert.NoError(t, err)
models/git/commit_status.gorenamed from models/commit_status.go+17−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git
66
77 import (
88 "context"
@@ -16,6 +16,7 @@ import ( · 7 unmodified lines
1616 "code.gitea.io/gitea/models/db"
1717 repo_model "code.gitea.io/gitea/models/repo"
1818 user_model "code.gitea.io/gitea/models/user"
19+ "code.gitea.io/gitea/modules/git"
1920 "code.gitea.io/gitea/modules/log"
2021 "code.gitea.io/gitea/modules/setting"
2122 api "code.gitea.io/gitea/modules/structs"
@@ -178,7 +179,7 @@ func GetCommitStatuses(repo *repo_model.Repository, sha string, opts *CommitStat · 156 unmodified lines
178179 opts.Page = 1
179180 }
180181 if opts.PageSize <= 0 {
181− opts.Page = ItemsPerPage
182+ opts.Page = setting.ItemsPerPage
182183 }
183184
184185 countSession := listCommitStatusesStatement(repo, sha, opts)
@@ -353,3 +354,17 @@ func ParseCommitsWithStatus(oldCommits []*asymkey_model.SignCommit, repo *repo_m · 168 unmodified lines
353354 func hashCommitStatusContext(context string) string {
354355 return fmt.Sprintf("%x", sha1.Sum([]byte(context)))
355356 }
357+
358+// ConvertFromGitCommit converts git commits into SignCommitWithStatuses
359+func ConvertFromGitCommit(commits []*git.Commit, repo *repo_model.Repository) []*SignCommitWithStatuses {
360+ return ParseCommitsWithStatus(
361+ asymkey_model.ParseCommitsWithSignature(
362+ user_model.ValidateCommitsWithEmails(commits),
363+ repo.GetTrustModel(),
364+ func(user *user_model.User) (bool, error) {
365+ return repo_model.IsOwnerMemberCollaborator(repo, user.ID)
366+ },
367+ ),
368+ repo,
369+ )
370+}
models/git/commit_status_test.gorenamed from models/commit_status_test.go+3−2
@@ -2,12 +2,13 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git_test
66
77 import (
88 "testing"
99
1010 "code.gitea.io/gitea/models/db"
11+ git_model "code.gitea.io/gitea/models/git"
1112 repo_model "code.gitea.io/gitea/models/repo"
1213 "code.gitea.io/gitea/models/unittest"
1314 "code.gitea.io/gitea/modules/structs"
@@ -22,7 +23,7 @@ func TestGetCommitStatuses(t *testing.T) { · 8 unmodified lines
2223
2324 sha1 := "1234123412341234123412341234123412341234"
2425
25− statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 50}})
26+ statuses, maxResults, err := git_model.GetCommitStatuses(repo1, sha1, &git_model.CommitStatusOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 50}})
2627 assert.NoError(t, err)
2728 assert.Equal(t, int(maxResults), 5)
2829 assert.Len(t, statuses, 5)
models/git/lfs.gorenamed from models/lfs.go+73−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git
66
77 import (
88 "context"
@@ -10,6 +10,7 @@ import ( · 1 unmodified line
1010 "fmt"
1111
1212 "code.gitea.io/gitea/models/db"
13+ "code.gitea.io/gitea/models/perm"
1314 repo_model "code.gitea.io/gitea/models/repo"
1415 user_model "code.gitea.io/gitea/models/user"
1516 "code.gitea.io/gitea/modules/lfs"
@@ -19,6 +20,76 @@ import ( · 3 unmodified lines
1920 "xorm.io/builder"
2021 )
2122
23+// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
24+type ErrLFSLockNotExist struct {
25+ ID int64
26+ RepoID int64
27+ Path string
28+}
29+
30+// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
31+func IsErrLFSLockNotExist(err error) bool {
32+ _, ok := err.(ErrLFSLockNotExist)
33+ return ok
34+}
35+
36+func (err ErrLFSLockNotExist) Error() string {
37+ return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
38+}
39+
40+// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
41+type ErrLFSUnauthorizedAction struct {
42+ RepoID int64
43+ UserName string
44+ Mode perm.AccessMode
45+}
46+
47+// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
48+func IsErrLFSUnauthorizedAction(err error) bool {
49+ _, ok := err.(ErrLFSUnauthorizedAction)
50+ return ok
51+}
52+
53+func (err ErrLFSUnauthorizedAction) Error() string {
54+ if err.Mode == perm.AccessModeWrite {
55+ return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
56+ }
57+ return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
58+}
59+
60+// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
61+type ErrLFSLockAlreadyExist struct {
62+ RepoID int64
63+ Path string
64+}
65+
66+// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
67+func IsErrLFSLockAlreadyExist(err error) bool {
68+ _, ok := err.(ErrLFSLockAlreadyExist)
69+ return ok
70+}
71+
72+func (err ErrLFSLockAlreadyExist) Error() string {
73+ return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
74+}
75+
76+// ErrLFSFileLocked represents a "LFSFileLocked" kind of error.
77+type ErrLFSFileLocked struct {
78+ RepoID int64
79+ Path string
80+ UserName string
81+}
82+
83+// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked.
84+func IsErrLFSFileLocked(err error) bool {
85+ _, ok := err.(ErrLFSFileLocked)
86+ return ok
87+}
88+
89+func (err ErrLFSFileLocked) Error() string {
90+ return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path)
91+}
92+
2293 // LFSMetaObject stores metadata for LFS tracked files.
2394 type LFSMetaObject struct {
2495 ID int64 `xorm:"pk autoincr"`
@@ -239,7 +310,7 @@ func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error · 214 unmodified lines
239310 for _, v := range lfsObjects {
240311 v.ID = 0
241312 v.RepositoryID = newRepo.ID
242− if _, err := db.GetEngine(ctx).Insert(v); err != nil {
313+ if err := db.Insert(ctx, v); err != nil {
243314 return err
244315 }
245316 }
models/git/lfs_lock.gorenamed from models/lfs_lock.go+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git
66
77 import (
88 "context"
models/git/main_test.go+18−0
@@ -0,0 +1,18 @@
1+// Copyright 2020 The Gitea Authors. All rights reserved.
2+// Use of this source code is governed by a MIT-style
3+// license that can be found in the LICENSE file.
4+
5+package git_test
6+
7+import (
8+ "path/filepath"
9+ "testing"
10+
11+ "code.gitea.io/gitea/models/unittest"
12+)
13+
14+func TestMain(m *testing.M) {
15+ unittest.MainTest(m, &unittest.TestOptions{
16+ GiteaRootPath: filepath.Join("..", ".."),
17+ })
18+}
models/git/protected_tag.gorenamed from models/protected_tag.go+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git
66
77 import (
88 "regexp"
models/git/protected_tag_test.gorenamed from models/protected_tag_test.go+17−16
@@ -2,11 +2,12 @@ · 1 unmodified line
22 // Use of this source code is governed by a MIT-style
33 // license that can be found in the LICENSE file.
44
5−package models
5+package git_test
66
77 import (
88 "testing"
99
10+ git_model "code.gitea.io/gitea/models/git"
1011 "code.gitea.io/gitea/models/unittest"
1112
1213 "github.com/stretchr/testify/assert"
@@ -15,42 +16,42 @@ import ( · 2 unmodified lines
1516 func TestIsUserAllowed(t *testing.T) {
1617 assert.NoError(t, unittest.PrepareTestDatabase())
1718
18− pt := &ProtectedTag{}
19− allowed, err := IsUserAllowedModifyTag(pt, 1)
19+ pt := &git_model.ProtectedTag{}
20+ allowed, err := git_model.IsUserAllowedModifyTag(pt, 1)
2021 assert.NoError(t, err)
2122 assert.False(t, allowed)
2223
23− pt = &ProtectedTag{
24+ pt = &git_model.ProtectedTag{
2425 AllowlistUserIDs: []int64{1},
2526 }
26− allowed, err = IsUserAllowedModifyTag(pt, 1)
27+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 1)
2728 assert.NoError(t, err)
2829 assert.True(t, allowed)
2930
30− allowed, err = IsUserAllowedModifyTag(pt, 2)
31+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 2)
3132 assert.NoError(t, err)
3233 assert.False(t, allowed)
3334
34− pt = &ProtectedTag{
35+ pt = &git_model.ProtectedTag{
3536 AllowlistTeamIDs: []int64{1},
3637 }
37− allowed, err = IsUserAllowedModifyTag(pt, 1)
38+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 1)
3839 assert.NoError(t, err)
3940 assert.False(t, allowed)
4041
41− allowed, err = IsUserAllowedModifyTag(pt, 2)
42+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 2)
4243 assert.NoError(t, err)
4344 assert.True(t, allowed)
4445
45− pt = &ProtectedTag{
46+ pt = &git_model.ProtectedTag{
4647 AllowlistUserIDs: []int64{1},
4748 AllowlistTeamIDs: []int64{1},
4849 }
49− allowed, err = IsUserAllowedModifyTag(pt, 1)
50+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 1)
5051 assert.NoError(t, err)
5152 assert.True(t, allowed)
5253
53− allowed, err = IsUserAllowedModifyTag(pt, 2)
54+ allowed, err = git_model.IsUserAllowedModifyTag(pt, 2)
5455 assert.NoError(t, err)
5556 assert.True(t, allowed)
5657 }
@@ -119,7 +120,7 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 62 unmodified lines
119120 }
120121
121122 t.Run("Glob", func(t *testing.T) {
122− protectedTags := []*ProtectedTag{
123+ protectedTags := []*git_model.ProtectedTag{
123124 {
124125 NamePattern: `*gitea`,
125126 AllowlistUserIDs: []int64{1},
@@ -134,14 +135,14 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 8 unmodified lines
134135 }
135136
136137 for n, c := range cases {
137− isAllowed, err := IsUserAllowedToControlTag(protectedTags, c.name, c.userid)
138+ isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, c.name, c.userid)
138139 assert.NoError(t, err)
139140 assert.Equal(t, c.allowed, isAllowed, "case %d: error should match", n)
140141 }
141142 })
142143
143144 t.Run("Regex", func(t *testing.T) {
144− protectedTags := []*ProtectedTag{
145+ protectedTags := []*git_model.ProtectedTag{
145146 {
146147 NamePattern: `/gitea\z/`,
147148 AllowlistUserIDs: []int64{1},
@@ -156,7 +157,7 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 8 unmodified lines
156157 }
157158
158159 for n, c := range cases {
159− isAllowed, err := IsUserAllowedToControlTag(protectedTags, c.name, c.userid)
160+ isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, c.name, c.userid)
160161 assert.NoError(t, err)
161162 assert.Equal(t, c.allowed, isAllowed, "case %d: error should match", n)
162163 }
models/issue_comment.go+7−6
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515 "unicode/utf8"
1616
1717 "code.gitea.io/gitea/models/db"
18+ git_model "code.gitea.io/gitea/models/git"
1819 issues_model "code.gitea.io/gitea/models/issues"
1920 "code.gitea.io/gitea/models/organization"
2021 project_model "code.gitea.io/gitea/models/project"
@@ -271,11 +272,11 @@ type Comment struct { · 250 unmodified lines
271272 RefIssue *Issue `xorm:"-"`
272273 RefComment *Comment `xorm:"-"`
273274
274− Commits []*SignCommitWithStatuses `xorm:"-"`
275− OldCommit string `xorm:"-"`
276− NewCommit string `xorm:"-"`
277− CommitsNum int64 `xorm:"-"`
278− IsForcePush bool `xorm:"-"`
275+ Commits []*git_model.SignCommitWithStatuses `xorm:"-"`
276+ OldCommit string `xorm:"-"`
277+ NewCommit string `xorm:"-"`
278+ CommitsNum int64 `xorm:"-"`
279+ IsForcePush bool `xorm:"-"`
279280 }
280281
281282 func init() {
@@ -761,7 +762,7 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) { · 479 unmodified lines
761762 }
762763 defer closer.Close()
763764
764− c.Commits = ConvertFromGitCommit(gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo)
765+ c.Commits = git_model.ConvertFromGitCommit(gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo)
765766 c.CommitsNum = int64(len(c.Commits))
766767 }
767768
models/org_team.go+2−1
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313
1414 "code.gitea.io/gitea/models/db"
15+ git_model "code.gitea.io/gitea/models/git"
1516 "code.gitea.io/gitea/models/organization"
1617 access_model "code.gitea.io/gitea/models/perm/access"
1718 repo_model "code.gitea.io/gitea/models/repo"
@@ -412,7 +413,7 @@ func DeleteTeam(t *organization.Team) error { · 394 unmodified lines
412413
413414 // update branch protections
414415 {
415− protections := make([]*ProtectedBranch, 0, 10)
416+ protections := make([]*git_model.ProtectedBranch, 0, 10)
416417 err := sess.In("repo_id",
417418 builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})).
418419 Find(&protections)
models/pull.go+5−4
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313
1414 "code.gitea.io/gitea/models/db"
15+ git_model "code.gitea.io/gitea/models/git"
1516 pull_model "code.gitea.io/gitea/models/pull"
1617 repo_model "code.gitea.io/gitea/models/repo"
1718 user_model "code.gitea.io/gitea/models/user"
@@ -78,9 +79,9 @@ type PullRequest struct { · 60 unmodified lines
7879 HeadBranch string
7980 HeadCommitID string `xorm:"-"`
8081 BaseBranch string
81− ProtectedBranch *ProtectedBranch `xorm:"-"`
82− MergeBase string `xorm:"VARCHAR(40)"`
83− AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`
82+ ProtectedBranch *git_model.ProtectedBranch `xorm:"-"`
83+ MergeBase string `xorm:"VARCHAR(40)"`
84+ AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`
8485
8586 HasMerged bool `xorm:"INDEX"`
8687 MergedCommitID string `xorm:"VARCHAR(40)"`
@@ -242,7 +243,7 @@ func (pr *PullRequest) LoadProtectedBranchCtx(ctx context.Context) (err error) { · 155 unmodified lines
242243 return
243244 }
244245 }
245− pr.ProtectedBranch, err = GetProtectedBranchBy(ctx, pr.BaseRepo.ID, pr.BaseBranch)
246+ pr.ProtectedBranch, err = git_model.GetProtectedBranchBy(ctx, pr.BaseRepo.ID, pr.BaseBranch)
246247 }
247248 return
248249 }
models/repo.go+9−11
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515 admin_model "code.gitea.io/gitea/models/admin"
1616 asymkey_model "code.gitea.io/gitea/models/asymkey"
1717 "code.gitea.io/gitea/models/db"
18+ git_model "code.gitea.io/gitea/models/git"
1819 issues_model "code.gitea.io/gitea/models/issues"
1920 "code.gitea.io/gitea/models/organization"
2021 "code.gitea.io/gitea/models/perm"
@@ -34,9 +35,6 @@ import ( · 13 unmodified lines
3435 "xorm.io/builder"
3536 )
3637
37−// ItemsPerPage maximum items per page in forks, watchers and stars of a repo
38−var ItemsPerPage = 40
39−
4038 // NewRepoContext creates a new repository context
4139 func NewRepoContext() {
4240 unit.LoadUnitConfig()
@@ -284,16 +282,16 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 241 unmodified lines
284282 &Action{RepoID: repo.ID},
285283 &repo_model.Collaboration{RepoID: repoID},
286284 &Comment{RefRepoID: repoID},
287− &CommitStatus{RepoID: repoID},
288− &DeletedBranch{RepoID: repoID},
285+ &git_model.CommitStatus{RepoID: repoID},
286+ &git_model.DeletedBranch{RepoID: repoID},
289287 &webhook.HookTask{RepoID: repoID},
290− &LFSLock{RepoID: repoID},
288+ &git_model.LFSLock{RepoID: repoID},
291289 &repo_model.LanguageStat{RepoID: repoID},
292290 &issues_model.Milestone{RepoID: repoID},
293291 &repo_model.Mirror{RepoID: repoID},
294292 &Notification{RepoID: repoID},
295− &ProtectedBranch{RepoID: repoID},
296− &ProtectedTag{RepoID: repoID},
293+ &git_model.ProtectedBranch{RepoID: repoID},
294+ &git_model.ProtectedTag{RepoID: repoID},
297295 &repo_model.PushMirror{RepoID: repoID},
298296 &Release{RepoID: repoID},
299297 &repo_model.RepoIndexerStatus{RepoID: repoID},
@@ -357,14 +355,14 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 57 unmodified lines
357355 }
358356
359357 // Remove LFS objects
360− var lfsObjects []*LFSMetaObject
358+ var lfsObjects []*git_model.LFSMetaObject
361359 if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
362360 return err
363361 }
364362
365363 lfsPaths := make([]string, 0, len(lfsObjects))
366364 for _, v := range lfsObjects {
367− count, err := db.CountByBean(ctx, &LFSMetaObject{Pointer: lfs.Pointer{Oid: v.Oid}})
365+ count, err := db.CountByBean(ctx, &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: v.Oid}})
368366 if err != nil {
369367 return err
370368 }
@@ -375,7 +373,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 4 unmodified lines
375373 lfsPaths = append(lfsPaths, v.RelativePath())
376374 }
377375
378− if _, err := db.DeleteByBean(ctx, &LFSMetaObject{RepositoryID: repoID}); err != nil {
376+ if _, err := db.DeleteByBean(ctx, &git_model.LFSMetaObject{RepositoryID: repoID}); err != nil {
379377 return err
380378 }
381379
models/repo/collaboration.go+21−0
@@ -10,6 +10,7 @@ import ( · 9 unmodified lines
1010
1111 "code.gitea.io/gitea/models/db"
1212 "code.gitea.io/gitea/models/perm"
13+ "code.gitea.io/gitea/models/unit"
1314 user_model "code.gitea.io/gitea/models/user"
1415 "code.gitea.io/gitea/modules/log"
1516 "code.gitea.io/gitea/modules/timeutil"
@@ -149,3 +150,23 @@ func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.Access · 133 unmodified lines
149150
150151 return committer.Commit()
151152 }
153+
154+// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
155+func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
156+ if repo.OwnerID == userID {
157+ return true, nil
158+ }
159+ teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
160+ Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
161+ Where("team_repo.repo_id = ?", repo.ID).
162+ And("team_unit.`type` = ?", unit.TypeCode).
163+ And("team_user.uid = ?", userID).Table("team_user").Exist()
164+ if err != nil {
165+ return false, err
166+ }
167+ if teamMember {
168+ return true, nil
169+ }
170+
171+ return db.GetEngine(db.DefaultContext).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
172+}
models/repo_collaboration.go+0−22
@@ -10,11 +10,9 @@ import ( · 9 unmodified lines
1010 "fmt"
1111
1212 "code.gitea.io/gitea/models/db"
13− "code.gitea.io/gitea/models/organization"
1413 "code.gitea.io/gitea/models/perm"
1514 access_model "code.gitea.io/gitea/models/perm/access"
1615 repo_model "code.gitea.io/gitea/models/repo"
17− "code.gitea.io/gitea/models/unit"
1816 user_model "code.gitea.io/gitea/models/user"
1917
2018 "xorm.io/builder"
@@ -120,23 +118,3 @@ func reconsiderWatches(ctx context.Context, repo *repo_model.Repository, uid int · 99 unmodified lines
120118 // Remove all IssueWatches a user has subscribed to in the repository
121119 return removeIssueWatchersByRepoID(ctx, uid, repo.ID)
122120 }
123−
124−// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
125−func IsOwnerMemberCollaborator(repo *repo_model.Repository, userID int64) (bool, error) {
126− if repo.OwnerID == userID {
127− return true, nil
128− }
129− teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
130− Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
131− Where("team_repo.repo_id = ?", repo.ID).
132− And("team_unit.`type` = ?", unit.TypeCode).
133− And("team_user.uid = ?", userID).Table("team_user").Exist(&organization.TeamUser{})
134− if err != nil {
135− return false, err
136− }
137− if teamMember {
138− return true, nil
139− }
140−
141− return db.GetEngine(db.DefaultContext).Get(&repo_model.Collaboration{RepoID: repo.ID, UserID: userID})
142−}
models/review.go+2−1
@@ -10,6 +10,7 @@ import ( · 9 unmodified lines
1010 "strings"
1111
1212 "code.gitea.io/gitea/models/db"
13+ git_model "code.gitea.io/gitea/models/git"
1314 "code.gitea.io/gitea/models/organization"
1415 "code.gitea.io/gitea/models/perm"
1516 access_model "code.gitea.io/gitea/models/perm/access"
@@ -234,7 +235,7 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo · 218 unmodified lines
234235 }
235236
236237 for _, reviewer := range reviewers {
237− official, err := isUserOfficialReviewer(ctx, pr.ProtectedBranch, reviewer)
238+ official, err := git_model.IsUserOfficialReviewerCtx(ctx, pr.ProtectedBranch, reviewer)
238239 if official || err != nil {
239240 return official, err
240241 }
models/user.go+2−1
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515 asymkey_model "code.gitea.io/gitea/models/asymkey"
1616 auth_model "code.gitea.io/gitea/models/auth"
1717 "code.gitea.io/gitea/models/db"
18+ git_model "code.gitea.io/gitea/models/git"
1819 "code.gitea.io/gitea/models/issues"
1920 "code.gitea.io/gitea/models/organization"
2021 access_model "code.gitea.io/gitea/models/perm/access"
@@ -125,7 +126,7 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) { · 104 unmodified lines
125126 {
126127 const batchSize = 50
127128 for start := 0; ; start += batchSize {
128− protections := make([]*ProtectedBranch, 0, batchSize)
129+ protections := make([]*git_model.ProtectedBranch, 0, batchSize)
129130 // @perf: We can't filter on DB side by u.ID, as those IDs are serialized as JSON strings.
130131 // We could filter down with `WHERE repo_id IN (reposWithPushPermission(u))`,
131132 // though that query will be quite complex and tricky to maintain (compare `getRepoAssignees()`).
modules/context/repo.go+3−2
@@ -17,6 +17,7 @@ import ( · 16 unmodified lines
1717
1818 "code.gitea.io/gitea/models"
1919 "code.gitea.io/gitea/models/db"
20+ git_model "code.gitea.io/gitea/models/git"
2021 access_model "code.gitea.io/gitea/models/perm/access"
2122 repo_model "code.gitea.io/gitea/models/repo"
2223 unit_model "code.gitea.io/gitea/models/unit"
@@ -118,7 +119,7 @@ type CanCommitToBranchResults struct { · 95 unmodified lines
118119 // CanCommitToBranch returns true if repository is editable and user has proper access level
119120 // and branch is not protected for push
120121 func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) {
121− protectedBranch, err := models.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName)
122+ protectedBranch, err := git_model.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName)
122123 if err != nil {
123124 return CanCommitToBranchResults{}, err
124125 }
@@ -825,7 +826,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string { · 700 unmodified lines
825826 if len(ref) == 0 {
826827 // maybe it's a renamed branch
827828 return getRefNameFromPath(ctx, path, func(s string) bool {
828− b, exist, err := models.FindRenamedBranch(ctx.Repo.Repository.ID, s)
829+ b, exist, err := git_model.FindRenamedBranch(ctx.Repo.Repository.ID, s)
829830 if err != nil {
830831 log.Error("FindRenamedBranch", err)
831832 return false
modules/convert/convert.go+5−4
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515 asymkey_model "code.gitea.io/gitea/models/asymkey"
1616 "code.gitea.io/gitea/models/auth"
1717 "code.gitea.io/gitea/models/db"
18+ git_model "code.gitea.io/gitea/models/git"
1819 "code.gitea.io/gitea/models/organization"
1920 "code.gitea.io/gitea/models/perm"
2021 access_model "code.gitea.io/gitea/models/perm/access"
@@ -39,7 +40,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { · 18 unmodified lines
3940 }
4041
4142 // ToBranch convert a git.Commit and git.Branch to an api.Branch
42−func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) {
43+func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git_model.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) {
4344 if bp == nil {
4445 var hasPerm bool
4546 var canPush bool
@@ -88,14 +89,14 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod · 42 unmodified lines
8889 return nil, err
8990 }
9091 branch.UserCanPush = bp.CanUserPush(user.ID)
91− branch.UserCanMerge = models.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission)
92+ branch.UserCanMerge = git_model.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission)
9293 }
9394
9495 return branch, nil
9596 }
9697
9798 // ToBranchProtection convert a ProtectedBranch to api.BranchProtection
98−func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
99+func ToBranchProtection(bp *git_model.ProtectedBranch) *api.BranchProtection {
99100 pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs)
100101 if err != nil {
101102 log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err)
@@ -399,7 +400,7 @@ func ToOAuth2Application(app *auth.OAuth2Application) *api.OAuth2Application { · 297 unmodified lines
399400 }
400401
401402 // ToLFSLock convert a LFSLock to api.LFSLock
402−func ToLFSLock(l *models.LFSLock) *api.LFSLock {
403+func ToLFSLock(l *git_model.LFSLock) *api.LFSLock {
403404 u, err := user_model.GetUserByID(l.OwnerID)
404405 if err != nil {
405406 return nil
modules/convert/status.go+4−4
@@ -5,13 +5,13 @@ · 4 unmodified lines
55 package convert
66
77 import (
8− "code.gitea.io/gitea/models"
8+ git_model "code.gitea.io/gitea/models/git"
99 user_model "code.gitea.io/gitea/models/user"
1010 api "code.gitea.io/gitea/modules/structs"
1111 )
1212
13−// ToCommitStatus converts models.CommitStatus to api.CommitStatus
14−func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus {
13+// ToCommitStatus converts git_model.CommitStatus to api.CommitStatus
14+func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus {
1515 apiStatus := &api.CommitStatus{
1616 Created: status.CreatedUnix.AsTime(),
1717 Updated: status.CreatedUnix.AsTime(),
@@ -32,7 +32,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { · 14 unmodified lines
3232 }
3333
3434 // ToCombinedStatus converts List of CommitStatus to a CombinedStatus
35−func ToCombinedStatus(statuses []*models.CommitStatus, repo *api.Repository) *api.CombinedStatus {
35+func ToCombinedStatus(statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
3636 if len(statuses) == 0 {
3737 return nil
3838 }
modules/gitgraph/graph_models.go+5−5
@@ -9,9 +9,9 @@ import ( · 8 unmodified lines
99 "fmt"
1010 "strings"
1111
12− "code.gitea.io/gitea/models"
1312 asymkey_model "code.gitea.io/gitea/models/asymkey"
1413 "code.gitea.io/gitea/models/db"
14+ git_model "code.gitea.io/gitea/models/git"
1515 repo_model "code.gitea.io/gitea/models/repo"
1616 user_model "code.gitea.io/gitea/models/user"
1717 "code.gitea.io/gitea/modules/git"
@@ -117,14 +117,14 @@ func (graph *Graph) LoadAndProcessCommits(repository *repo_model.Repository, git · 99 unmodified lines
117117 c.Verification = asymkey_model.ParseCommitWithSignature(c.Commit)
118118
119119 _ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
120− return models.IsOwnerMemberCollaborator(repository, user.ID)
120+ return repo_model.IsOwnerMemberCollaborator(repository, user.ID)
121121 }, &keyMap)
122122
123− statuses, _, err := models.GetLatestCommitStatus(db.DefaultContext, repository.ID, c.Commit.ID.String(), db.ListOptions{})
123+ statuses, _, err := git_model.GetLatestCommitStatus(db.DefaultContext, repository.ID, c.Commit.ID.String(), db.ListOptions{})
124124 if err != nil {
125125 log.Error("GetLatestCommitStatus: %v", err)
126126 } else {
127− c.Status = models.CalcCommitStatus(statuses)
127+ c.Status = git_model.CalcCommitStatus(statuses)
128128 }
129129 }
130130 return nil
@@ -240,7 +240,7 @@ type Commit struct { · 109 unmodified lines
240240 Commit *git.Commit
241241 User *user_model.User
242242 Verification *asymkey_model.CommitVerification
243− Status *models.CommitStatus
243+ Status *git_model.CommitStatus
244244 Flow int64
245245 Row int
246246 Column int
modules/lfs/content_store.go+1−1
@@ -113,7 +113,7 @@ func (s *ContentStore) Verify(pointer Pointer) (bool, error) { · 112 unmodified lines
113113 return true, nil
114114 }
115115
116−// ReadMetaObject will read a models.LFSMetaObject and return a reader
116+// ReadMetaObject will read a git_model.LFSMetaObject and return a reader
117117 func ReadMetaObject(pointer Pointer) (io.ReadCloser, error) {
118118 contentStore := NewContentStore()
119119 return contentStore.Get(pointer)
modules/repository/create.go+2−1
@@ -14,6 +14,7 @@ import ( · 13 unmodified lines
1414
1515 "code.gitea.io/gitea/models"
1616 "code.gitea.io/gitea/models/db"
17+ git_model "code.gitea.io/gitea/models/git"
1718 access_model "code.gitea.io/gitea/models/perm/access"
1819 repo_model "code.gitea.io/gitea/models/repo"
1920 user_model "code.gitea.io/gitea/models/user"
@@ -146,7 +147,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { · 126 unmodified lines
146147 return fmt.Errorf("updateSize: %v", err)
147148 }
148149
149− lfsSize, err := models.GetRepoLFSSize(ctx, repo.ID)
150+ lfsSize, err := git_model.GetRepoLFSSize(ctx, repo.ID)
150151 if err != nil {
151152 return fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err)
152153 }
modules/repository/generate.go+2−1
@@ -16,6 +16,7 @@ import ( · 15 unmodified lines
1616 "time"
1717
1818 "code.gitea.io/gitea/models"
19+ git_model "code.gitea.io/gitea/models/git"
1920 repo_model "code.gitea.io/gitea/models/repo"
2021 user_model "code.gitea.io/gitea/models/user"
2122 "code.gitea.io/gitea/modules/git"
@@ -278,7 +279,7 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_mo · 256 unmodified lines
278279 return fmt.Errorf("failed to update size for repository: %v", err)
279280 }
280281
281− if err := models.CopyLFS(ctx, generateRepo, templateRepo); err != nil {
282+ if err := git_model.CopyLFS(ctx, generateRepo, templateRepo); err != nil {
282283 return fmt.Errorf("failed to copy LFS: %v", err)
283284 }
284285 return nil
modules/repository/repo.go+6−5
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515
1616 "code.gitea.io/gitea/models"
1717 "code.gitea.io/gitea/models/db"
18+ git_model "code.gitea.io/gitea/models/git"
1819 "code.gitea.io/gitea/models/organization"
1920 repo_model "code.gitea.io/gitea/models/repo"
2021 user_model "code.gitea.io/gitea/models/user"
@@ -390,7 +391,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 369 unmodified lines
390391
391392 defer content.Close()
392393
393− _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repo.ID})
394+ _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repo.ID})
394395 if err != nil {
395396 log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, p, err)
396397 return err
@@ -398,7 +399,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 1 unmodified line
398399
399400 if err := contentStore.Put(p, content); err != nil {
400401 log.Error("Repo[%-v]: Error storing content for LFS meta object %-v: %v", repo, p, err)
401− if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil {
402+ if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil {
402403 log.Error("Repo[%-v]: Error removing LFS meta object %-v: %v", repo, p, err2)
403404 }
404405 return err
@@ -417,8 +418,8 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 12 unmodified lines
417418
418419 var batch []lfs.Pointer
419420 for pointerBlob := range pointerChan {
420− meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid)
421− if err != nil && err != models.ErrLFSObjectNotExist {
421+ meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid)
422+ if err != nil && err != git_model.ErrLFSObjectNotExist {
422423 log.Error("Repo[%-v]: Error querying LFS meta object %-v: %v", repo, pointerBlob.Pointer, err)
423424 return err
424425 }
@@ -437,7 +438,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 12 unmodified lines
437438
438439 if exist {
439440 log.Trace("Repo[%-v]: LFS object %-v already present; creating meta object", repo, pointerBlob.Pointer)
440− _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID})
441+ _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID})
441442 if err != nil {
442443 log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, pointerBlob.Pointer, err)
443444 return err
modules/setting/repository.go+3−0
@@ -20,6 +20,9 @@ const ( · 19 unmodified lines
2020 RepoCreatingPublic = "public"
2121 )
2222
23+// ItemsPerPage maximum items per page in forks, watchers and stars of a repo
24+const ItemsPerPage = 40
25+
2326 // Repository settings
2427 var (
2528 Repository = struct {
routers/api/v1/repo/branch.go+15−14
@@ -11,6 +11,7 @@ import ( · 10 unmodified lines
1111 "net/http"
1212
1313 "code.gitea.io/gitea/models"
14+ git_model "code.gitea.io/gitea/models/git"
1415 "code.gitea.io/gitea/models/organization"
1516 user_model "code.gitea.io/gitea/models/user"
1617 "code.gitea.io/gitea/modules/context"
@@ -70,7 +71,7 @@ func GetBranch(ctx *context.APIContext) { · 53 unmodified lines
7071 return
7172 }
7273
73− branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName)
74+ branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName)
7475 if err != nil {
7576 ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
7677 return
@@ -206,7 +207,7 @@ func CreateBranch(ctx *context.APIContext) { · 129 unmodified lines
206207 return
207208 }
208209
209− branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name)
210+ branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name)
210211 if err != nil {
211212 ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
212213 return
@@ -271,7 +272,7 @@ func ListBranches(ctx *context.APIContext) { · 58 unmodified lines
271272 ctx.Error(http.StatusInternalServerError, "GetCommit", err)
272273 return
273274 }
274− branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name)
275+ branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name)
275276 if err != nil {
276277 ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
277278 return
@@ -320,7 +321,7 @@ func GetBranchProtection(ctx *context.APIContext) { · 42 unmodified lines
320321
321322 repo := ctx.Repo.Repository
322323 bpName := ctx.Params(":name")
323− bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
324+ bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
324325 if err != nil {
325326 ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
326327 return
@@ -356,7 +357,7 @@ func ListBranchProtections(ctx *context.APIContext) { · 29 unmodified lines
356357 // "$ref": "#/responses/BranchProtectionList"
357358
358359 repo := ctx.Repo.Repository
359− bps, err := models.GetProtectedBranches(repo.ID)
360+ bps, err := git_model.GetProtectedBranches(repo.ID)
360361 if err != nil {
361362 ctx.Error(http.StatusInternalServerError, "GetProtectedBranches", err)
362363 return
@@ -412,7 +413,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 49 unmodified lines
412413 return
413414 }
414415
415− protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, form.BranchName)
416+ protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, form.BranchName)
416417 if err != nil {
417418 ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err)
418419 return
@@ -484,7 +485,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 65 unmodified lines
484485 }
485486 }
486487
487− protectBranch = &models.ProtectedBranch{
488+ protectBranch = &git_model.ProtectedBranch{
488489 RepoID: ctx.Repo.Repository.ID,
489490 BranchName: form.BranchName,
490491 CanPush: form.EnablePush,
@@ -504,7 +505,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 13 unmodified lines
504505 BlockOnOutdatedBranch: form.BlockOnOutdatedBranch,
505506 }
506507
507− err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
508+ err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
508509 UserIDs: whitelistUsers,
509510 TeamIDs: whitelistTeams,
510511 MergeUserIDs: mergeWhitelistUsers,
@@ -523,7 +524,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 12 unmodified lines
523524 }
524525
525526 // Reload from db to get all whitelists
526− bp, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName)
527+ bp, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName)
527528 if err != nil {
528529 ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
529530 return
@@ -575,7 +576,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 45 unmodified lines
575576 form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
576577 repo := ctx.Repo.Repository
577578 bpName := ctx.Params(":name")
578− protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
579+ protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
579580 if err != nil {
580581 ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
581582 return
@@ -739,7 +740,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 157 unmodified lines
739740 }
740741 }
741742
742− err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
743+ err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
743744 UserIDs: whitelistUsers,
744745 TeamIDs: whitelistTeams,
745746 MergeUserIDs: mergeWhitelistUsers,
@@ -758,7 +759,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 12 unmodified lines
758759 }
759760
760761 // Reload from db to ensure get all whitelists
761− bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
762+ bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
762763 if err != nil {
763764 ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err)
764765 return
@@ -802,7 +803,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { · 37 unmodified lines
802803
803804 repo := ctx.Repo.Repository
804805 bpName := ctx.Params(":name")
805− bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
806+ bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
806807 if err != nil {
807808 ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
808809 return
@@ -812,7 +813,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { · 3 unmodified lines
812813 return
813814 }
814815
815− if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil {
816+ if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil {
816817 ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err)
817818 return
818819 }
routers/api/v1/repo/file.go+3−2
@@ -15,6 +15,7 @@ import ( · 14 unmodified lines
1515 "time"
1616
1717 "code.gitea.io/gitea/models"
18+ git_model "code.gitea.io/gitea/models/git"
1819 repo_model "code.gitea.io/gitea/models/repo"
1920 "code.gitea.io/gitea/models/unit"
2021 "code.gitea.io/gitea/modules/cache"
@@ -173,10 +174,10 @@ func GetRawFileOrLFS(ctx *context.APIContext) { · 152 unmodified lines
173174 }
174175
175176 // Now check if there is a meta object for this pointer
176− meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
177+ meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
177178
178179 // If there isn't one just serve the data directly
179− if err == models.ErrLFSObjectNotExist {
180+ if err == git_model.ErrLFSObjectNotExist {
180181 // Handle caching for the blob SHA (not the LFS object OID)
181182 if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
182183 return
routers/api/v1/repo/status.go+4−4
@@ -8,7 +8,7 @@ import ( · 7 unmodified lines
88 "fmt"
99 "net/http"
1010
11− "code.gitea.io/gitea/models"
11+ git_model "code.gitea.io/gitea/models/git"
1212 "code.gitea.io/gitea/modules/context"
1313 "code.gitea.io/gitea/modules/convert"
1414 api "code.gitea.io/gitea/modules/structs"
@@ -56,7 +56,7 @@ func NewCommitStatus(ctx *context.APIContext) { · 41 unmodified lines
5656 ctx.Error(http.StatusBadRequest, "sha not given", nil)
5757 return
5858 }
59− status := &models.CommitStatus{
59+ status := &git_model.CommitStatus{
6060 State: api.CommitStatusState(form.State),
6161 TargetURL: form.TargetURL,
6262 Description: form.Description,
@@ -188,7 +188,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { · 125 unmodified lines
188188
189189 listOptions := utils.GetListOptions(ctx)
190190
191− statuses, maxResults, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{
191+ statuses, maxResults, err := git_model.GetCommitStatuses(repo, sha, &git_model.CommitStatusOptions{
192192 ListOptions: listOptions,
193193 SortType: ctx.FormTrim("sort"),
194194 State: ctx.FormTrim("state"),
@@ -253,7 +253,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { · 58 unmodified lines
253253
254254 repo := ctx.Repo.Repository
255255
256− statuses, count, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
256+ statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
257257 if err != nil {
258258 ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err))
259259 return
routers/private/hook_pre_receive.go+5−4
@@ -13,6 +13,7 @@ import ( · 12 unmodified lines
1313
1414 "code.gitea.io/gitea/models"
1515 asymkey_model "code.gitea.io/gitea/models/asymkey"
16+ git_model "code.gitea.io/gitea/models/git"
1617 perm_model "code.gitea.io/gitea/models/perm"
1718 access_model "code.gitea.io/gitea/models/perm/access"
1819 "code.gitea.io/gitea/models/unit"
@@ -40,7 +41,7 @@ type preReceiveContext struct { · 21 unmodified lines
4041 canWriteCode bool
4142 checkedCanWriteCode bool
4243
43− protectedTags []*models.ProtectedTag
44+ protectedTags []*git_model.ProtectedTag
4445 gotProtectedTags bool
4546
4647 env []string
@@ -155,7 +156,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID, refFullN · 108 unmodified lines
155156 return
156157 }
157158
158− protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName)
159+ protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, branchName)
159160 if err != nil {
160161 log.Error("Unable to get protected branch: %s in %-v Error: %v", branchName, repo, err)
161162 ctx.JSON(http.StatusInternalServerError, private.Response{
@@ -370,7 +371,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName · 208 unmodified lines
370371
371372 if !ctx.gotProtectedTags {
372373 var err error
373− ctx.protectedTags, err = models.GetProtectedTags(ctx.Repo.Repository.ID)
374+ ctx.protectedTags, err = git_model.GetProtectedTags(ctx.Repo.Repository.ID)
374375 if err != nil {
375376 log.Error("Unable to get protected tags for %-v Error: %v", ctx.Repo.Repository, err)
376377 ctx.JSON(http.StatusInternalServerError, private.Response{
@@ -381,7 +382,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName · 4 unmodified lines
381382 ctx.gotProtectedTags = true
382383 }
383384
384− isAllowed, err := models.IsUserAllowedToControlTag(ctx.protectedTags, tagName, ctx.opts.UserID)
385+ isAllowed, err := git_model.IsUserAllowedToControlTag(ctx.protectedTags, tagName, ctx.opts.UserID)
385386 if err != nil {
386387 ctx.JSON(http.StatusInternalServerError, private.Response{
387388 Err: err.Error(),
routers/web/repo/branch.go+6−5
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313
1414 "code.gitea.io/gitea/models"
15+ git_model "code.gitea.io/gitea/models/git"
1516 repo_model "code.gitea.io/gitea/models/repo"
1617 "code.gitea.io/gitea/models/unit"
1718 "code.gitea.io/gitea/modules/base"
@@ -40,7 +41,7 @@ type Branch struct { · 22 unmodified lines
4041 IsProtected bool
4142 IsDeleted bool
4243 IsIncluded bool
43− DeletedBranch *models.DeletedBranch
44+ DeletedBranch *git_model.DeletedBranch
4445 CommitsAhead int
4546 CommitsBehind int
4647 LatestPullRequest *models.PullRequest
@@ -119,7 +120,7 @@ func RestoreBranchPost(ctx *context.Context) { · 72 unmodified lines
119120 branchID := ctx.FormInt64("branch_id")
120121 branchName := ctx.FormString("name")
121122
122− deletedBranch, err := models.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID)
123+ deletedBranch, err := git_model.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID)
123124 if err != nil {
124125 log.Error("GetDeletedBranchByID: %v", err)
125126 ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
@@ -184,7 +185,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in · 58 unmodified lines
184185 return nil, nil, 0
185186 }
186187
187− protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID)
188+ protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID)
188189 if err != nil {
189190 ctx.ServerError("GetProtectedBranches", err)
190191 return nil, nil, 0
@@ -231,7 +232,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in · 40 unmodified lines
231232 return defaultBranchBranch, branches, totalNumOfBranches
232233 }
233234
234−func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, protectedBranches []*models.ProtectedBranch,
235+func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, protectedBranches []*git_model.ProtectedBranch,
235236 repoIDToRepo map[int64]*repo_model.Repository,
236237 repoIDToGitRepo map[int64]*git.Repository,
237238 ) *Branch {
@@ -326,7 +327,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p · 88 unmodified lines
326327 func getDeletedBranches(ctx *context.Context) ([]*Branch, error) {
327328 branches := []*Branch{}
328329
329− deletedBranches, err := models.GetDeletedBranches(ctx.Repo.Repository.ID)
330+ deletedBranches, err := git_model.GetDeletedBranches(ctx.Repo.Repository.ID)
330331 if err != nil {
331332 return branches, err
332333 }
routers/web/repo/commit.go+8−7
@@ -11,9 +11,10 @@ import ( · 10 unmodified lines
1111 "net/http"
1212 "strings"
1313
14− "code.gitea.io/gitea/models"
1514 asymkey_model "code.gitea.io/gitea/models/asymkey"
1615 "code.gitea.io/gitea/models/db"
16+ git_model "code.gitea.io/gitea/models/git"
17+ repo_model "code.gitea.io/gitea/models/repo"
1718 user_model "code.gitea.io/gitea/models/user"
1819 "code.gitea.io/gitea/modules/base"
1920 "code.gitea.io/gitea/modules/charset"
@@ -75,7 +76,7 @@ func Commits(ctx *context.Context) { · 55 unmodified lines
7576 ctx.ServerError("CommitsByRange", err)
7677 return
7778 }
78− ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
79+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
7980
8081 ctx.Data["Username"] = ctx.Repo.Owner.Name
8182 ctx.Data["Reponame"] = ctx.Repo.Repository.Name
@@ -194,7 +195,7 @@ func SearchCommits(ctx *context.Context) { · 112 unmodified lines
194195 return
195196 }
196197 ctx.Data["CommitCount"] = len(commits)
197− ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
198+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
198199
199200 ctx.Data["Keyword"] = query
200201 if all {
@@ -235,7 +236,7 @@ func FileHistory(ctx *context.Context) { · 34 unmodified lines
235236 ctx.ServerError("CommitsByFileAndRange", err)
236237 return
237238 }
238− ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
239+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
239240
240241 ctx.Data["Username"] = ctx.Repo.Owner.Name
241242 ctx.Data["Reponame"] = ctx.Repo.Repository.Name
@@ -335,12 +336,12 @@ func Diff(ctx *context.Context) { · 93 unmodified lines
335336 ctx.Data["Commit"] = commit
336337 ctx.Data["Diff"] = diff
337338
338− statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{})
339+ statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{})
339340 if err != nil {
340341 log.Error("GetLatestCommitStatus: %v", err)
341342 }
342343
343− ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
344+ ctx.Data["CommitStatus"] = git_model.CalcCommitStatus(statuses)
344345 ctx.Data["CommitStatuses"] = statuses
345346
346347 verification := asymkey_model.ParseCommitWithSignature(commit)
@@ -350,7 +351,7 @@ func Diff(ctx *context.Context) { · 3 unmodified lines
350351 ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
351352
352353 if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
353− return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
354+ return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
354355 }, nil); err != nil {
355356 ctx.ServerError("CalculateTrustStatus", err)
356357 return
routers/web/repo/compare.go+2−1
@@ -18,6 +18,7 @@ import ( · 17 unmodified lines
1818 "strings"
1919
2020 "code.gitea.io/gitea/models"
21+ git_model "code.gitea.io/gitea/models/git"
2122 access_model "code.gitea.io/gitea/models/perm/access"
2223 repo_model "code.gitea.io/gitea/models/repo"
2324 "code.gitea.io/gitea/models/unit"
@@ -636,7 +637,7 @@ func PrepareCompareDiff( · 612 unmodified lines
636637 return false
637638 }
638639
639− commits := models.ConvertFromGitCommit(ci.CompareInfo.Commits, ci.HeadRepo)
640+ commits := git_model.ConvertFromGitCommit(ci.CompareInfo.Commits, ci.HeadRepo)
640641 ctx.Data["Commits"] = commits
641642 ctx.Data["CommitCount"] = len(commits)
642643
routers/web/repo/download.go+2−2
@@ -9,7 +9,7 @@ import ( · 8 unmodified lines
99 "path"
1010 "time"
1111
12− "code.gitea.io/gitea/models"
12+ git_model "code.gitea.io/gitea/models/git"
1313 "code.gitea.io/gitea/modules/cache"
1414 "code.gitea.io/gitea/modules/context"
1515 "code.gitea.io/gitea/modules/git"
@@ -43,7 +43,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified time.Time · 27 unmodified lines
4343
4444 pointer, _ := lfs.ReadPointer(dataRc)
4545 if pointer.IsValid() {
46− meta, _ := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
46+ meta, _ := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
4747 if meta == nil {
4848 if err = dataRc.Close(); err != nil {
4949 log.Error("ServeBlobOrLFS: Close: %v", err)
routers/web/repo/editor.go+5−4
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313
1414 "code.gitea.io/gitea/models"
15+ git_model "code.gitea.io/gitea/models/git"
1516 "code.gitea.io/gitea/models/unit"
1617 "code.gitea.io/gitea/modules/base"
1718 "code.gitea.io/gitea/modules/charset"
@@ -253,9 +254,9 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b · 235 unmodified lines
253254 // This is where we handle all the errors thrown by files_service.CreateOrUpdateRepoFile
254255 if git.IsErrNotExist(err) {
255256 ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", ctx.Repo.TreePath), tplEditFile, &form)
256− } else if models.IsErrLFSFileLocked(err) {
257+ } else if git_model.IsErrLFSFileLocked(err) {
257258 ctx.Data["Err_TreePath"] = true
258− ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName), tplEditFile, &form)
259+ ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(git_model.ErrLFSFileLocked).Path, err.(git_model.ErrLFSFileLocked).UserName), tplEditFile, &form)
259260 } else if models.IsErrFilenameInvalid(err) {
260261 ctx.Data["Err_TreePath"] = true
261262 ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath), tplEditFile, &form)
@@ -660,9 +661,9 @@ func UploadFilePost(ctx *context.Context) { · 398 unmodified lines
660661 Files: form.Files,
661662 Signoff: form.Signoff,
662663 }); err != nil {
663− if models.IsErrLFSFileLocked(err) {
664+ if git_model.IsErrLFSFileLocked(err) {
664665 ctx.Data["Err_TreePath"] = true
665− ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName), tplUploadFile, &form)
666+ ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(git_model.ErrLFSFileLocked).Path, err.(git_model.ErrLFSFileLocked).UserName), tplUploadFile, &form)
666667 } else if models.IsErrFilenameInvalid(err) {
667668 ctx.Data["Err_TreePath"] = true
668669 ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath), tplUploadFile, &form)
routers/web/repo/issue.go+7−6
@@ -21,6 +21,7 @@ import ( · 20 unmodified lines
2121
2222 "code.gitea.io/gitea/models"
2323 "code.gitea.io/gitea/models/db"
24+ git_model "code.gitea.io/gitea/models/git"
2425 issues_model "code.gitea.io/gitea/models/issues"
2526 "code.gitea.io/gitea/models/organization"
2627 access_model "code.gitea.io/gitea/models/perm/access"
@@ -1536,7 +1537,7 @@ func ViewIssue(ctx *context.Context) { · 1509 unmodified lines
15361537 if perm.CanWrite(unit.TypeCode) {
15371538 // Check if branch is not protected
15381539 if pull.HeadBranch != pull.HeadRepo.DefaultBranch {
1539− if protected, err := models.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil {
1540+ if protected, err := git_model.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil {
15401541 log.Error("IsProtectedBranch: %v", err)
15411542 } else if !protected {
15421543 canDelete = true
@@ -1620,11 +1621,11 @@ func ViewIssue(ctx *context.Context) { · 77 unmodified lines
16201621 if ctx.Doer != nil {
16211622 showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.Doer.ID)
16221623 }
1623− ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(ctx, pull)
1624− ctx.Data["IsBlockedByRejection"] = pull.ProtectedBranch.MergeBlockedByRejectedReview(ctx, pull)
1625− ctx.Data["IsBlockedByOfficialReviewRequests"] = pull.ProtectedBranch.MergeBlockedByOfficialReviewRequests(ctx, pull)
1626− ctx.Data["IsBlockedByOutdatedBranch"] = pull.ProtectedBranch.MergeBlockedByOutdatedBranch(pull)
1627− ctx.Data["GrantedApprovals"] = pull.ProtectedBranch.GetGrantedApprovalsCount(ctx, pull)
1624+ ctx.Data["IsBlockedByApprovals"] = !models.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull)
1625+ ctx.Data["IsBlockedByRejection"] = models.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull)
1626+ ctx.Data["IsBlockedByOfficialReviewRequests"] = models.MergeBlockedByOfficialReviewRequests(ctx, pull.ProtectedBranch, pull)
1627+ ctx.Data["IsBlockedByOutdatedBranch"] = models.MergeBlockedByOutdatedBranch(pull.ProtectedBranch, pull)
1628+ ctx.Data["GrantedApprovals"] = models.GetGrantedApprovalsCount(ctx, pull.ProtectedBranch, pull)
16281629 ctx.Data["RequireSigned"] = pull.ProtectedBranch.RequireSignedCommits
16291630 ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles
16301631 ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0
routers/web/repo/lfs.go+18−18
@@ -15,7 +15,7 @@ import ( · 14 unmodified lines
1515 "strconv"
1616 "strings"
1717
18− "code.gitea.io/gitea/models"
18+ git_model "code.gitea.io/gitea/models/git"
1919 "code.gitea.io/gitea/modules/base"
2020 "code.gitea.io/gitea/modules/charset"
2121 "code.gitea.io/gitea/modules/context"
@@ -48,7 +48,7 @@ func LFSFiles(ctx *context.Context) { · 26 unmodified lines
4848 if page <= 1 {
4949 page = 1
5050 }
51− total, err := models.CountLFSMetaObjects(ctx.Repo.Repository.ID)
51+ total, err := git_model.CountLFSMetaObjects(ctx.Repo.Repository.ID)
5252 if err != nil {
5353 ctx.ServerError("LFSFiles", err)
5454 return
@@ -58,7 +58,7 @@ func LFSFiles(ctx *context.Context) { · 3 unmodified lines
5858 pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5)
5959 ctx.Data["Title"] = ctx.Tr("repo.settings.lfs")
6060 ctx.Data["PageIsSettingsLFS"] = true
61− lfsMetaObjects, err := models.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
61+ lfsMetaObjects, err := git_model.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
6262 if err != nil {
6363 ctx.ServerError("LFSFiles", err)
6464 return
@@ -80,7 +80,7 @@ func LFSLocks(ctx *context.Context) { · 15 unmodified lines
8080 if page <= 1 {
8181 page = 1
8282 }
83− total, err := models.CountLFSLockByRepoID(ctx.Repo.Repository.ID)
83+ total, err := git_model.CountLFSLockByRepoID(ctx.Repo.Repository.ID)
8484 if err != nil {
8585 ctx.ServerError("LFSLocks", err)
8686 return
@@ -90,7 +90,7 @@ func LFSLocks(ctx *context.Context) { · 3 unmodified lines
9090 pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5)
9191 ctx.Data["Title"] = ctx.Tr("repo.settings.lfs_locks")
9292 ctx.Data["PageIsSettingsLFS"] = true
93− lfsLocks, err := models.GetLFSLockByRepoID(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
93+ lfsLocks, err := git_model.GetLFSLockByRepoID(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
9494 if err != nil {
9595 ctx.ServerError("LFSLocks", err)
9696 return
@@ -216,12 +216,12 @@ func LFSLockFile(ctx *context.Context) { · 119 unmodified lines
216216 return
217217 }
218218
219− _, err := models.CreateLFSLock(ctx.Repo.Repository, &models.LFSLock{
219+ _, err := git_model.CreateLFSLock(ctx.Repo.Repository, &git_model.LFSLock{
220220 Path: lockPath,
221221 OwnerID: ctx.Doer.ID,
222222 })
223223 if err != nil {
224− if models.IsErrLFSLockAlreadyExist(err) {
224+ if git_model.IsErrLFSLockAlreadyExist(err) {
225225 ctx.Flash.Error(ctx.Tr("repo.settings.lfs_lock_already_exists", originalPath))
226226 ctx.Redirect(ctx.Repo.RepoLink + "/settings/lfs/locks")
227227 return
@@ -238,7 +238,7 @@ func LFSUnlock(ctx *context.Context) { · 10 unmodified lines
238238 ctx.NotFound("LFSUnlock", nil)
239239 return
240240 }
241− _, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
241+ _, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
242242 if err != nil {
243243 ctx.ServerError("LFSUnlock", err)
244244 return
@@ -263,9 +263,9 @@ func LFSFileGet(ctx *context.Context) { · 18 unmodified lines
263263
264264 ctx.Data["Title"] = oid
265265 ctx.Data["PageIsSettingsLFS"] = true
266− meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
266+ meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
267267 if err != nil {
268− if err == models.ErrLFSObjectNotExist {
268+ if err == git_model.ErrLFSObjectNotExist {
269269 ctx.NotFound("LFSFileGet", nil)
270270 return
271271 }
@@ -357,7 +357,7 @@ func LFSDelete(ctx *context.Context) { · 85 unmodified lines
357357 return
358358 }
359359
360− count, err := models.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
360+ count, err := git_model.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
361361 if err != nil {
362362 ctx.ServerError("LFSDelete", err)
363363 return
@@ -456,8 +456,8 @@ func LFSPointerFiles(ctx *context.Context) { · 92 unmodified lines
456456 Size: pointerBlob.Size,
457457 }
458458
459− if _, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil {
460− if err != models.ErrLFSObjectNotExist {
459+ if _, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil {
460+ if err != git_model.ErrLFSObjectNotExist {
461461 return err
462462 }
463463 } else {
@@ -474,12 +474,12 @@ func LFSPointerFiles(ctx *context.Context) { · 10 unmodified lines
474474 // Can we fix?
475475 // OK well that's "simple"
476476 // - we need to check whether current user has access to a repo that has access to the file
477− result.Associatable, err = models.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid)
477+ result.Associatable, err = git_model.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid)
478478 if err != nil {
479479 return err
480480 }
481481 if !result.Associatable {
482− associated, err := models.LFSObjectIsAssociated(pointerBlob.Oid)
482+ associated, err := git_model.LFSObjectIsAssociated(pointerBlob.Oid)
483483 if err != nil {
484484 return err
485485 }
@@ -532,7 +532,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 46 unmodified lines
532532 return
533533 }
534534 oids := ctx.FormStrings("oid")
535− metas := make([]*models.LFSMetaObject, len(oids))
535+ metas := make([]*git_model.LFSMetaObject, len(oids))
536536 for i, oid := range oids {
537537 idx := strings.IndexRune(oid, ' ')
538538 if idx < 0 || idx+1 > len(oid) {
@@ -540,7 +540,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 1 unmodified line
540540 return
541541 }
542542 var err error
543− metas[i] = &models.LFSMetaObject{}
543+ metas[i] = &git_model.LFSMetaObject{}
544544 metas[i].Size, err = strconv.ParseInt(oid[idx+1:], 10, 64)
545545 if err != nil {
546546 ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %v", oid, err))
@@ -549,7 +549,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 2 unmodified lines
549549 metas[i].Oid = oid[:idx]
550550 // metas[i].RepositoryID = ctx.Repo.Repository.ID
551551 }
552− if err := models.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil {
552+ if err := git_model.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil {
553553 ctx.ServerError("LFSAutoAssociate", err)
554554 return
555555 }
routers/web/repo/pull.go+8−7
@@ -18,6 +18,7 @@ import ( · 17 unmodified lines
1818
1919 "code.gitea.io/gitea/models"
2020 "code.gitea.io/gitea/models/db"
21+ git_model "code.gitea.io/gitea/models/git"
2122 "code.gitea.io/gitea/models/organization"
2223 access_model "code.gitea.io/gitea/models/perm/access"
2324 pull_model "code.gitea.io/gitea/models/pull"
@@ -379,14 +380,14 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C · 355 unmodified lines
379380
380381 if len(compareInfo.Commits) != 0 {
381382 sha := compareInfo.Commits[0].ID.String()
382− commitStatuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{})
383+ commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{})
383384 if err != nil {
384385 ctx.ServerError("GetLatestCommitStatus", err)
385386 return nil
386387 }
387388 if len(commitStatuses) != 0 {
388389 ctx.Data["LatestCommitStatuses"] = commitStatuses
389− ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
390+ ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
390391 }
391392 }
392393
@@ -440,14 +441,14 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare · 47 unmodified lines
440441 ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
441442 return nil
442443 }
443− commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
444+ commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
444445 if err != nil {
445446 ctx.ServerError("GetLatestCommitStatus", err)
446447 return nil
447448 }
448449 if len(commitStatuses) > 0 {
449450 ctx.Data["LatestCommitStatuses"] = commitStatuses
450− ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
451+ ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
451452 }
452453
453454 compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
@@ -530,14 +531,14 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare · 76 unmodified lines
530531 return nil
531532 }
532533
533− commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
534+ commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
534535 if err != nil {
535536 ctx.ServerError("GetLatestCommitStatus", err)
536537 return nil
537538 }
538539 if len(commitStatuses) > 0 {
539540 ctx.Data["LatestCommitStatuses"] = commitStatuses
540− ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
541+ ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
541542 }
542543
543544 if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck {
@@ -629,7 +630,7 @@ func ViewPullCommits(ctx *context.Context) { · 85 unmodified lines
629630 ctx.Data["Username"] = ctx.Repo.Owner.Name
630631 ctx.Data["Reponame"] = ctx.Repo.Repository.Name
631632
632− commits := models.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository)
633+ commits := git_model.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository)
633634 ctx.Data["Commits"] = commits
634635 ctx.Data["CommitCount"] = len(commits)
635636
routers/web/repo/setting_protected_branch.go+9−9
@@ -10,7 +10,7 @@ import ( · 9 unmodified lines
1010 "strings"
1111 "time"
1212
13− "code.gitea.io/gitea/models"
13+ git_model "code.gitea.io/gitea/models/git"
1414 "code.gitea.io/gitea/models/organization"
1515 "code.gitea.io/gitea/models/perm"
1616 access_model "code.gitea.io/gitea/models/perm/access"
@@ -32,7 +32,7 @@ func ProtectedBranch(ctx *context.Context) { · 15 unmodified lines
3232 ctx.Data["Title"] = ctx.Tr("repo.settings")
3333 ctx.Data["PageIsSettingsBranches"] = true
3434
35− protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID)
35+ protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID)
3636 if err != nil {
3737 ctx.ServerError("GetProtectedBranches", err)
3838 return
@@ -111,7 +111,7 @@ func SettingsProtectedBranch(c *context.Context) { · 72 unmodified lines
111111 c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + branch
112112 c.Data["PageIsSettingsBranches"] = true
113113
114− protectBranch, err := models.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch)
114+ protectBranch, err := git_model.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch)
115115 if err != nil {
116116 if !git.IsErrBranchNotExist(err) {
117117 c.ServerError("GetProtectBranchOfRepoByName", err)
@@ -121,7 +121,7 @@ func SettingsProtectedBranch(c *context.Context) { · 3 unmodified lines
121121
122122 if protectBranch == nil {
123123 // No options found, create defaults.
124− protectBranch = &models.ProtectedBranch{
124+ protectBranch = &git_model.ProtectedBranch{
125125 BranchName: branch,
126126 }
127127 }
@@ -135,7 +135,7 @@ func SettingsProtectedBranch(c *context.Context) { · 7 unmodified lines
135135 c.Data["whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.WhitelistUserIDs), ",")
136136 c.Data["merge_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.MergeWhitelistUserIDs), ",")
137137 c.Data["approvals_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.ApprovalsWhitelistUserIDs), ",")
138− contexts, _ := models.FindRepoRecentCommitStatusContexts(c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts
138+ contexts, _ := git_model.FindRepoRecentCommitStatusContexts(c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts
139139 for _, ctx := range protectBranch.StatusCheckContexts {
140140 var found bool
141141 for i := range contexts {
@@ -184,7 +184,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 42 unmodified lines
184184 return
185185 }
186186
187− protectBranch, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch)
187+ protectBranch, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch)
188188 if err != nil {
189189 if !git.IsErrBranchNotExist(err) {
190190 ctx.ServerError("GetProtectBranchOfRepoByName", err)
@@ -195,7 +195,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 4 unmodified lines
195195 if f.Protected {
196196 if protectBranch == nil {
197197 // No options found, create defaults.
198− protectBranch = &models.ProtectedBranch{
198+ protectBranch = &git_model.ProtectedBranch{
199199 RepoID: ctx.Repo.Repository.ID,
200200 BranchName: branch,
201201 }
@@ -262,7 +262,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 60 unmodified lines
262262 protectBranch.UnprotectedFilePatterns = f.UnprotectedFilePatterns
263263 protectBranch.BlockOnOutdatedBranch = f.BlockOnOutdatedBranch
264264
265− err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
265+ err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
266266 UserIDs: whitelistUsers,
267267 TeamIDs: whitelistTeams,
268268 MergeUserIDs: mergeWhitelistUsers,
@@ -282,7 +282,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 13 unmodified lines
282282 ctx.Redirect(fmt.Sprintf("%s/settings/branches/%s", ctx.Repo.RepoLink, util.PathEscapeSegments(branch)))
283283 } else {
284284 if protectBranch != nil {
285− if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil {
285+ if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil {
286286 ctx.ServerError("DeleteProtectedBranch", err)
287287 return
288288 }
routers/web/repo/tag.go+8−8
@@ -9,7 +9,7 @@ import ( · 8 unmodified lines
99 "net/http"
1010 "strings"
1111
12− "code.gitea.io/gitea/models"
12+ git_model "code.gitea.io/gitea/models/git"
1313 "code.gitea.io/gitea/models/organization"
1414 "code.gitea.io/gitea/models/perm"
1515 access_model "code.gitea.io/gitea/models/perm/access"
@@ -43,7 +43,7 @@ func NewProtectedTagPost(ctx *context.Context) { · 27 unmodified lines
4343 repo := ctx.Repo.Repository
4444 form := web.GetForm(ctx).(*forms.ProtectTagForm)
4545
46− pt := &models.ProtectedTag{
46+ pt := &git_model.ProtectedTag{
4747 RepoID: repo.ID,
4848 NamePattern: strings.TrimSpace(form.NamePattern),
4949 }
@@ -55,7 +55,7 @@ func NewProtectedTagPost(ctx *context.Context) { · 5 unmodified lines
5555 pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ","))
5656 }
5757
58− if err := models.InsertProtectedTag(pt); err != nil {
58+ if err := git_model.InsertProtectedTag(pt); err != nil {
5959 ctx.ServerError("InsertProtectedTag", err)
6060 return
6161 }
@@ -108,7 +108,7 @@ func EditProtectedTagPost(ctx *context.Context) { · 46 unmodified lines
108108 pt.AllowlistUserIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistUsers, ","))
109109 pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ","))
110110
111− if err := models.UpdateProtectedTag(pt); err != nil {
111+ if err := git_model.UpdateProtectedTag(pt); err != nil {
112112 ctx.ServerError("UpdateProtectedTag", err)
113113 return
114114 }
@@ -124,7 +124,7 @@ func DeleteProtectedTagPost(ctx *context.Context) { · 9 unmodified lines
124124 return
125125 }
126126
127− if err := models.DeleteProtectedTag(pt); err != nil {
127+ if err := git_model.DeleteProtectedTag(pt); err != nil {
128128 ctx.ServerError("DeleteProtectedTag", err)
129129 return
130130 }
@@ -137,7 +137,7 @@ func setTagsContext(ctx *context.Context) error { · 6 unmodified lines
137137 ctx.Data["Title"] = ctx.Tr("repo.settings")
138138 ctx.Data["PageIsSettingsTags"] = true
139139
140− protectedTags, err := models.GetProtectedTags(ctx.Repo.Repository.ID)
140+ protectedTags, err := git_model.GetProtectedTags(ctx.Repo.Repository.ID)
141141 if err != nil {
142142 ctx.ServerError("GetProtectedTags", err)
143143 return err
@@ -163,13 +163,13 @@ func setTagsContext(ctx *context.Context) error { · 19 unmodified lines
163163 return nil
164164 }
165165
166−func selectProtectedTagByContext(ctx *context.Context) *models.ProtectedTag {
166+func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag {
167167 id := ctx.FormInt64("id")
168168 if id == 0 {
169169 id = ctx.ParamsInt64(":id")
170170 }
171171
172− tag, err := models.GetProtectedTagByID(id)
172+ tag, err := git_model.GetProtectedTagByID(id)
173173 if err != nil {
174174 ctx.ServerError("GetProtectedTagByID", err)
175175 return nil
routers/web/repo/view.go+13−12
@@ -22,6 +22,7 @@ import ( · 21 unmodified lines
2222 "code.gitea.io/gitea/models"
2323 asymkey_model "code.gitea.io/gitea/models/asymkey"
2424 "code.gitea.io/gitea/models/db"
25+ git_model "code.gitea.io/gitea/models/git"
2526 repo_model "code.gitea.io/gitea/models/repo"
2627 unit_model "code.gitea.io/gitea/models/unit"
2728 user_model "code.gitea.io/gitea/models/user"
@@ -294,8 +295,8 @@ func renderReadmeFile(ctx *context.Context, readmeFile *namedBlob, readmeTreelin · 266 unmodified lines
294295 if isTextFile && setting.LFS.StartServer {
295296 pointer, _ := lfs.ReadPointerFromBuffer(buf)
296297 if pointer.IsValid() {
297− meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
298− if err != nil && err != models.ErrLFSObjectNotExist {
298+ meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
299+ if err != nil && err != git_model.ErrLFSObjectNotExist {
299300 ctx.ServerError("GetLFSMetaObject", err)
300301 return
301302 }
@@ -417,8 +418,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st · 115 unmodified lines
417418 if isTextFile && setting.LFS.StartServer {
418419 pointer, _ := lfs.ReadPointerFromBuffer(buf)
419420 if pointer.IsValid() {
420− meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
421− if err != nil && err != models.ErrLFSObjectNotExist {
421+ meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
422+ if err != nil && err != git_model.ErrLFSObjectNotExist {
422423 ctx.ServerError("GetLFSMetaObject", err)
423424 return
424425 }
@@ -466,7 +467,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st · 41 unmodified lines
466467 ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource
467468
468469 // Check LFS Lock
469− lfsLock, err := models.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath)
470+ lfsLock, err := git_model.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath)
470471 ctx.Data["LFSLock"] = lfsLock
471472 if err != nil {
472473 ctx.ServerError("GetTreePathLock", err)
@@ -842,7 +843,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri · 369 unmodified lines
842843 verification := asymkey_model.ParseCommitWithSignature(latestCommit)
843844
844845 if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
845− return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
846+ return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
846847 }, nil); err != nil {
847848 ctx.ServerError("CalculateTrustStatus", err)
848849 return nil
@@ -851,12 +852,12 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri · 2 unmodified lines
851852 ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit)
852853 }
853854
854− statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
855+ statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
855856 if err != nil {
856857 log.Error("GetLatestCommitStatus: %v", err)
857858 }
858859
859− ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses)
860+ ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(statuses)
860861 ctx.Data["LatestCommitStatuses"] = statuses
861862
862863 branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
@@ -991,12 +992,12 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOp · 128 unmodified lines
991992 if page <= 0 {
992993 page = 1
993994 }
994− pager := context.NewPagination(total, models.ItemsPerPage, page, 5)
995+ pager := context.NewPagination(total, setting.ItemsPerPage, page, 5)
995996 ctx.Data["Page"] = pager
996997
997998 items, err := getter(db.ListOptions{
998999 Page: pager.Paginater.Current(),
999− PageSize: models.ItemsPerPage,
1000+ PageSize: setting.ItemsPerPage,
10001001 })
10011002 if err != nil {
10021003 ctx.ServerError("getter", err)
@@ -1037,12 +1038,12 @@ func Forks(ctx *context.Context) { · 34 unmodified lines
10371038 page = 1
10381039 }
10391040
1040− pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5)
1041+ pager := context.NewPagination(ctx.Repo.Repository.NumForks, setting.ItemsPerPage, page, 5)
10411042 ctx.Data["Page"] = pager
10421043
10431044 forks, err := repo_model.GetForks(ctx.Repo.Repository, db.ListOptions{
10441045 Page: pager.Paginater.Current(),
1045− PageSize: models.ItemsPerPage,
1046+ PageSize: setting.ItemsPerPage,
10461047 })
10471048 if err != nil {
10481049 ctx.ServerError("GetForks", err)
routers/web/repo/wiki.go+2−1
@@ -16,6 +16,7 @@ import ( · 15 unmodified lines
1616 "time"
1717
1818 "code.gitea.io/gitea/models"
19+ git_model "code.gitea.io/gitea/models/git"
1920 "code.gitea.io/gitea/models/unit"
2021 "code.gitea.io/gitea/modules/base"
2122 "code.gitea.io/gitea/modules/charset"
@@ -350,7 +351,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) · 328 unmodified lines
350351 ctx.ServerError("CommitsByFileAndRangeNoFollow", err)
351352 return nil, nil
352353 }
353− ctx.Data["Commits"] = models.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository)
354+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository)
354355
355356 pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
356357 pager.SetDefaultParams(ctx)
services/asymkey/sign.go+3−2
@@ -13,6 +13,7 @@ import ( · 12 unmodified lines
1313 asymkey_model "code.gitea.io/gitea/models/asymkey"
1414 "code.gitea.io/gitea/models/auth"
1515 "code.gitea.io/gitea/models/db"
16+ git_model "code.gitea.io/gitea/models/git"
1617 user_model "code.gitea.io/gitea/models/user"
1718 "code.gitea.io/gitea/modules/git"
1819 "code.gitea.io/gitea/modules/log"
@@ -310,14 +311,14 @@ Loop: · 291 unmodified lines
310311 return false, "", nil, &ErrWontSign{twofa}
311312 }
312313 case approved:
313− protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, pr.BaseBranch)
314+ protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, pr.BaseBranch)
314315 if err != nil {
315316 return false, "", nil, err
316317 }
317318 if protectedBranch == nil {
318319 return false, "", nil, &ErrWontSign{approved}
319320 }
320− if protectedBranch.GetGrantedApprovalsCount(ctx, pr) < 1 {
321+ if models.GetGrantedApprovalsCount(ctx, protectedBranch, pr) < 1 {
321322 return false, "", nil, &ErrWontSign{approved}
322323 }
323324 case baseSigned:
services/cron/tasks_basic.go+2−1
@@ -9,6 +9,7 @@ import ( · 8 unmodified lines
99 "time"
1010
1111 "code.gitea.io/gitea/models"
12+ git_model "code.gitea.io/gitea/models/git"
1213 user_model "code.gitea.io/gitea/models/user"
1314 "code.gitea.io/gitea/models/webhook"
1415 "code.gitea.io/gitea/modules/setting"
@@ -109,7 +110,7 @@ func registerDeletedBranchesCleanup() { · 94 unmodified lines
109110 OlderThan: 24 * time.Hour,
110111 }, func(ctx context.Context, _ *user_model.User, config Config) error {
111112 realConfig := config.(*OlderThanConfig)
112− models.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
113+ git_model.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
113114 return nil
114115 })
115116 }
services/gitdiff/gitdiff.go+2−1
@@ -22,6 +22,7 @@ import ( · 21 unmodified lines
2222
2323 "code.gitea.io/gitea/models"
2424 "code.gitea.io/gitea/models/db"
25+ git_model "code.gitea.io/gitea/models/git"
2526 pull_model "code.gitea.io/gitea/models/pull"
2627 user_model "code.gitea.io/gitea/models/user"
2728 "code.gitea.io/gitea/modules/analyze"
@@ -1219,7 +1220,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 1191 unmodified lines
12191220 } else if curFileLFSPrefix && strings.HasPrefix(line[1:], lfs.MetaFileOidPrefix) {
12201221 oid := strings.TrimPrefix(line[1:], lfs.MetaFileOidPrefix)
12211222 if len(oid) == 64 {
1222− m := &models.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}}
1223+ m := &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}}
12231224 count, err := db.CountByBean(db.DefaultContext, m)
12241225
12251226 if err == nil && count > 0 {
services/lfs/locks.go+14−14
@@ -9,7 +9,7 @@ import ( · 8 unmodified lines
99 "strconv"
1010 "strings"
1111
12− "code.gitea.io/gitea/models"
12+ git_model "code.gitea.io/gitea/models/git"
1313 repo_model "code.gitea.io/gitea/models/repo"
1414 "code.gitea.io/gitea/modules/context"
1515 "code.gitea.io/gitea/modules/convert"
@@ -20,9 +20,9 @@ import ( · 4 unmodified lines
2020 api "code.gitea.io/gitea/modules/structs"
2121 )
2222
23−func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *models.LFSLock, err error) {
23+func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *git_model.LFSLock, err error) {
2424 if err != nil {
25− if models.IsErrLFSLockNotExist(err) {
25+ if git_model.IsErrLFSLockNotExist(err) {
2626 ctx.JSON(http.StatusOK, api.LFSLockList{
2727 Locks: []*api.LFSLock{},
2828 })
@@ -88,8 +88,8 @@ func GetListLockHandler(ctx *context.Context) { · 59 unmodified lines
8888 })
8989 return
9090 }
91− lock, err := models.GetLFSLockByID(ctx, v)
92− if err != nil && !models.IsErrLFSLockNotExist(err) {
91+ lock, err := git_model.GetLFSLockByID(ctx, v)
92+ if err != nil && !git_model.IsErrLFSLockNotExist(err) {
9393 log.Error("Unable to get lock with ID[%s]: Error: %v", v, err)
9494 }
9595 handleLockListOut(ctx, repository, lock, err)
@@ -98,8 +98,8 @@ func GetListLockHandler(ctx *context.Context) { · 2 unmodified lines
9898
9999 path := ctx.FormString("path")
100100 if path != "" { // Case where we request a specific id
101− lock, err := models.GetLFSLock(ctx, repository, path)
102− if err != nil && !models.IsErrLFSLockNotExist(err) {
101+ lock, err := git_model.GetLFSLock(ctx, repository, path)
102+ if err != nil && !git_model.IsErrLFSLockNotExist(err) {
103103 log.Error("Unable to get lock for repository %-v with path %s: Error: %v", repository, path, err)
104104 }
105105 handleLockListOut(ctx, repository, lock, err)
@@ -107,7 +107,7 @@ func GetListLockHandler(ctx *context.Context) { · 1 unmodified line
107107 }
108108
109109 // If no query params path or id
110− lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit)
110+ lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit)
111111 if err != nil {
112112 log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
113113 ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
@@ -168,19 +168,19 @@ func PostLockHandler(ctx *context.Context) { · 54 unmodified lines
168168 return
169169 }
170170
171− lock, err := models.CreateLFSLock(repository, &models.LFSLock{
171+ lock, err := git_model.CreateLFSLock(repository, &git_model.LFSLock{
172172 Path: req.Path,
173173 OwnerID: ctx.Doer.ID,
174174 })
175175 if err != nil {
176− if models.IsErrLFSLockAlreadyExist(err) {
176+ if git_model.IsErrLFSLockAlreadyExist(err) {
177177 ctx.JSON(http.StatusConflict, api.LFSLockError{
178178 Lock: convert.ToLFSLock(lock),
179179 Message: "already created lock",
180180 })
181181 return
182182 }
183− if models.IsErrLFSUnauthorizedAction(err) {
183+ if git_model.IsErrLFSUnauthorizedAction(err) {
184184 ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
185185 ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
186186 Message: "You must have push access to create locks : " + err.Error(),
@@ -234,7 +234,7 @@ func VerifyLockHandler(ctx *context.Context) { · 47 unmodified lines
234234 } else if limit < 0 {
235235 limit = 0
236236 }
237− lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit)
237+ lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit)
238238 if err != nil {
239239 log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
240240 ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
@@ -301,9 +301,9 @@ func UnLockHandler(ctx *context.Context) { · 60 unmodified lines
301301 return
302302 }
303303
304− lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force)
304+ lock, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force)
305305 if err != nil {
306− if models.IsErrLFSUnauthorizedAction(err) {
306+ if git_model.IsErrLFSUnauthorizedAction(err) {
307307 ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
308308 ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
309309 Message: "You must have push access to delete locks : " + err.Error(),
services/lfs/server.go+10−10
@@ -18,7 +18,7 @@ import ( · 17 unmodified lines
1818 "strconv"
1919 "strings"
2020
21− "code.gitea.io/gitea/models"
21+ git_model "code.gitea.io/gitea/models/git"
2222 "code.gitea.io/gitea/models/perm"
2323 access_model "code.gitea.io/gitea/models/perm/access"
2424 repo_model "code.gitea.io/gitea/models/repo"
@@ -197,8 +197,8 @@ func BatchHandler(ctx *context.Context) { · 172 unmodified lines
197197 return
198198 }
199199
200− meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid)
201− if err != nil && err != models.ErrLFSObjectNotExist {
200+ meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid)
201+ if err != nil && err != git_model.ErrLFSObjectNotExist {
202202 log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
203203 writeStatus(ctx, http.StatusInternalServerError)
204204 return
@@ -223,14 +223,14 @@ func BatchHandler(ctx *context.Context) { · 18 unmodified lines
223223 }
224224
225225 if exists && meta == nil {
226− accessible, err := models.LFSObjectAccessible(ctx.Doer, p.Oid)
226+ accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid)
227227 if err != nil {
228228 log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
229229 writeStatus(ctx, http.StatusInternalServerError)
230230 return
231231 }
232232 if accessible {
233− _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
233+ _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
234234 if err != nil {
235235 log.Error("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
236236 writeStatus(ctx, http.StatusInternalServerError)
@@ -297,7 +297,7 @@ func UploadHandler(ctx *context.Context) { · 60 unmodified lines
297297
298298 uploadOrVerify := func() error {
299299 if exists {
300− accessible, err := models.LFSObjectAccessible(ctx.Doer, p.Oid)
300+ accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid)
301301 if err != nil {
302302 log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
303303 return err
@@ -323,7 +323,7 @@ func UploadHandler(ctx *context.Context) { · 19 unmodified lines
323323 log.Error("Error putting LFS MetaObject [%s] into content store. Error: %v", p.Oid, err)
324324 return err
325325 }
326− _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
326+ _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
327327 return err
328328 }
329329
@@ -335,7 +335,7 @@ func UploadHandler(ctx *context.Context) { · 5 unmodified lines
335335 } else {
336336 writeStatus(ctx, http.StatusInternalServerError)
337337 }
338− if _, err = models.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil {
338+ if _, err = git_model.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil {
339339 log.Error("Error whilst removing metaobject for LFS OID[%s]: %v", p.Oid, err)
340340 }
341341 return
@@ -386,7 +386,7 @@ func getRequestContext(ctx *context.Context) *requestContext { · 44 unmodified lines
386386 }
387387 }
388388
389−func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module.Pointer, requireWrite bool) *models.LFSMetaObject {
389+func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module.Pointer, requireWrite bool) *git_model.LFSMetaObject {
390390 if !p.IsValid() {
391391 log.Info("Attempt to access invalid LFS OID[%s] in %s/%s", p.Oid, rc.User, rc.Repo)
392392 writeStatusMessage(ctx, http.StatusUnprocessableEntity, "Oid or size are invalid")
@@ -398,7 +398,7 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module · 5 unmodified lines
398398 return nil
399399 }
400400
401− meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid)
401+ meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid)
402402 if err != nil {
403403 log.Error("Unable to get LFS OID[%s] Error: %v", p.Oid, err)
404404 writeStatus(ctx, http.StatusNotFound)
services/pull/commit_status.go+7−6
@@ -10,6 +10,7 @@ import ( · 9 unmodified lines
1010
1111 "code.gitea.io/gitea/models"
1212 "code.gitea.io/gitea/models/db"
13+ git_model "code.gitea.io/gitea/models/git"
1314 "code.gitea.io/gitea/modules/git"
1415 "code.gitea.io/gitea/modules/structs"
1516
@@ -17,9 +18,9 @@ import ( · 1 unmodified line
1718 )
1819
1920 // MergeRequiredContextsCommitStatus returns a commit status state for given required contexts
20−func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, requiredContexts []string) structs.CommitStatusState {
21+func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus, requiredContexts []string) structs.CommitStatusState {
2122 if len(requiredContexts) == 0 {
22− status := models.CalcCommitStatus(commitStatuses)
23+ status := git_model.CalcCommitStatus(commitStatuses)
2324 if status != nil {
2425 return status.State
2526 }
@@ -38,7 +39,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, re · 12 unmodified lines
3839
3940 if targetStatus == "" {
4041 targetStatus = structs.CommitStatusPending
41− commitStatuses = append(commitStatuses, &models.CommitStatus{
42+ commitStatuses = append(commitStatuses, &git_model.CommitStatus{
4243 State: targetStatus,
4344 Context: ctx,
4445 Description: "Pending",
@@ -52,10 +53,10 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, re · 7 unmodified lines
5253 }
5354
5455 // IsCommitStatusContextSuccess returns true if all required status check contexts succeed.
55−func IsCommitStatusContextSuccess(commitStatuses []*models.CommitStatus, requiredContexts []string) bool {
56+func IsCommitStatusContextSuccess(commitStatuses []*git_model.CommitStatus, requiredContexts []string) bool {
5657 // If no specific context is required, require that last commit status is a success
5758 if len(requiredContexts) == 0 {
58− status := models.CalcCommitStatus(commitStatuses)
59+ status := git_model.CalcCommitStatus(commitStatuses)
5960 if status == nil || status.State != structs.CommitStatusSuccess {
6061 return false
6162 }
@@ -132,7 +133,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *models.PullRequest · 70 unmodified lines
132133 return "", errors.Wrap(err, "LoadBaseRepo")
133134 }
134135
135− commitStatuses, _, err := models.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptions{})
136+ commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptions{})
136137 if err != nil {
137138 return "", errors.Wrap(err, "GetLatestCommitStatus")
138139 }
services/pull/lfs.go+5−4
@@ -13,6 +13,7 @@ import ( · 12 unmodified lines
1313 "sync"
1414
1515 "code.gitea.io/gitea/models"
16+ git_model "code.gitea.io/gitea/models/git"
1617 "code.gitea.io/gitea/modules/git/pipeline"
1718 "code.gitea.io/gitea/modules/lfs"
1819 "code.gitea.io/gitea/modules/log"
@@ -115,8 +116,8 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg · 96 unmodified lines
115116 }
116117
117118 // Then we need to check that this pointer is in the db
118− if _, err := models.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil {
119− if err == models.ErrLFSObjectNotExist {
119+ if _, err := git_model.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil {
120+ if err == git_model.ErrLFSObjectNotExist {
120121 log.Warn("During merge of: %d in %-v, there is a pointer to LFS Oid: %s which although present in the LFS store is not associated with the head repo %-v", pr.Index, pr.BaseRepo, pointer.Oid, pr.HeadRepo)
121122 continue
122123 }
@@ -126,9 +127,9 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg · 3 unmodified lines
126127 // OK we have a pointer that is associated with the head repo
127128 // and is actually a file in the LFS
128129 // Therefore it should be associated with the base repo
129− meta := &models.LFSMetaObject{Pointer: pointer}
130+ meta := &git_model.LFSMetaObject{Pointer: pointer}
130131 meta.RepositoryID = pr.BaseRepoID
131− if _, err := models.NewLFSMetaObject(meta); err != nil {
132+ if _, err := git_model.NewLFSMetaObject(meta); err != nil {
132133 _ = catFileBatchReader.CloseWithError(err)
133134 break
134135 }
services/pull/merge.go+7−6
@@ -19,6 +19,7 @@ import ( · 18 unmodified lines
1919
2020 "code.gitea.io/gitea/models"
2121 "code.gitea.io/gitea/models/db"
22+ git_model "code.gitea.io/gitea/models/git"
2223 access_model "code.gitea.io/gitea/models/perm/access"
2324 pull_model "code.gitea.io/gitea/models/pull"
2425 repo_model "code.gitea.io/gitea/models/repo"
@@ -756,7 +757,7 @@ func IsUserAllowedToMerge(ctx context.Context, pr *models.PullRequest, p access_ · 731 unmodified lines
756757 return false, err
757758 }
758759
759− if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && models.IsUserMergeWhitelisted(ctx, pr.ProtectedBranch, user.ID, p)) {
760+ if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && git_model.IsUserMergeWhitelisted(ctx, pr.ProtectedBranch, user.ID, p)) {
760761 return true, nil
761762 }
762763
@@ -786,23 +787,23 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski · 23 unmodified lines
786787 }
787788 }
788789
789− if !pr.ProtectedBranch.HasEnoughApprovals(ctx, pr) {
790+ if !models.HasEnoughApprovals(ctx, pr.ProtectedBranch, pr) {
790791 return models.ErrDisallowedToMerge{
791792 Reason: "Does not have enough approvals",
792793 }
793794 }
794− if pr.ProtectedBranch.MergeBlockedByRejectedReview(ctx, pr) {
795+ if models.MergeBlockedByRejectedReview(ctx, pr.ProtectedBranch, pr) {
795796 return models.ErrDisallowedToMerge{
796797 Reason: "There are requested changes",
797798 }
798799 }
799− if pr.ProtectedBranch.MergeBlockedByOfficialReviewRequests(ctx, pr) {
800+ if models.MergeBlockedByOfficialReviewRequests(ctx, pr.ProtectedBranch, pr) {
800801 return models.ErrDisallowedToMerge{
801802 Reason: "There are official review requests",
802803 }
803804 }
804805
805− if pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr) {
806+ if models.MergeBlockedByOutdatedBranch(pr.ProtectedBranch, pr) {
806807 return models.ErrDisallowedToMerge{
807808 Reason: "The head branch is behind the base branch",
808809 }
@@ -812,7 +813,7 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski · 3 unmodified lines
812813 return nil
813814 }
814815
815− if pr.ProtectedBranch.MergeBlockedByProtectedFiles(pr) {
816+ if pr.ProtectedBranch.MergeBlockedByProtectedFiles(pr.ChangedProtectedFiles) {
816817 return models.ErrDisallowedToMerge{
817818 Reason: "Changed protected files",
818819 }
services/pull/pull.go+8−7
@@ -16,6 +16,7 @@ import ( · 15 unmodified lines
1616
1717 "code.gitea.io/gitea/models"
1818 "code.gitea.io/gitea/models/db"
19+ git_model "code.gitea.io/gitea/models/git"
1920 repo_model "code.gitea.io/gitea/models/repo"
2021 user_model "code.gitea.io/gitea/models/user"
2122 "code.gitea.io/gitea/modules/git"
@@ -735,13 +736,13 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s · 713 unmodified lines
735736 }
736737
737738 // GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status
738−func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*models.CommitStatus, error) {
739+func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*git_model.CommitStatus, error) {
739740 _, lastStatus, err := GetIssuesAllCommitStatus(ctx, issues)
740741 return lastStatus, err
741742 }
742743
743744 // GetIssuesAllCommitStatus returns a map of issue ID to a list of all statuses for the most recent commit as well as a map of issue ID to only the commit's latest status
744−func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*models.CommitStatus, map[int64]*models.CommitStatus, error) {
745+func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error) {
745746 if err := issues.LoadPullRequests(); err != nil {
746747 return nil, nil, err
747748 }
@@ -751,8 +752,8 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map · 3 unmodified lines
751752
752753 var (
753754 gitRepos = make(map[int64]*git.Repository)
754− res = make(map[int64][]*models.CommitStatus)
755− lastRes = make(map[int64]*models.CommitStatus)
755+ res = make(map[int64][]*git_model.CommitStatus)
756+ lastRes = make(map[int64]*git_model.CommitStatus)
756757 err error
757758 )
758759 defer func() {
@@ -787,14 +788,14 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map · 28 unmodified lines
787788 }
788789
789790 // getAllCommitStatus get pr's commit statuses.
790−func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*models.CommitStatus, lastStatus *models.CommitStatus, err error) {
791+func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) {
791792 sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitRefName())
792793 if shaErr != nil {
793794 return nil, nil, shaErr
794795 }
795796
796− statuses, _, err = models.GetLatestCommitStatus(db.DefaultContext, pr.BaseRepo.ID, sha, db.ListOptions{})
797− lastStatus = models.CalcCommitStatus(statuses)
797+ statuses, _, err = git_model.GetLatestCommitStatus(db.DefaultContext, pr.BaseRepo.ID, sha, db.ListOptions{})
798+ lastStatus = git_model.CalcCommitStatus(statuses)
798799 return statuses, lastStatus, err
799800 }
800801
services/release/release.go+3−2
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212
1313 "code.gitea.io/gitea/models"
1414 "code.gitea.io/gitea/models/db"
15+ git_model "code.gitea.io/gitea/models/git"
1516 repo_model "code.gitea.io/gitea/models/repo"
1617 user_model "code.gitea.io/gitea/models/user"
1718 "code.gitea.io/gitea/modules/git"
@@ -32,11 +33,11 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool, · 14 unmodified lines
3233 return false, err
3334 }
3435
35− protectedTags, err := models.GetProtectedTags(rel.Repo.ID)
36+ protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID)
3637 if err != nil {
3738 return false, fmt.Errorf("GetProtectedTags: %v", err)
3839 }
39− isAllowed, err := models.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
40+ isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
4041 if err != nil {
4142 return false, err
4243 }
services/repository/branch.go+4−3
@@ -11,6 +11,7 @@ import ( · 10 unmodified lines
1111 "strings"
1212
1313 "code.gitea.io/gitea/models"
14+ git_model "code.gitea.io/gitea/models/git"
1415 repo_model "code.gitea.io/gitea/models/repo"
1516 user_model "code.gitea.io/gitea/models/user"
1617 "code.gitea.io/gitea/modules/git"
@@ -118,7 +119,7 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g · 101 unmodified lines
118119 return "from_not_exist", nil
119120 }
120121
121− if err := models.RenameBranch(repo, from, to, func(isDefault bool) error {
122+ if err := git_model.RenameBranch(repo, from, to, func(isDefault bool) error {
122123 err2 := gitRepo.RenameBranch(from, to)
123124 if err2 != nil {
124125 return err2
@@ -158,7 +159,7 @@ func DeleteBranch(doer *user_model.User, repo *repo_model.Repository, gitRepo *g · 33 unmodified lines
158159 return ErrBranchIsDefault
159160 }
160161
161− isProtected, err := models.IsProtectedBranch(repo.ID, branchName)
162+ isProtected, err := git_model.IsProtectedBranch(repo.ID, branchName)
162163 if err != nil {
163164 return err
164165 }
@@ -196,7 +197,7 @@ func DeleteBranch(doer *user_model.User, repo *repo_model.Repository, gitRepo *g · 31 unmodified lines
196197 log.Error("Update: %v", err)
197198 }
198199
199− if err := models.AddDeletedBranch(repo.ID, branchName, commit.ID.String(), doer.ID); err != nil {
200+ if err := git_model.AddDeletedBranch(repo.ID, branchName, commit.ID.String(), doer.ID); err != nil {
200201 log.Warn("AddDeletedBranch: %v", err)
201202 }
202203
services/repository/files/commit.go+3−3
@@ -8,8 +8,8 @@ import ( · 7 unmodified lines
88 "context"
99 "fmt"
1010
11− "code.gitea.io/gitea/models"
1211 asymkey_model "code.gitea.io/gitea/models/asymkey"
12+ git_model "code.gitea.io/gitea/models/git"
1313 repo_model "code.gitea.io/gitea/models/repo"
1414 user_model "code.gitea.io/gitea/models/user"
1515 "code.gitea.io/gitea/modules/git"
@@ -20,7 +20,7 @@ import ( · 4 unmodified lines
2020 // CreateCommitStatus creates a new CommitStatus given a bunch of parameters
2121 // NOTE: All text-values will be trimmed from whitespaces.
2222 // Requires: Repo, Creator, SHA
23−func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
23+func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creator *user_model.User, sha string, status *git_model.CommitStatus) error {
2424 repoPath := repo.RepoPath()
2525
2626 // confirm that commit is exist
@@ -36,7 +36,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato · 9 unmodified lines
3636 }
3737 gitRepo.Close()
3838
39− if err := models.NewCommitStatus(models.NewCommitStatusOptions{
39+ if err := git_model.NewCommitStatus(git_model.NewCommitStatusOptions{
4040 Repo: repo,
4141 Creator: creator,
4242 SHA: sha,
services/repository/files/patch.go+2−1
@@ -10,6 +10,7 @@ import ( · 9 unmodified lines
1010 "strings"
1111
1212 "code.gitea.io/gitea/models"
13+ git_model "code.gitea.io/gitea/models/git"
1314 repo_model "code.gitea.io/gitea/models/repo"
1415 user_model "code.gitea.io/gitea/models/user"
1516 "code.gitea.io/gitea/modules/git"
@@ -66,7 +67,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode · 50 unmodified lines
6667 return err
6768 }
6869 } else {
69− protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch)
70+ protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch)
7071 if err != nil {
7172 return err
7273 }
services/repository/files/update.go+8−7
@@ -13,6 +13,7 @@ import ( · 12 unmodified lines
1313 "time"
1414
1515 "code.gitea.io/gitea/models"
16+ git_model "code.gitea.io/gitea/models/git"
1617 repo_model "code.gitea.io/gitea/models/repo"
1718 user_model "code.gitea.io/gitea/models/user"
1819 "code.gitea.io/gitea/modules/charset"
@@ -75,8 +76,8 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *repo_model.Repository) (st · 56 unmodified lines
7576 if setting.LFS.StartServer {
7677 pointer, _ := lfs.ReadPointerFromBuffer(buf)
7778 if pointer.IsValid() {
78− meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointer.Oid)
79− if err != nil && err != models.ErrLFSObjectNotExist {
79+ meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointer.Oid)
80+ if err != nil && err != git_model.ErrLFSObjectNotExist {
8081 // return default
8182 return "UTF-8", false
8283 }
@@ -364,7 +365,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 281 unmodified lines
364365 }
365366 // Reset the opts.Content to our adjusted content to ensure that LFS gets the correct content
366367 opts.Content = content
367− var lfsMetaObject *models.LFSMetaObject
368+ var lfsMetaObject *git_model.LFSMetaObject
368369
369370 if setting.LFS.StartServer && hasOldBranch {
370371 // Check there is no way this can return multiple infos
@@ -383,7 +384,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 12 unmodified lines
383384 if err != nil {
384385 return nil, err
385386 }
386− lfsMetaObject = &models.LFSMetaObject{Pointer: pointer, RepositoryID: repo.ID}
387+ lfsMetaObject = &git_model.LFSMetaObject{Pointer: pointer, RepositoryID: repo.ID}
387388 content = pointer.StringContent()
388389 }
389390 }
@@ -423,7 +424,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 33 unmodified lines
423424
424425 if lfsMetaObject != nil {
425426 // We have an LFS object - create it
426− lfsMetaObject, err = models.NewLFSMetaObject(lfsMetaObject)
427+ lfsMetaObject, err = git_model.NewLFSMetaObject(lfsMetaObject)
427428 if err != nil {
428429 return nil, err
429430 }
@@ -434,7 +435,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 4 unmodified lines
434435 }
435436 if !exist {
436437 if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil {
437− if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil {
438+ if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil {
438439 return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err)
439440 }
440441 return nil, err
@@ -462,7 +463,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 21 unmodified lines
462463
463464 // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch
464465 func VerifyBranchProtection(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, branchName, treePath string) error {
465− protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName)
466+ protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, branchName)
466467 if err != nil {
467468 return err
468469 }
services/repository/files/upload.go+7−6
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212 "strings"
1313
1414 "code.gitea.io/gitea/models"
15+ git_model "code.gitea.io/gitea/models/git"
1516 repo_model "code.gitea.io/gitea/models/repo"
1617 user_model "code.gitea.io/gitea/models/user"
1718 "code.gitea.io/gitea/modules/git"
@@ -32,7 +33,7 @@ type UploadRepoFileOptions struct { · 14 unmodified lines
3233
3334 type uploadInfo struct {
3435 upload *models.Upload
35− lfsMetaObject *models.LFSMetaObject
36+ lfsMetaObject *git_model.LFSMetaObject
3637 }
3738
3839 func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, original error) error {
@@ -41,7 +42,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig · 2 unmodified lines
4142 continue
4243 }
4344 if !info.lfsMetaObject.Existing {
44− if _, err := models.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil {
45+ if _, err := git_model.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil {
4546 original = fmt.Errorf("%v, %v", original, err)
4647 }
4748 }
@@ -65,7 +66,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 17 unmodified lines
6566 for i, upload := range uploads {
6667 // Check file is not lfs locked, will return nil if lock setting not enabled
6768 filepath := path.Join(opts.TreePath, upload.Name)
68− lfsLock, err := models.GetTreePathLock(repo.ID, filepath)
69+ lfsLock, err := git_model.GetTreePathLock(repo.ID, filepath)
6970 if err != nil {
7071 return err
7172 }
@@ -74,7 +75,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 2 unmodified lines
7475 if err != nil {
7576 return err
7677 }
77− return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name}
78+ return git_model.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name}
7879 }
7980
8081 names[i] = upload.Name
@@ -133,7 +134,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 52 unmodified lines
133134 if infos[i].lfsMetaObject == nil {
134135 continue
135136 }
136− infos[i].lfsMetaObject, err = models.NewLFSMetaObject(infos[i].lfsMetaObject)
137+ infos[i].lfsMetaObject, err = git_model.NewLFSMetaObject(infos[i].lfsMetaObject)
137138 if err != nil {
138139 // OK Now we need to cleanup
139140 return cleanUpAfterFailure(&infos, t, err)
@@ -175,7 +176,7 @@ func copyUploadedLFSFileIntoRepository(info *uploadInfo, filename2attribute2info · 35 unmodified lines
175176 return err
176177 }
177178
178− info.lfsMetaObject = &models.LFSMetaObject{Pointer: pointer, RepositoryID: t.repo.ID}
179+ info.lfsMetaObject = &git_model.LFSMetaObject{Pointer: pointer, RepositoryID: t.repo.ID}
179180
180181 if objectHash, err = t.HashObject(strings.NewReader(pointer.StringContent())); err != nil {
181182 return err
services/repository/fork.go+2−1
@@ -12,6 +12,7 @@ import ( · 11 unmodified lines
1212
1313 "code.gitea.io/gitea/models"
1414 "code.gitea.io/gitea/models/db"
15+ git_model "code.gitea.io/gitea/models/git"
1516 repo_model "code.gitea.io/gitea/models/repo"
1617 user_model "code.gitea.io/gitea/models/user"
1718 "code.gitea.io/gitea/modules/git"
@@ -101,7 +102,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork · 83 unmodified lines
101102 }
102103
103104 // copy lfs files failure should not be ignored
104− if err = models.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil {
105+ if err = git_model.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil {
105106 return err
106107 }
107108
services/repository/push.go+2−1
@@ -13,6 +13,7 @@ import ( · 12 unmodified lines
1313
1414 "code.gitea.io/gitea/models"
1515 "code.gitea.io/gitea/models/db"
16+ git_model "code.gitea.io/gitea/models/git"
1617 repo_model "code.gitea.io/gitea/models/repo"
1718 user_model "code.gitea.io/gitea/models/user"
1819 "code.gitea.io/gitea/modules/cache"
@@ -252,7 +253,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { · 233 unmodified lines
252253
253254 notification.NotifyPushCommits(pusher, repo, opts, commits)
254255
255− if err = models.RemoveDeletedBranchByName(repo.ID, branch); err != nil {
256+ if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil {
256257 log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err)
257258 }
258259