diff options
Diffstat (limited to 'services/repository/files')
-rw-r--r-- | services/repository/files/commit.go | 5 | ||||
-rw-r--r-- | services/repository/files/content.go | 7 | ||||
-rw-r--r-- | services/repository/files/delete.go | 3 | ||||
-rw-r--r-- | services/repository/files/diff.go | 4 | ||||
-rw-r--r-- | services/repository/files/diff_test.go | 4 | ||||
-rw-r--r-- | services/repository/files/file.go | 6 | ||||
-rw-r--r-- | services/repository/files/temp_repo.go | 11 | ||||
-rw-r--r-- | services/repository/files/tree.go | 3 | ||||
-rw-r--r-- | services/repository/files/update.go | 15 | ||||
-rw-r--r-- | services/repository/files/upload.go | 7 |
10 files changed, 36 insertions, 29 deletions
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go index 8f14ed8926..6bff1bb97f 100644 --- a/services/repository/files/commit.go +++ b/services/repository/files/commit.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/structs" @@ -16,7 +17,7 @@ import ( // CreateCommitStatus creates a new CommitStatus given a bunch of parameters // NOTE: All text-values will be trimmed from whitespaces. // Requires: Repo, Creator, SHA -func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { +func CreateCommitStatus(repo *repo_model.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { repoPath := repo.RepoPath() // confirm that commit is exist @@ -43,7 +44,7 @@ func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha s } // CountDivergingCommits determines how many commits a branch is ahead or behind the repository's base branch -func CountDivergingCommits(repo *models.Repository, branch string) (*git.DivergeObject, error) { +func CountDivergingCommits(repo *repo_model.Repository, branch string) (*git.DivergeObject, error) { divergence, err := git.GetDivergingCommits(repo.RepoPath(), repo.DefaultBranch, branch) if err != nil { return nil, err diff --git a/services/repository/files/content.go b/services/repository/files/content.go index afb775fed3..10461c82a7 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -38,7 +39,7 @@ func (ct *ContentType) String() string { // GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree // directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag -func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { +func GetContentsOrList(repo *repo_model.Repository, treePath, ref string) (interface{}, error) { if repo.IsEmpty { return make([]interface{}, 0), nil } @@ -100,7 +101,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface } // GetContents gets the meta data on a file's contents. Ref can be a branch, commit or tag -func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) { +func GetContents(repo *repo_model.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) { if ref == "" { ref = repo.DefaultBranch } @@ -218,7 +219,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (* } // GetBlobBySHA get the GitBlobResponse of a repository using a sha hash. -func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, error) { +func GetBlobBySHA(repo *repo_model.Repository, sha string) (*api.GitBlobResponse, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, err diff --git a/services/repository/files/delete.go b/services/repository/files/delete.go index f7b342db3f..15208addda 100644 --- a/services/repository/files/delete.go +++ b/services/repository/files/delete.go @@ -9,6 +9,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" @@ -30,7 +31,7 @@ type DeleteRepoFileOptions struct { } // DeleteRepoFile deletes a file in the given repository -func DeleteRepoFile(repo *models.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) { +func DeleteRepoFile(repo *repo_model.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) { // If no branch name is set, assume the repo's default branch if opts.OldBranch == "" { opts.OldBranch = repo.DefaultBranch diff --git a/services/repository/files/diff.go b/services/repository/files/diff.go index fadaf20231..fb41237e13 100644 --- a/services/repository/files/diff.go +++ b/services/repository/files/diff.go @@ -7,12 +7,12 @@ package files import ( "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/services/gitdiff" ) // GetDiffPreview produces and returns diff result of a file which is not yet committed. -func GetDiffPreview(repo *models.Repository, branch, treePath, content string) (*gitdiff.Diff, error) { +func GetDiffPreview(repo *repo_model.Repository, branch, treePath, content string) (*gitdiff.Diff, error) { if branch == "" { branch = repo.DefaultBranch } diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go index be8e92033d..2f256e888c 100644 --- a/services/repository/files/diff_test.go +++ b/services/repository/files/diff_test.go @@ -7,7 +7,7 @@ package files import ( "testing" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/test" @@ -152,7 +152,7 @@ func TestGetDiffPreviewErrors(t *testing.T) { content := "# repo1\n\nDescription for repo1\nthis is a new line" t.Run("empty repo", func(t *testing.T) { - diff, err := GetDiffPreview(&models.Repository{}, branch, treePath, content) + diff, err := GetDiffPreview(&repo_model.Repository{}, branch, treePath, content) assert.Nil(t, diff) assert.EqualError(t, err, "repository does not exist [id: 0, uid: 0, owner_name: , name: ]") }) diff --git a/services/repository/files/file.go b/services/repository/files/file.go index 8de60c4cb8..7886119587 100644 --- a/services/repository/files/file.go +++ b/services/repository/files/file.go @@ -11,14 +11,14 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" ) // GetFileResponseFromCommit Constructs a FileResponse from a Commit object -func GetFileResponseFromCommit(repo *models.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) { +func GetFileResponseFromCommit(repo *repo_model.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) { fileContents, _ := GetContents(repo, treeName, branch, false) // ok if fails, then will be nil fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil verification := GetPayloadCommitVerification(commit) @@ -31,7 +31,7 @@ func GetFileResponseFromCommit(repo *models.Repository, commit *git.Commit, bran } // GetFileCommitResponse Constructs a FileCommitResponse from a Commit object -func GetFileCommitResponse(repo *models.Repository, commit *git.Commit) (*api.FileCommitResponse, error) { +func GetFileCommitResponse(repo *repo_model.Repository, commit *git.Commit) (*api.FileCommitResponse, error) { if repo == nil { return nil, fmt.Errorf("repo cannot be nil") } diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index 55dcd7436c..815aa2c69f 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -15,6 +15,7 @@ import ( "time" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -24,13 +25,13 @@ import ( // TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone type TemporaryUploadRepository struct { - repo *models.Repository + repo *repo_model.Repository gitRepo *git.Repository basePath string } // NewTemporaryUploadRepository creates a new temporary upload repository -func NewTemporaryUploadRepository(repo *models.Repository) (*TemporaryUploadRepository, error) { +func NewTemporaryUploadRepository(repo *repo_model.Repository) (*TemporaryUploadRepository, error) { basePath, err := models.CreateTemporaryPath("upload") if err != nil { return nil, err @@ -56,7 +57,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error { Name: branch, } } else if matched, _ := regexp.MatchString(".* repository .* does not exist.*", stderr); matched { - return models.ErrRepoNotExist{ + return repo_model.ErrRepoNotExist{ ID: t.repo.ID, UID: t.repo.OwnerID, OwnerName: t.repo.OwnerName, @@ -216,10 +217,10 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *user_m // Determine if we should sign if git.CheckGitVersionAtLeast("1.7.9") == nil { - sign, keyID, signer, _ := t.repo.SignCRUDAction(author, t.basePath, "HEAD") + sign, keyID, signer, _ := models.SignCRUDAction(t.repo, author, t.basePath, "HEAD") if sign { args = append(args, "-S"+keyID) - if t.repo.GetTrustModel() == models.CommitterTrustModel || t.repo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if t.repo.GetTrustModel() == repo_model.CommitterTrustModel || t.repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { if committerSig.Name != authorSig.Name || committerSig.Email != authorSig.Email { // Add trailers _, _ = messageBytes.WriteString("\n") diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index ede206274e..c6b77355ed 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -9,13 +9,14 @@ import ( "net/url" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" ) // GetTreeBySHA get the GitTreeResponse of a repository using a sha hash. -func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) { +func GetTreeBySHA(repo *repo_model.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, err diff --git a/services/repository/files/update.go b/services/repository/files/update.go index eeb98f3630..9a069acbfc 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -12,6 +12,7 @@ import ( "time" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/git" @@ -55,7 +56,7 @@ type UpdateRepoFileOptions struct { Signoff bool } -func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string, bool) { +func detectEncodingAndBOM(entry *git.TreeEntry, repo *repo_model.Repository) (string, bool) { reader, err := entry.Blob().DataAsync() if err != nil { // return default @@ -73,7 +74,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string if setting.LFS.StartServer { pointer, _ := lfs.ReadPointerFromBuffer(buf) if pointer.IsValid() { - meta, err := repo.GetLFSMetaObjectByOid(pointer.Oid) + meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointer.Oid) if err != nil && err != models.ErrLFSObjectNotExist { // return default return "UTF-8", false @@ -123,7 +124,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string } // CreateOrUpdateRepoFile adds or updates a file in the given repository -func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) { +func CreateOrUpdateRepoFile(repo *repo_model.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) { // If no branch name is set, assume default branch if opts.OldBranch == "" { opts.OldBranch = repo.DefaultBranch @@ -413,7 +414,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts } if !exist { if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil { - if _, err2 := repo.RemoveLFSMetaObjectByOid(lfsMetaObject.Oid); err2 != nil { + if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil { return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err) } return nil, err @@ -440,8 +441,8 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts } // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch -func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, branchName string, treePath string) error { - protectedBranch, err := repo.GetBranchProtection(branchName) +func VerifyBranchProtection(repo *repo_model.Repository, doer *user_model.User, branchName string, treePath string) error { + protectedBranch, err := models.GetProtectedBranchBy(repo.ID, branchName) if err != nil { return err } @@ -457,7 +458,7 @@ func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, bran } } if protectedBranch.RequireSignedCommits { - _, _, _, err := repo.SignCRUDAction(doer, repo.RepoPath(), branchName) + _, _, _, err := models.SignCRUDAction(repo, doer, repo.RepoPath(), branchName) if err != nil { if !models.IsErrWontSign(err) { return err diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go index 7a0ea31085..5e9c936113 100644 --- a/services/repository/files/upload.go +++ b/services/repository/files/upload.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" @@ -39,7 +40,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig continue } if !info.lfsMetaObject.Existing { - if _, err := t.repo.RemoveLFSMetaObjectByOid(info.lfsMetaObject.Oid); err != nil { + if _, err := models.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil { original = fmt.Errorf("%v, %v", original, err) } } @@ -48,7 +49,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig } // UploadRepoFiles uploads files to the given repository -func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error { +func UploadRepoFiles(repo *repo_model.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error { if len(opts.Files) == 0 { return nil } @@ -63,7 +64,7 @@ func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *Uploa for i, upload := range uploads { // Check file is not lfs locked, will return nil if lock setting not enabled filepath := path.Join(opts.TreePath, upload.Name) - lfsLock, err := repo.GetTreePathLock(filepath) + lfsLock, err := models.GetTreePathLock(repo.ID, filepath) if err != nil { return err } |