## Purpose This is a refactor toward building an abstraction over managing git repositories. Afterwards, it does not matter anymore if they are stored on the local disk or somewhere remote. ## What this PR changes We used `git.OpenRepository` everywhere previously. Now, we should split them into two distinct functions: Firstly, there are temporary repositories which do not change: ```go git.OpenRepository(ctx, diskPath) ``` Gitea managed repositories having a record in the database in the `repository` table are moved into the new package `gitrepo`: ```go gitrepo.OpenRepository(ctx, repo_model.Repo) ``` Why is `repo_model.Repository` the second parameter instead of file path? Because then we can easily adapt our repository storage strategy. The repositories can be stored locally, however, they could just as well be stored on a remote server. ## Further changes in other PRs - A Git Command wrapper on package `gitrepo` could be created. i.e. `NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir: repo.RepoPath()}`, the directory should be empty before invoking this method and it can be filled in the function only. #28940 - Remove the `RepoPath()`/`WikiPath()` functions to reduce the possibility of mistakes. ---------
Unified · Split
| @@ -11,6 +11,7 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | "code.gitea.io/gitea/models/db" |
| 12 | 12 | repo_model "code.gitea.io/gitea/models/repo" |
| 13 | 13 | "code.gitea.io/gitea/modules/git" |
| 14 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 14 | 15 | "code.gitea.io/gitea/modules/log" |
| 15 | 16 | repo_module "code.gitea.io/gitea/modules/repository" |
| 16 | 17 | |
| @@ -122,7 +123,7 @@ func runRepoSyncReleases(_ *cli.Context) error { · 105 unmodified lines | ||
| 122 | 123 | log.Trace("Processing next %d repos of %d", len(repos), count) |
| 123 | 124 | for _, repo := range repos { |
| 124 | 125 | log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath()) |
| 125 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 126 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 126 | 127 | if err != nil { |
| 127 | 128 | log.Warn("OpenRepository: %v", err) |
| 128 | 129 | continue |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 15 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 16 | "code.gitea.io/gitea/modules/git" |
| 17 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 18 | |
| 18 | 19 | "xorm.io/xorm" |
| 19 | 20 | ) |
| @@ -65,7 +66,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom · 45 unmodified lines | ||
| 65 | 66 | return nil, fmt.Errorf("FillUnresolvedIssues: %w", err) |
| 66 | 67 | } |
| 67 | 68 | if code { |
| 68 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 69 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 69 | 70 | if err != nil { |
| 70 | 71 | return nil, fmt.Errorf("OpenRepository: %w", err) |
| 71 | 72 | } |
| @@ -82,7 +83,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom · 10 unmodified lines | ||
| 82 | 83 | |
| 83 | 84 | // GetActivityStatsTopAuthors returns top author stats for git commits for all branches |
| 84 | 85 | func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) { |
| 85 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 86 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 86 | 87 | if err != nil { |
| 87 | 88 | return nil, fmt.Errorf("OpenRepository: %w", err) |
| 88 | 89 | } |
| @@ -18,7 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | repo_model "code.gitea.io/gitea/models/repo" |
| 19 | 19 | user_model "code.gitea.io/gitea/models/user" |
| 20 | 20 | "code.gitea.io/gitea/modules/container" |
| 21 | − "code.gitea.io/gitea/modules/git" | |
| 21 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 22 | "code.gitea.io/gitea/modules/json" |
| 23 | 23 | "code.gitea.io/gitea/modules/log" |
| 24 | 24 | "code.gitea.io/gitea/modules/references" |
| @@ -762,8 +762,7 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) { · 737 unmodified lines | ||
| 762 | 762 | c.OldCommit = data.CommitIDs[0] |
| 763 | 763 | c.NewCommit = data.CommitIDs[1] |
| 764 | 764 | } else { |
| 765 | − repoPath := c.Issue.Repo.RepoPath() | |
| 766 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath) | |
| 765 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, c.Issue.Repo) | |
| 767 | 766 | if err != nil { |
| 768 | 767 | return err |
| 769 | 768 | } |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | repo_model "code.gitea.io/gitea/models/repo" |
| 20 | 20 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 21 | "code.gitea.io/gitea/modules/git" |
| 22 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 23 | "code.gitea.io/gitea/modules/log" |
| 23 | 24 | "code.gitea.io/gitea/modules/setting" |
| 24 | 25 | "code.gitea.io/gitea/modules/timeutil" |
| @@ -865,7 +866,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque · 840 unmodified lines | ||
| 865 | 866 | return err |
| 866 | 867 | } |
| 867 | 868 | |
| 868 | − repo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 869 | + repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 869 | 870 | if err != nil { |
| 870 | 871 | return err |
| 871 | 872 | } |
| @@ -196,6 +196,14 @@ func init() { · 195 unmodified lines | ||
| 196 | 196 | db.RegisterModel(new(Repository)) |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | +func (repo *Repository) GetName() string { | |
| 200 | + return repo.Name | |
| 201 | +} | |
| 202 | + | |
| 203 | +func (repo *Repository) GetOwnerName() string { | |
| 204 | + return repo.OwnerName | |
| 205 | +} | |
| 206 | + | |
| 199 | 207 | // SanitizedOriginalURL returns a sanitized OriginalURL |
| 200 | 208 | func (repo *Repository) SanitizedOriginalURL() string { |
| 201 | 209 | if repo.OriginalURL == "" { |
| @@ -11,11 +11,11 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | "net/url" |
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | − repo_model "code.gitea.io/gitea/models/repo" | |
| 15 | 14 | "code.gitea.io/gitea/models/unit" |
| 16 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 16 | mc "code.gitea.io/gitea/modules/cache" |
| 18 | 17 | "code.gitea.io/gitea/modules/git" |
| 18 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 19 | "code.gitea.io/gitea/modules/httpcache" |
| 20 | 20 | "code.gitea.io/gitea/modules/log" |
| 21 | 21 | "code.gitea.io/gitea/modules/setting" |
| @@ -224,7 +224,7 @@ func APIContexter() func(http.Handler) http.Handler { · 202 unmodified lines | ||
| 224 | 224 | defer baseCleanUp() |
| 225 | 225 | |
| 226 | 226 | ctx.Base.AppendContextValue(apiContextKey, ctx) |
| 227 | − ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) | |
| 227 | + ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) | |
| 228 | 228 | |
| 229 | 229 | // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid. |
| 230 | 230 | if ctx.Req.Method == "POST" && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") { |
| @@ -278,10 +278,9 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) (cancel context · 47 unmodified lines | ||
| 278 | 278 | |
| 279 | 279 | // For API calls. |
| 280 | 280 | if ctx.Repo.GitRepo == nil { |
| 281 | − repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) | |
| 282 | − gitRepo, err := git.OpenRepository(ctx, repoPath) | |
| 281 | + gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 283 | 282 | if err != nil { |
| 284 | − ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err) | |
| 283 | + ctx.Error(http.StatusInternalServerError, fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err) | |
| 285 | 284 | return cancel |
| 286 | 285 | } |
| 287 | 286 | ctx.Repo.GitRepo = gitRepo |
| @@ -17,7 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | "code.gitea.io/gitea/models/unit" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 19 | 19 | mc "code.gitea.io/gitea/modules/cache" |
| 20 | − "code.gitea.io/gitea/modules/git" | |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 21 | 21 | "code.gitea.io/gitea/modules/httpcache" |
| 22 | 22 | "code.gitea.io/gitea/modules/setting" |
| 23 | 23 | "code.gitea.io/gitea/modules/templates" |
| @@ -163,7 +163,7 @@ func Contexter() func(next http.Handler) http.Handler { · 139 unmodified lines | ||
| 163 | 163 | ctx.Data["PageData"] = ctx.PageData |
| 164 | 164 | |
| 165 | 165 | ctx.Base.AppendContextValue(WebContextKey, ctx) |
| 166 | − ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) | |
| 166 | + ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) | |
| 167 | 167 | |
| 168 | 168 | ctx.Csrf = PrepareCSRFProtector(csrfOpts, ctx) |
| 169 | 169 | |
| @@ -23,6 +23,7 @@ import ( · 22 unmodified lines | ||
| 23 | 23 | user_model "code.gitea.io/gitea/models/user" |
| 24 | 24 | "code.gitea.io/gitea/modules/cache" |
| 25 | 25 | "code.gitea.io/gitea/modules/git" |
| 26 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 26 | 27 | code_indexer "code.gitea.io/gitea/modules/indexer/code" |
| 27 | 28 | "code.gitea.io/gitea/modules/log" |
| 28 | 29 | repo_module "code.gitea.io/gitea/modules/repository" |
| @@ -633,7 +634,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { · 604 unmodified lines | ||
| 633 | 634 | return nil |
| 634 | 635 | } |
| 635 | 636 | |
| 636 | − gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName)) | |
| 637 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 637 | 638 | if err != nil { |
| 638 | 639 | if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") { |
| 639 | 640 | log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err) |
| @@ -645,7 +646,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { · 5 unmodified lines | ||
| 645 | 646 | } |
| 646 | 647 | return nil |
| 647 | 648 | } |
| 648 | − ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err) | |
| 649 | + ctx.ServerError("RepoAssignment Invalid repo "+repo.FullName(), err) | |
| 649 | 650 | return nil |
| 650 | 651 | } |
| 651 | 652 | if ctx.Repo.GitRepo != nil { |
| @@ -920,10 +921,9 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context · 268 unmodified lines | ||
| 920 | 921 | ) |
| 921 | 922 | |
| 922 | 923 | if ctx.Repo.GitRepo == nil { |
| 923 | − repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) | |
| 924 | − ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath) | |
| 924 | + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 925 | 925 | if err != nil { |
| 926 | − ctx.ServerError("RepoRef Invalid repo "+repoPath, err) | |
| 926 | + ctx.ServerError(fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err) | |
| 927 | 927 | return nil |
| 928 | 928 | } |
| 929 | 929 | // We opened it, we should close it |
| @@ -18,7 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | "code.gitea.io/gitea/models/unittest" |
| 19 | 19 | user_model "code.gitea.io/gitea/models/user" |
| 20 | 20 | "code.gitea.io/gitea/modules/context" |
| 21 | − "code.gitea.io/gitea/modules/git" | |
| 21 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 22 | "code.gitea.io/gitea/modules/templates" |
| 23 | 23 | "code.gitea.io/gitea/modules/translation" |
| 24 | 24 | "code.gitea.io/gitea/modules/web/middleware" |
| @@ -107,7 +107,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) { · 82 unmodified lines | ||
| 107 | 107 | assert.FailNow(t, "context is not *context.Context or *context.APIContext") |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | − gitRepo, err := git.OpenRepository(ctx, repo.Repository.RepoPath()) | |
| 110 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo.Repository) | |
| 111 | 111 | assert.NoError(t, err) |
| 112 | 112 | defer gitRepo.Close() |
| 113 | 113 | branch, err := gitRepo.GetHEADBranch() |
| @@ -137,7 +137,7 @@ func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) { · 23 unmodified lines | ||
| 137 | 137 | func LoadGitRepo(t *testing.T, ctx *context.Context) { |
| 138 | 138 | assert.NoError(t, ctx.Repo.Repository.LoadOwner(ctx)) |
| 139 | 139 | var err error |
| 140 | − ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) | |
| 140 | + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 141 | 141 | assert.NoError(t, err) |
| 142 | 142 | } |
| 143 | 143 | |
| @@ -3,48 +3,4 @@ · 2 unmodified lines | ||
| 3 | 3 | |
| 4 | 4 | package git |
| 5 | 5 | |
| 6 | −import ( | |
| 7 | − "context" | |
| 8 | − "io" | |
| 9 | −) | |
| 10 | − | |
| 11 | 6 | var isGogit bool |
| 12 | − | |
| 13 | −// contextKey is a value for use with context.WithValue. | |
| 14 | −type contextKey struct { | |
| 15 | − name string | |
| 16 | −} | |
| 17 | − | |
| 18 | −// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context | |
| 19 | −var RepositoryContextKey = &contextKey{"repository"} | |
| 20 | − | |
| 21 | −// RepositoryFromContext attempts to get the repository from the context | |
| 22 | −func RepositoryFromContext(ctx context.Context, path string) *Repository { | |
| 23 | − value := ctx.Value(RepositoryContextKey) | |
| 24 | − if value == nil { | |
| 25 | − return nil | |
| 26 | − } | |
| 27 | − | |
| 28 | − if repo, ok := value.(*Repository); ok && repo != nil { | |
| 29 | − if repo.Path == path { | |
| 30 | − return repo | |
| 31 | − } | |
| 32 | − } | |
| 33 | − | |
| 34 | − return nil | |
| 35 | −} | |
| 36 | − | |
| 37 | −type nopCloser func() | |
| 38 | − | |
| 39 | −func (nopCloser) Close() error { return nil } | |
| 40 | − | |
| 41 | −// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it | |
| 42 | −func RepositoryFromContextOrOpen(ctx context.Context, path string) (*Repository, io.Closer, error) { | |
| 43 | − gitRepo := RepositoryFromContext(ctx, path) | |
| 44 | − if gitRepo != nil { | |
| 45 | − return gitRepo, nopCloser(nil), nil | |
| 46 | − } | |
| 47 | − | |
| 48 | − gitRepo, err := OpenRepository(ctx, path) | |
| 49 | − return gitRepo, gitRepo, err | |
| 50 | −} | |
| @@ -86,29 +86,6 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) { · 85 unmodified lines | ||
| 86 | 86 | }, nil |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | −// GetBranchesByPath returns a branch by it's path | |
| 90 | −// if limit = 0 it will not limit | |
| 91 | −func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) { | |
| 92 | − gitRepo, err := OpenRepository(ctx, path) | |
| 93 | − if err != nil { | |
| 94 | − return nil, 0, err | |
| 95 | − } | |
| 96 | − defer gitRepo.Close() | |
| 97 | − | |
| 98 | − return gitRepo.GetBranches(skip, limit) | |
| 99 | −} | |
| 100 | − | |
| 101 | −// GetBranchCommitID returns a branch commit ID by its name | |
| 102 | −func GetBranchCommitID(ctx context.Context, path, branch string) (string, error) { | |
| 103 | − gitRepo, err := OpenRepository(ctx, path) | |
| 104 | − if err != nil { | |
| 105 | − return "", err | |
| 106 | − } | |
| 107 | − defer gitRepo.Close() | |
| 108 | − | |
| 109 | − return gitRepo.GetBranchCommitID(branch) | |
| 110 | −} | |
| 111 | − | |
| 112 | 89 | // GetBranches returns a slice of *git.Branch |
| 113 | 90 | func (repo *Repository) GetBranches(skip, limit int) ([]*Branch, int, error) { |
| 114 | 91 | brs, countAll, err := repo.GetBranchNames(skip, limit) |
| @@ -7,7 +7,6 @@ · 6 unmodified lines | ||
| 7 | 7 | package git |
| 8 | 8 | |
| 9 | 9 | import ( |
| 10 | − "context" | |
| 11 | 10 | "sort" |
| 12 | 11 | "strings" |
| 13 | 12 | |
| @@ -95,34 +94,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) { · 81 unmodified lines | ||
| 95 | 94 | return branchNames, len(branchData), nil |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | −// WalkReferences walks all the references from the repository | |
| 99 | −// refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty. | |
| 100 | −func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) { | |
| 101 | − repo := RepositoryFromContext(ctx, repoPath) | |
| 102 | − if repo == nil { | |
| 103 | − var err error | |
| 104 | − repo, err = OpenRepository(ctx, repoPath) | |
| 105 | − if err != nil { | |
| 106 | − return 0, err | |
| 107 | − } | |
| 108 | − defer repo.Close() | |
| 109 | − } | |
| 110 | − | |
| 111 | − i := 0 | |
| 112 | − iter, err := repo.gogitRepo.References() | |
| 113 | − if err != nil { | |
| 114 | − return i, err | |
| 115 | − } | |
| 116 | − defer iter.Close() | |
| 117 | − | |
| 118 | − err = iter.ForEach(func(ref *plumbing.Reference) error { | |
| 119 | − err := walkfn(ref.Hash().String(), string(ref.Name())) | |
| 120 | − i++ | |
| 121 | − return err | |
| 122 | − }) | |
| 123 | − return i, err | |
| 124 | −} | |
| 125 | − | |
| 126 | 97 | // WalkReferences walks all the references from the repository |
| 127 | 98 | func (repo *Repository) WalkReferences(arg ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) { |
| 128 | 99 | i := 0 |
| @@ -65,11 +65,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) { · 64 unmodified lines | ||
| 65 | 65 | return callShowRef(repo.Ctx, repo.Path, BranchPrefix, TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}, skip, limit) |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | −// WalkReferences walks all the references from the repository | |
| 69 | −func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) { | |
| 70 | − return walkShowRef(ctx, repoPath, nil, 0, 0, walkfn) | |
| 71 | −} | |
| 72 | − | |
| 73 | 68 | // WalkReferences walks all the references from the repository |
| 74 | 69 | // refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty. |
| 75 | 70 | func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) { |
| @@ -81,12 +76,12 @@ func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walk · 5 unmodified lines | ||
| 81 | 76 | args = TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"} |
| 82 | 77 | } |
| 83 | 78 | |
| 84 | − return walkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn) | |
| 79 | + return WalkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn) | |
| 85 | 80 | } |
| 86 | 81 | |
| 87 | 82 | // callShowRef return refs, if limit = 0 it will not limit |
| 88 | 83 | func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs TrustedCmdArgs, skip, limit int) (branchNames []string, countAll int, err error) { |
| 89 | − countAll, err = walkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error { | |
| 84 | + countAll, err = WalkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error { | |
| 90 | 85 | branchName = strings.TrimPrefix(branchName, trimPrefix) |
| 91 | 86 | branchNames = append(branchNames, branchName) |
| 92 | 87 | |
| @@ -95,7 +90,7 @@ func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs Tru · 2 unmodified lines | ||
| 95 | 90 | return branchNames, countAll, err |
| 96 | 91 | } |
| 97 | 92 | |
| 98 | −func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) { | |
| 93 | +func WalkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) { | |
| 99 | 94 | stdoutReader, stdoutWriter := io.Pipe() |
| 100 | 95 | defer func() { |
| 101 | 96 | _ = stdoutReader.Close() |
| @@ -189,7 +184,7 @@ func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, · 87 unmodified lines | ||
| 189 | 184 | // GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash |
| 190 | 185 | func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error) { |
| 191 | 186 | var revList []string |
| 192 | − _, err := walkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error { | |
| 187 | + _, err := WalkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error { | |
| 193 | 188 | if walkSha == sha && strings.HasPrefix(refname, prefix) { |
| 194 | 189 | revList = append(revList, refname) |
| 195 | 190 | } |
| @@ -0,0 +1,32 @@ | ||
| 1 | +// Copyright 2024 The Gitea Authors. All rights reserved. | |
| 2 | +// SPDX-License-Identifier: MIT | |
| 3 | + | |
| 4 | +package gitrepo | |
| 5 | + | |
| 6 | +import ( | |
| 7 | + "context" | |
| 8 | + | |
| 9 | + "code.gitea.io/gitea/modules/git" | |
| 10 | +) | |
| 11 | + | |
| 12 | +// GetBranchesByPath returns a branch by its path | |
| 13 | +// if limit = 0 it will not limit | |
| 14 | +func GetBranchesByPath(ctx context.Context, repo Repository, skip, limit int) ([]*git.Branch, int, error) { | |
| 15 | + gitRepo, err := OpenRepository(ctx, repo) | |
| 16 | + if err != nil { | |
| 17 | + return nil, 0, err | |
| 18 | + } | |
| 19 | + defer gitRepo.Close() | |
| 20 | + | |
| 21 | + return gitRepo.GetBranches(skip, limit) | |
| 22 | +} | |
| 23 | + | |
| 24 | +func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (string, error) { | |
| 25 | + gitRepo, err := OpenRepository(ctx, repo) | |
| 26 | + if err != nil { | |
| 27 | + return "", err | |
| 28 | + } | |
| 29 | + defer gitRepo.Close() | |
| 30 | + | |
| 31 | + return gitRepo.GetBranchCommitID(branch) | |
| 32 | +} | |
| @@ -0,0 +1,103 @@ | ||
| 1 | +// Copyright 2024 The Gitea Authors. All rights reserved. | |
| 2 | +// SPDX-License-Identifier: MIT | |
| 3 | + | |
| 4 | +package gitrepo | |
| 5 | + | |
| 6 | +import ( | |
| 7 | + "context" | |
| 8 | + "io" | |
| 9 | + "path/filepath" | |
| 10 | + "strings" | |
| 11 | + | |
| 12 | + "code.gitea.io/gitea/modules/git" | |
| 13 | + "code.gitea.io/gitea/modules/setting" | |
| 14 | +) | |
| 15 | + | |
| 16 | +type Repository interface { | |
| 17 | + GetName() string | |
| 18 | + GetOwnerName() string | |
| 19 | +} | |
| 20 | + | |
| 21 | +func repoPath(repo Repository) string { | |
| 22 | + return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".git") | |
| 23 | +} | |
| 24 | + | |
| 25 | +func wikiPath(repo Repository) string { | |
| 26 | + return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".wiki.git") | |
| 27 | +} | |
| 28 | + | |
| 29 | +// OpenRepository opens the repository at the given relative path with the provided context. | |
| 30 | +func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error) { | |
| 31 | + return git.OpenRepository(ctx, repoPath(repo)) | |
| 32 | +} | |
| 33 | + | |
| 34 | +func OpenWikiRepository(ctx context.Context, repo Repository) (*git.Repository, error) { | |
| 35 | + return git.OpenRepository(ctx, wikiPath(repo)) | |
| 36 | +} | |
| 37 | + | |
| 38 | +// contextKey is a value for use with context.WithValue. | |
| 39 | +type contextKey struct { | |
| 40 | + name string | |
| 41 | +} | |
| 42 | + | |
| 43 | +// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context | |
| 44 | +var RepositoryContextKey = &contextKey{"repository"} | |
| 45 | + | |
| 46 | +// RepositoryFromContext attempts to get the repository from the context | |
| 47 | +func repositoryFromContext(ctx context.Context, repo Repository) *git.Repository { | |
| 48 | + value := ctx.Value(RepositoryContextKey) | |
| 49 | + if value == nil { | |
| 50 | + return nil | |
| 51 | + } | |
| 52 | + | |
| 53 | + if gitRepo, ok := value.(*git.Repository); ok && gitRepo != nil { | |
| 54 | + if gitRepo.Path == repoPath(repo) { | |
| 55 | + return gitRepo | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + return nil | |
| 60 | +} | |
| 61 | + | |
| 62 | +type nopCloser func() | |
| 63 | + | |
| 64 | +func (nopCloser) Close() error { return nil } | |
| 65 | + | |
| 66 | +// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it | |
| 67 | +func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Repository, io.Closer, error) { | |
| 68 | + gitRepo := repositoryFromContext(ctx, repo) | |
| 69 | + if gitRepo != nil { | |
| 70 | + return gitRepo, nopCloser(nil), nil | |
| 71 | + } | |
| 72 | + | |
| 73 | + gitRepo, err := OpenRepository(ctx, repo) | |
| 74 | + return gitRepo, gitRepo, err | |
| 75 | +} | |
| 76 | + | |
| 77 | +// repositoryFromContextPath attempts to get the repository from the context | |
| 78 | +func repositoryFromContextPath(ctx context.Context, path string) *git.Repository { | |
| 79 | + value := ctx.Value(RepositoryContextKey) | |
| 80 | + if value == nil { | |
| 81 | + return nil | |
| 82 | + } | |
| 83 | + | |
| 84 | + if repo, ok := value.(*git.Repository); ok && repo != nil { | |
| 85 | + if repo.Path == path { | |
| 86 | + return repo | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + return nil | |
| 91 | +} | |
| 92 | + | |
| 93 | +// RepositoryFromContextOrOpenPath attempts to get the repository from the context or just opens it | |
| 94 | +// Deprecated: Use RepositoryFromContextOrOpen instead | |
| 95 | +func RepositoryFromContextOrOpenPath(ctx context.Context, path string) (*git.Repository, io.Closer, error) { | |
| 96 | + gitRepo := repositoryFromContextPath(ctx, path) | |
| 97 | + if gitRepo != nil { | |
| 98 | + return gitRepo, nopCloser(nil), nil | |
| 99 | + } | |
| 100 | + | |
| 101 | + gitRepo, err := git.OpenRepository(ctx, path) | |
| 102 | + return gitRepo, gitRepo, err | |
| 103 | +} | |
| @@ -0,0 +1,40 @@ | ||
| 1 | +// Copyright 2024 The Gitea Authors. All rights reserved. | |
| 2 | +// SPDX-License-Identifier: MIT | |
| 3 | + | |
| 4 | +//go:build gogit | |
| 5 | + | |
| 6 | +package gitrepo | |
| 7 | + | |
| 8 | +import ( | |
| 9 | + "context" | |
| 10 | + | |
| 11 | + "github.com/go-git/go-git/v5/plumbing" | |
| 12 | +) | |
| 13 | + | |
| 14 | +// WalkReferences walks all the references from the repository | |
| 15 | +// refname is empty, ObjectTag or ObjectBranch. All other values should be treated as equivalent to empty. | |
| 16 | +func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) { | |
| 17 | + gitRepo := repositoryFromContext(ctx, repo) | |
| 18 | + if gitRepo == nil { | |
| 19 | + var err error | |
| 20 | + gitRepo, err = OpenRepository(ctx, repo) | |
| 21 | + if err != nil { | |
| 22 | + return 0, err | |
| 23 | + } | |
| 24 | + defer gitRepo.Close() | |
| 25 | + } | |
| 26 | + | |
| 27 | + i := 0 | |
| 28 | + iter, err := gitRepo.GoGitRepo().References() | |
| 29 | + if err != nil { | |
| 30 | + return i, err | |
| 31 | + } | |
| 32 | + defer iter.Close() | |
| 33 | + | |
| 34 | + err = iter.ForEach(func(ref *plumbing.Reference) error { | |
| 35 | + err := walkfn(ref.Hash().String(), string(ref.Name())) | |
| 36 | + i++ | |
| 37 | + return err | |
| 38 | + }) | |
| 39 | + return i, err | |
| 40 | +} | |
| @@ -0,0 +1,17 @@ | ||
| 1 | +// Copyright 2024 The Gitea Authors. All rights reserved. | |
| 2 | +// SPDX-License-Identifier: MIT | |
| 3 | + | |
| 4 | +//go:build !gogit | |
| 5 | + | |
| 6 | +package gitrepo | |
| 7 | + | |
| 8 | +import ( | |
| 9 | + "context" | |
| 10 | + | |
| 11 | + "code.gitea.io/gitea/modules/git" | |
| 12 | +) | |
| 13 | + | |
| 14 | +// WalkReferences walks all the references from the repository | |
| 15 | +func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) { | |
| 16 | + return git.WalkShowRef(ctx, repoPath(repo), nil, 0, 0, walkfn) | |
| 17 | +} | |
| @@ -8,6 +8,7 @@ import ( · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | repo_model "code.gitea.io/gitea/models/repo" |
| 10 | 10 | "code.gitea.io/gitea/modules/git" |
| 11 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 11 | 12 | "code.gitea.io/gitea/modules/graceful" |
| 12 | 13 | "code.gitea.io/gitea/modules/log" |
| 13 | 14 | "code.gitea.io/gitea/modules/process" |
| @@ -35,7 +36,7 @@ func (db *DBIndexer) Index(id int64) error { · 21 unmodified lines | ||
| 35 | 36 | return err |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 39 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 39 | 40 | if err != nil { |
| 40 | 41 | if err.Error() == "no such file or directory" { |
| 41 | 42 | return nil |
| @@ -11,6 +11,7 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | repo_model "code.gitea.io/gitea/models/repo" |
| 12 | 12 | "code.gitea.io/gitea/modules/container" |
| 13 | 13 | "code.gitea.io/gitea/modules/git" |
| 14 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 14 | 15 | "code.gitea.io/gitea/modules/log" |
| 15 | 16 | "code.gitea.io/gitea/modules/timeutil" |
| 16 | 17 | ) |
| @@ -24,9 +25,9 @@ func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error) · 7 unmodified lines | ||
| 24 | 25 | |
| 25 | 26 | log.Debug("SyncRepoBranches: in Repo[%d:%s]", repo.ID, repo.FullName()) |
| 26 | 27 | |
| 27 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 28 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 28 | 29 | if err != nil { |
| 29 | − log.Error("OpenRepository[%s]: %w", repo.RepoPath(), err) | |
| 30 | + log.Error("OpenRepository[%s]: %w", repo.FullName(), err) | |
| 30 | 31 | return 0, err |
| 31 | 32 | } |
| 32 | 33 | defer gitRepo.Close() |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | repo_model "code.gitea.io/gitea/models/repo" |
| 20 | 20 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 21 | "code.gitea.io/gitea/modules/git" |
| 22 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 23 | "code.gitea.io/gitea/modules/log" |
| 23 | 24 | "code.gitea.io/gitea/modules/util" |
| 24 | 25 | |
| @@ -271,7 +272,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r · 246 unmodified lines | ||
| 271 | 272 | repo.DefaultBranch = templateRepo.DefaultBranch |
| 272 | 273 | } |
| 273 | 274 | |
| 274 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 275 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 275 | 276 | if err != nil { |
| 276 | 277 | return fmt.Errorf("openRepository: %w", err) |
| 277 | 278 | } |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | user_model "code.gitea.io/gitea/models/user" |
| 20 | 20 | "code.gitea.io/gitea/modules/container" |
| 21 | 21 | "code.gitea.io/gitea/modules/git" |
| 22 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 23 | "code.gitea.io/gitea/modules/lfs" |
| 23 | 24 | "code.gitea.io/gitea/modules/log" |
| 24 | 25 | "code.gitea.io/gitea/modules/migration" |
| @@ -291,7 +292,7 @@ func SyncRepoTags(ctx context.Context, repoID int64) error { · 266 unmodified lines | ||
| 291 | 292 | return err |
| 292 | 293 | } |
| 293 | 294 | |
| 294 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 295 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 295 | 296 | if err != nil { |
| 296 | 297 | return err |
| 297 | 298 | } |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 17 | "code.gitea.io/gitea/modules/context" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | repo_module "code.gitea.io/gitea/modules/repository" |
| 20 | 21 | api "code.gitea.io/gitea/modules/structs" |
| 21 | 22 | "code.gitea.io/gitea/modules/util" |
| @@ -643,7 +644,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 621 unmodified lines | ||
| 643 | 644 | } else { |
| 644 | 645 | if !isPlainRule { |
| 645 | 646 | if ctx.Repo.GitRepo == nil { |
| 646 | − ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) | |
| 647 | + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 647 | 648 | if err != nil { |
| 648 | 649 | ctx.Error(http.StatusInternalServerError, "OpenRepository", err) |
| 649 | 650 | return |
| @@ -920,7 +921,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 270 unmodified lines | ||
| 920 | 921 | } else { |
| 921 | 922 | if !isPlainRule { |
| 922 | 923 | if ctx.Repo.GitRepo == nil { |
| 923 | − ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) | |
| 924 | + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 924 | 925 | if err != nil { |
| 925 | 926 | ctx.Error(http.StatusInternalServerError, "OpenRepository", err) |
| 926 | 927 | return |
| @@ -21,6 +21,7 @@ import ( · 20 unmodified lines | ||
| 21 | 21 | "code.gitea.io/gitea/models/unit" |
| 22 | 22 | "code.gitea.io/gitea/modules/context" |
| 23 | 23 | "code.gitea.io/gitea/modules/git" |
| 24 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 24 | 25 | "code.gitea.io/gitea/modules/httpcache" |
| 25 | 26 | "code.gitea.io/gitea/modules/lfs" |
| 26 | 27 | "code.gitea.io/gitea/modules/log" |
| @@ -279,9 +280,8 @@ func GetArchive(ctx *context.APIContext) { · 252 unmodified lines | ||
| 279 | 280 | // "404": |
| 280 | 281 | // "$ref": "#/responses/notFound" |
| 281 | 282 | |
| 282 | − repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) | |
| 283 | 283 | if ctx.Repo.GitRepo == nil { |
| 284 | − gitRepo, err := git.OpenRepository(ctx, repoPath) | |
| 284 | + gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 285 | 285 | if err != nil { |
| 286 | 286 | ctx.Error(http.StatusInternalServerError, "OpenRepository", err) |
| 287 | 287 | return |
| @@ -23,6 +23,7 @@ import ( · 22 unmodified lines | ||
| 23 | 23 | user_model "code.gitea.io/gitea/models/user" |
| 24 | 24 | "code.gitea.io/gitea/modules/context" |
| 25 | 25 | "code.gitea.io/gitea/modules/git" |
| 26 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 26 | 27 | "code.gitea.io/gitea/modules/log" |
| 27 | 28 | "code.gitea.io/gitea/modules/setting" |
| 28 | 29 | api "code.gitea.io/gitea/modules/structs" |
| @@ -906,9 +907,9 @@ func MergePullRequest(ctx *context.APIContext) { · 877 unmodified lines | ||
| 906 | 907 | if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil { |
| 907 | 908 | headRepo = ctx.Repo.GitRepo |
| 908 | 909 | } else { |
| 909 | − headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) | |
| 910 | + headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo) | |
| 910 | 911 | if err != nil { |
| 911 | − ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) | |
| 912 | + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err) | |
| 912 | 913 | return |
| 913 | 914 | } |
| 914 | 915 | defer headRepo.Close() |
| @@ -1004,7 +1005,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) · 89 unmodified lines | ||
| 1004 | 1005 | headRepo = ctx.Repo.Repository |
| 1005 | 1006 | headGitRepo = ctx.Repo.GitRepo |
| 1006 | 1007 | } else { |
| 1007 | − headGitRepo, err = git.OpenRepository(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name)) | |
| 1008 | + headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo) | |
| 1008 | 1009 | if err != nil { |
| 1009 | 1010 | ctx.Error(http.StatusInternalServerError, "OpenRepository", err) |
| 1010 | 1011 | return nil, nil, nil, nil, "", "" |
| @@ -1308,7 +1309,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { · 297 unmodified lines | ||
| 1308 | 1309 | } |
| 1309 | 1310 | |
| 1310 | 1311 | var prInfo *git.CompareInfo |
| 1311 | − baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) | |
| 1312 | + baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo) | |
| 1312 | 1313 | if err != nil { |
| 1313 | 1314 | ctx.ServerError("OpenRepository", err) |
| 1314 | 1315 | return |
| @@ -13,7 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | access_model "code.gitea.io/gitea/models/perm/access" |
| 14 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 15 | "code.gitea.io/gitea/modules/context" |
| 16 | − "code.gitea.io/gitea/modules/git" | |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 17 | api "code.gitea.io/gitea/modules/structs" |
| 18 | 18 | "code.gitea.io/gitea/modules/web" |
| 19 | 19 | "code.gitea.io/gitea/routers/api/v1/utils" |
| @@ -329,8 +329,7 @@ func CreatePullReview(ctx *context.APIContext) { · 309 unmodified lines | ||
| 329 | 329 | |
| 330 | 330 | // if CommitID is empty, set it as lastCommitID |
| 331 | 331 | if opts.CommitID == "" { |
| 332 | − | |
| 333 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo.RepoPath()) | |
| 332 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo) | |
| 334 | 333 | if err != nil { |
| 335 | 334 | ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err) |
| 336 | 335 | return |
| @@ -21,6 +21,7 @@ import ( · 20 unmodified lines | ||
| 21 | 21 | user_model "code.gitea.io/gitea/models/user" |
| 22 | 22 | "code.gitea.io/gitea/modules/context" |
| 23 | 23 | "code.gitea.io/gitea/modules/git" |
| 24 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 24 | 25 | "code.gitea.io/gitea/modules/label" |
| 25 | 26 | "code.gitea.io/gitea/modules/log" |
| 26 | 27 | repo_module "code.gitea.io/gitea/modules/repository" |
| @@ -718,7 +719,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err · 691 unmodified lines | ||
| 718 | 719 | |
| 719 | 720 | if ctx.Repo.GitRepo == nil && !repo.IsEmpty { |
| 720 | 721 | var err error |
| 721 | − ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) | |
| 722 | + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 722 | 723 | if err != nil { |
| 723 | 724 | ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err) |
| 724 | 725 | return err |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | repo_model "code.gitea.io/gitea/models/repo" |
| 13 | 13 | "code.gitea.io/gitea/modules/context" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | "code.gitea.io/gitea/modules/setting" |
| 16 | 17 | api "code.gitea.io/gitea/modules/structs" |
| 17 | 18 | "code.gitea.io/gitea/modules/util" |
| @@ -475,7 +476,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) · 457 unmodified lines | ||
| 475 | 476 | // findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error. |
| 476 | 477 | // The caller is responsible for closing the returned repo again |
| 477 | 478 | func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) { |
| 478 | − wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) | |
| 479 | + wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) | |
| 479 | 480 | if err != nil { |
| 480 | 481 | |
| 481 | 482 | if git.IsErrNotExist(err) || err.Error() == "no such file or directory" { |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | "code.gitea.io/gitea/modules/context" |
| 12 | 12 | "code.gitea.io/gitea/modules/git" |
| 13 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 13 | 14 | "code.gitea.io/gitea/modules/log" |
| 14 | 15 | ) |
| 15 | 16 | |
| @@ -79,7 +80,7 @@ func ConvertToObjectID(ctx gocontext.Context, repo *context.Repository, commitID · 63 unmodified lines | ||
| 79 | 80 | } |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.Repository.RepoPath()) | |
| 83 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo.Repository) | |
| 83 | 84 | if err != nil { |
| 84 | 85 | return objectFormat.EmptyObjectID(), fmt.Errorf("RepositoryFromContextOrOpen: %w", err) |
| 85 | 86 | } |
| @@ -10,7 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | repo_model "code.gitea.io/gitea/models/repo" |
| 12 | 12 | gitea_context "code.gitea.io/gitea/modules/context" |
| 13 | − "code.gitea.io/gitea/modules/git" | |
| 13 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 14 | 14 | "code.gitea.io/gitea/modules/log" |
| 15 | 15 | "code.gitea.io/gitea/modules/private" |
| 16 | 16 | ) |
| @@ -28,7 +28,7 @@ func RepoAssignment(ctx *gitea_context.PrivateContext) context.CancelFunc { · 11 unmodified lines | ||
| 28 | 28 | return nil |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 31 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 32 | 32 | if err != nil { |
| 33 | 33 | log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err) |
| 34 | 34 | ctx.JSON(http.StatusInternalServerError, private.Response{ |
| @@ -22,6 +22,7 @@ import ( · 21 unmodified lines | ||
| 22 | 22 | "code.gitea.io/gitea/modules/context" |
| 23 | 23 | "code.gitea.io/gitea/modules/git" |
| 24 | 24 | "code.gitea.io/gitea/modules/gitgraph" |
| 25 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 25 | 26 | "code.gitea.io/gitea/modules/log" |
| 26 | 27 | "code.gitea.io/gitea/modules/markup" |
| 27 | 28 | "code.gitea.io/gitea/modules/setting" |
| @@ -279,7 +280,7 @@ func Diff(ctx *context.Context) { · 251 unmodified lines | ||
| 279 | 280 | ) |
| 280 | 281 | |
| 281 | 282 | if ctx.Data["PageIsWiki"] != nil { |
| 282 | − gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) | |
| 283 | + gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) | |
| 283 | 284 | if err != nil { |
| 284 | 285 | ctx.ServerError("Repo.GitRepo.GetCommit", err) |
| 285 | 286 | return |
| @@ -404,7 +405,7 @@ func Diff(ctx *context.Context) { · 118 unmodified lines | ||
| 404 | 405 | func RawDiff(ctx *context.Context) { |
| 405 | 406 | var gitRepo *git.Repository |
| 406 | 407 | if ctx.Data["PageIsWiki"] != nil { |
| 407 | − wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) | |
| 408 | + wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) | |
| 408 | 409 | if err != nil { |
| 409 | 410 | ctx.ServerError("OpenRepository", err) |
| 410 | 411 | return |
| @@ -28,6 +28,7 @@ import ( · 27 unmodified lines | ||
| 28 | 28 | "code.gitea.io/gitea/modules/context" |
| 29 | 29 | csv_module "code.gitea.io/gitea/modules/csv" |
| 30 | 30 | "code.gitea.io/gitea/modules/git" |
| 31 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 31 | 32 | "code.gitea.io/gitea/modules/log" |
| 32 | 33 | "code.gitea.io/gitea/modules/markup" |
| 33 | 34 | "code.gitea.io/gitea/modules/setting" |
| @@ -408,7 +409,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { · 374 unmodified lines | ||
| 408 | 409 | ci.HeadRepo = ctx.Repo.Repository |
| 409 | 410 | ci.HeadGitRepo = ctx.Repo.GitRepo |
| 410 | 411 | } else if has { |
| 411 | − ci.HeadGitRepo, err = git.OpenRepository(ctx, ci.HeadRepo.RepoPath()) | |
| 412 | + ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo) | |
| 412 | 413 | if err != nil { |
| 413 | 414 | ctx.ServerError("OpenRepository", err) |
| 414 | 415 | return nil |
| @@ -688,7 +689,7 @@ func PrepareCompareDiff( · 273 unmodified lines | ||
| 688 | 689 | } |
| 689 | 690 | |
| 690 | 691 | func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) { |
| 691 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 692 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 692 | 693 | if err != nil { |
| 693 | 694 | return nil, nil, err |
| 694 | 695 | } |
| @@ -876,7 +877,7 @@ func ExcerptBlob(ctx *context.Context) { · 181 unmodified lines | ||
| 876 | 877 | gitRepo := ctx.Repo.GitRepo |
| 877 | 878 | if ctx.FormBool("wiki") { |
| 878 | 879 | var err error |
| 879 | − gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) | |
| 880 | + gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) | |
| 880 | 881 | if err != nil { |
| 881 | 882 | ctx.ServerError("OpenRepository", err) |
| 882 | 883 | return |
| @@ -9,6 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "code.gitea.io/gitea/models/unittest" |
| 10 | 10 | "code.gitea.io/gitea/modules/contexttest" |
| 11 | 11 | "code.gitea.io/gitea/modules/git" |
| 12 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 12 | 13 | |
| 13 | 14 | "github.com/stretchr/testify/assert" |
| 14 | 15 | ) |
| @@ -66,7 +67,7 @@ func TestGetClosestParentWithFiles(t *testing.T) { · 51 unmodified lines | ||
| 66 | 67 | |
| 67 | 68 | repo := ctx.Repo.Repository |
| 68 | 69 | branch := repo.DefaultBranch |
| 69 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 70 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 70 | 71 | defer gitRepo.Close() |
| 71 | 72 | commit, _ := gitRepo.GetBranchCommit(branch) |
| 72 | 73 | var expectedTreePath string // Should return the root dir, empty string, since there are no subdirs in this repo |
| @@ -29,6 +29,7 @@ import ( · 28 unmodified lines | ||
| 29 | 29 | "code.gitea.io/gitea/modules/base" |
| 30 | 30 | "code.gitea.io/gitea/modules/context" |
| 31 | 31 | "code.gitea.io/gitea/modules/git" |
| 32 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 32 | 33 | issue_template "code.gitea.io/gitea/modules/issue/template" |
| 33 | 34 | "code.gitea.io/gitea/modules/log" |
| 34 | 35 | "code.gitea.io/gitea/modules/setting" |
| @@ -530,7 +531,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C · 495 unmodified lines | ||
| 530 | 531 | if pull.BaseRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil { |
| 531 | 532 | baseGitRepo = ctx.Repo.GitRepo |
| 532 | 533 | } else { |
| 533 | − baseGitRepo, err := git.OpenRepository(ctx, pull.BaseRepo.RepoPath()) | |
| 534 | + baseGitRepo, err := gitrepo.OpenRepository(ctx, pull.BaseRepo) | |
| 534 | 535 | if err != nil { |
| 535 | 536 | ctx.ServerError("OpenRepository", err) |
| 536 | 537 | return nil |
| @@ -582,7 +583,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C · 45 unmodified lines | ||
| 582 | 583 | var headBranchSha string |
| 583 | 584 | // HeadRepo may be missing |
| 584 | 585 | if pull.HeadRepo != nil { |
| 585 | − headGitRepo, err := git.OpenRepository(ctx, pull.HeadRepo.RepoPath()) | |
| 586 | + headGitRepo, err := gitrepo.OpenRepository(ctx, pull.HeadRepo) | |
| 586 | 587 | if err != nil { |
| 587 | 588 | ctx.ServerError("OpenRepository", err) |
| 588 | 589 | return nil |
| @@ -1314,9 +1315,9 @@ func MergePullRequest(ctx *context.Context) { · 725 unmodified lines | ||
| 1314 | 1315 | if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil { |
| 1315 | 1316 | headRepo = ctx.Repo.GitRepo |
| 1316 | 1317 | } else { |
| 1317 | − headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) | |
| 1318 | + headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo) | |
| 1318 | 1319 | if err != nil { |
| 1319 | − ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) | |
| 1320 | + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err) | |
| 1320 | 1321 | return |
| 1321 | 1322 | } |
| 1322 | 1323 | defer headRepo.Close() |
| @@ -1537,9 +1538,9 @@ func CleanUpPullRequest(ctx *context.Context) { · 214 unmodified lines | ||
| 1537 | 1538 | gitBaseRepo = ctx.Repo.GitRepo |
| 1538 | 1539 | } else { |
| 1539 | 1540 | // If not just open it |
| 1540 | − gitBaseRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 1541 | + gitBaseRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 1541 | 1542 | if err != nil { |
| 1542 | − ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err) | |
| 1543 | + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.FullName()), err) | |
| 1543 | 1544 | return |
| 1544 | 1545 | } |
| 1545 | 1546 | defer gitBaseRepo.Close() |
| @@ -1552,9 +1553,9 @@ func CleanUpPullRequest(ctx *context.Context) { · 6 unmodified lines | ||
| 1552 | 1553 | gitRepo = ctx.Repo.GitRepo |
| 1553 | 1554 | } else if pr.BaseRepoID != pr.HeadRepoID { |
| 1554 | 1555 | // Otherwise just load it up |
| 1555 | − gitRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) | |
| 1556 | + gitRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo) | |
| 1556 | 1557 | if err != nil { |
| 1557 | − ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) | |
| 1558 | + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err) | |
| 1558 | 1559 | return |
| 1559 | 1560 | } |
| 1560 | 1561 | defer gitRepo.Close() |
| @@ -20,6 +20,7 @@ import ( · 19 unmodified lines | ||
| 20 | 20 | "code.gitea.io/gitea/modules/charset" |
| 21 | 21 | "code.gitea.io/gitea/modules/context" |
| 22 | 22 | "code.gitea.io/gitea/modules/git" |
| 23 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 23 | 24 | "code.gitea.io/gitea/modules/log" |
| 24 | 25 | "code.gitea.io/gitea/modules/markup" |
| 25 | 26 | "code.gitea.io/gitea/modules/markup/markdown" |
| @@ -92,7 +93,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) · 66 unmodified lines | ||
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) { |
| 95 | − wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) | |
| 96 | + wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) | |
| 96 | 97 | if err != nil { |
| 97 | 98 | ctx.ServerError("OpenRepository", err) |
| 98 | 99 | return nil, nil, err |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models/unittest" |
| 14 | 14 | "code.gitea.io/gitea/modules/contexttest" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/modules/web" |
| 17 | 18 | "code.gitea.io/gitea/services/forms" |
| 18 | 19 | wiki_service "code.gitea.io/gitea/services/wiki" |
| @@ -26,7 +27,7 @@ const ( · 7 unmodified lines | ||
| 26 | 27 | ) |
| 27 | 28 | |
| 28 | 29 | func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName wiki_service.WebPath) *git.TreeEntry { |
| 29 | − wikiRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) | |
| 30 | + wikiRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) | |
| 30 | 31 | assert.NoError(t, err) |
| 31 | 32 | defer wikiRepo.Close() |
| 32 | 33 | commit, err := wikiRepo.GetBranchCommit("master") |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 14 | "code.gitea.io/gitea/modules/context" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/modules/log" |
| 17 | 18 | "code.gitea.io/gitea/modules/markup" |
| 18 | 19 | "code.gitea.io/gitea/modules/markup/markdown" |
| @@ -90,7 +91,7 @@ func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profile · 71 unmodified lines | ||
| 90 | 91 | if err == nil { |
| 91 | 92 | perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer) |
| 92 | 93 | if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) { |
| 93 | − if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil { | |
| 94 | + if profileGitRepo, err = gitrepo.OpenRepository(ctx, profileDbRepo); err != nil { | |
| 94 | 95 | log.Error("FindUserProfileReadme failed to OpenRepository: %v", err) |
| 95 | 96 | } else { |
| 96 | 97 | if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil { |
| @@ -20,6 +20,7 @@ import ( · 19 unmodified lines | ||
| 20 | 20 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 21 | actions_module "code.gitea.io/gitea/modules/actions" |
| 22 | 22 | "code.gitea.io/gitea/modules/git" |
| 23 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 23 | 24 | "code.gitea.io/gitea/modules/json" |
| 24 | 25 | "code.gitea.io/gitea/modules/log" |
| 25 | 26 | "code.gitea.io/gitea/modules/setting" |
| @@ -128,7 +129,7 @@ func notify(ctx context.Context, input *notifyInput) error { · 102 unmodified lines | ||
| 128 | 129 | return nil |
| 129 | 130 | } |
| 130 | 131 | |
| 131 | − gitRepo, err := git.OpenRepository(context.Background(), input.Repo.RepoPath()) | |
| 132 | + gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo) | |
| 132 | 133 | if err != nil { |
| 133 | 134 | return fmt.Errorf("git.OpenRepository: %w", err) |
| 134 | 135 | } |
| @@ -13,8 +13,10 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models/db" |
| 14 | 14 | git_model "code.gitea.io/gitea/models/git" |
| 15 | 15 | issues_model "code.gitea.io/gitea/models/issues" |
| 16 | + repo_model "code.gitea.io/gitea/models/repo" | |
| 16 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 18 | 20 | "code.gitea.io/gitea/modules/log" |
| 19 | 21 | "code.gitea.io/gitea/modules/process" |
| 20 | 22 | "code.gitea.io/gitea/modules/setting" |
| @@ -167,7 +169,8 @@ Loop: · 146 unmodified lines | ||
| 167 | 169 | } |
| 168 | 170 | |
| 169 | 171 | // SignWikiCommit determines if we should sign the commits to this repository wiki |
| 170 | −func SignWikiCommit(ctx context.Context, repoWikiPath string, u *user_model.User) (bool, string, *git.Signature, error) { | |
| 172 | +func SignWikiCommit(ctx context.Context, repo *repo_model.Repository, u *user_model.User) (bool, string, *git.Signature, error) { | |
| 173 | + repoWikiPath := repo.WikiPath() | |
| 171 | 174 | rules := signingModeFromStrings(setting.Repository.Signing.Wiki) |
| 172 | 175 | signingKey, sig := SigningKey(ctx, repoWikiPath) |
| 173 | 176 | if signingKey == "" { |
| @@ -201,7 +204,7 @@ Loop: · 27 unmodified lines | ||
| 201 | 204 | return false, "", nil, &ErrWontSign{twofa} |
| 202 | 205 | } |
| 203 | 206 | case parentSigned: |
| 204 | − gitRepo, err := git.OpenRepository(ctx, repoWikiPath) | |
| 207 | + gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo) | |
| 205 | 208 | if err != nil { |
| 206 | 209 | return false, "", nil, err |
| 207 | 210 | } |
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 19 | 19 | "code.gitea.io/gitea/modules/git" |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 20 | 21 | "code.gitea.io/gitea/modules/graceful" |
| 21 | 22 | "code.gitea.io/gitea/modules/log" |
| 22 | 23 | "code.gitea.io/gitea/modules/process" |
| @@ -111,7 +112,7 @@ func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model · 88 unmodified lines | ||
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) { |
| 114 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 115 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 115 | 116 | if err != nil { |
| 116 | 117 | return nil, err |
| 117 | 118 | } |
| @@ -190,7 +191,7 @@ func handlePull(pullID int64, sha string) { · 72 unmodified lines | ||
| 190 | 191 | return |
| 191 | 192 | } |
| 192 | 193 | |
| 193 | − headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) | |
| 194 | + headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo) | |
| 194 | 195 | if err != nil { |
| 195 | 196 | log.Error("OpenRepository %-v: %v", pr.HeadRepo, err) |
| 196 | 197 | return |
| @@ -246,7 +247,7 @@ func handlePull(pullID int64, sha string) { · 49 unmodified lines | ||
| 246 | 247 | return |
| 247 | 248 | } |
| 248 | 249 | |
| 249 | − baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 250 | + baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 250 | 251 | if err != nil { |
| 251 | 252 | log.Error("OpenRepository %-v: %v", pr.BaseRepo, err) |
| 252 | 253 | return |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | access_model "code.gitea.io/gitea/models/perm/access" |
| 13 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | "code.gitea.io/gitea/modules/log" |
| 16 | 17 | api "code.gitea.io/gitea/modules/structs" |
| 17 | 18 | ) |
| @@ -101,7 +102,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u · 83 unmodified lines | ||
| 101 | 102 | apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr() |
| 102 | 103 | } |
| 103 | 104 | |
| 104 | − gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 105 | + gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 105 | 106 | if err != nil { |
| 106 | 107 | log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err) |
| 107 | 108 | return nil |
| @@ -127,7 +128,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u · 19 unmodified lines | ||
| 127 | 128 | } |
| 128 | 129 | |
| 129 | 130 | if pr.Flow == issues_model.PullRequestFlowAGit { |
| 130 | − gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 131 | + gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 131 | 132 | if err != nil { |
| 132 | 133 | log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err) |
| 133 | 134 | return nil |
| @@ -154,7 +155,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u · 20 unmodified lines | ||
| 154 | 155 | apiPullRequest.Head.RepoID = pr.HeadRepo.ID |
| 155 | 156 | apiPullRequest.Head.Repository = ToRepo(ctx, pr.HeadRepo, p) |
| 156 | 157 | |
| 157 | − headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) | |
| 158 | + headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo) | |
| 158 | 159 | if err != nil { |
| 159 | 160 | log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err) |
| 160 | 161 | return nil |
| @@ -190,7 +191,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u · 29 unmodified lines | ||
| 190 | 191 | } |
| 191 | 192 | |
| 192 | 193 | if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 { |
| 193 | − baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 194 | + baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 194 | 195 | if err != nil { |
| 195 | 196 | log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err) |
| 196 | 197 | return nil |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/repository" |
| 21 | 22 | "code.gitea.io/gitea/modules/setting" |
| @@ -91,7 +92,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool · 69 unmodified lines | ||
| 91 | 92 | |
| 92 | 93 | if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error { |
| 93 | 94 | numRepos++ |
| 94 | − r, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 95 | + r, err := gitrepo.OpenRepository(ctx, repo) | |
| 95 | 96 | if err != nil { |
| 96 | 97 | return err |
| 97 | 98 | } |
| @@ -21,6 +21,7 @@ import ( · 20 unmodified lines | ||
| 21 | 21 | user_model "code.gitea.io/gitea/models/user" |
| 22 | 22 | base_module "code.gitea.io/gitea/modules/base" |
| 23 | 23 | "code.gitea.io/gitea/modules/git" |
| 24 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 24 | 25 | "code.gitea.io/gitea/modules/label" |
| 25 | 26 | "code.gitea.io/gitea/modules/log" |
| 26 | 27 | base "code.gitea.io/gitea/modules/migration" |
| @@ -139,7 +140,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate · 112 unmodified lines | ||
| 139 | 140 | if err != nil { |
| 140 | 141 | return err |
| 141 | 142 | } |
| 142 | − g.gitRepo, err = git.OpenRepository(g.ctx, r.RepoPath()) | |
| 143 | + g.gitRepo, err = gitrepo.OpenRepository(g.ctx, r) | |
| 143 | 144 | return err |
| 144 | 145 | } |
| 145 | 146 | |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | "code.gitea.io/gitea/models/unittest" |
| 20 | 20 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 21 | "code.gitea.io/gitea/modules/git" |
| 22 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 23 | "code.gitea.io/gitea/modules/graceful" |
| 23 | 24 | "code.gitea.io/gitea/modules/log" |
| 24 | 25 | base "code.gitea.io/gitea/modules/migration" |
| @@ -249,7 +250,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) { · 224 unmodified lines | ||
| 249 | 250 | Author: &signature, |
| 250 | 251 | Message: "Initial Commit", |
| 251 | 252 | })) |
| 252 | − fromGitRepo, err := git.OpenRepository(git.DefaultContext, fromRepo.RepoPath()) | |
| 253 | + fromGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, fromRepo) | |
| 253 | 254 | assert.NoError(t, err) |
| 254 | 255 | defer fromGitRepo.Close() |
| 255 | 256 | baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef) |
| @@ -292,7 +293,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) { · 36 unmodified lines | ||
| 292 | 293 | Author: &signature, |
| 293 | 294 | Message: "branch2 commit", |
| 294 | 295 | })) |
| 295 | − forkGitRepo, err := git.OpenRepository(git.DefaultContext, forkRepo.RepoPath()) | |
| 296 | + forkGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, forkRepo) | |
| 296 | 297 | assert.NoError(t, err) |
| 297 | 298 | defer forkGitRepo.Close() |
| 298 | 299 | forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef) |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | system_model "code.gitea.io/gitea/models/system" |
| 14 | 14 | "code.gitea.io/gitea/modules/cache" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/modules/lfs" |
| 17 | 18 | "code.gitea.io/gitea/modules/log" |
| 18 | 19 | "code.gitea.io/gitea/modules/process" |
| @@ -300,7 +301,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo · 281 unmodified lines | ||
| 300 | 301 | log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err) |
| 301 | 302 | } |
| 302 | 303 | |
| 303 | − gitRepo, err := git.OpenRepository(ctx, repoPath) | |
| 304 | + gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo) | |
| 304 | 305 | if err != nil { |
| 305 | 306 | log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err) |
| 306 | 307 | return nil, false |
| @@ -396,7 +397,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo · 89 unmodified lines | ||
| 396 | 397 | } |
| 397 | 398 | |
| 398 | 399 | log.Trace("SyncMirrors [repo: %-v]: invalidating mirror branch caches...", m.Repo) |
| 399 | − branches, _, err := git.GetBranchesByPath(ctx, m.Repo.RepoPath(), 0, 0) | |
| 400 | + branches, _, err := gitrepo.GetBranchesByPath(ctx, m.Repo, 0, 0) | |
| 400 | 401 | if err != nil { |
| 401 | 402 | log.Error("SyncMirrors [repo: %-v]: failed to GetBranches: %v", m.Repo, err) |
| 402 | 403 | return nil, false |
| @@ -453,7 +454,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { · 50 unmodified lines | ||
| 453 | 454 | log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo) |
| 454 | 455 | } else { |
| 455 | 456 | log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results)) |
| 456 | − gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath()) | |
| 457 | + gitRepo, err = gitrepo.OpenRepository(ctx, m.Repo) | |
| 457 | 458 | if err != nil { |
| 458 | 459 | log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err) |
| 459 | 460 | return false |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "code.gitea.io/gitea/models/db" |
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | "code.gitea.io/gitea/modules/git" |
| 18 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 18 | 19 | "code.gitea.io/gitea/modules/lfs" |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/process" |
| @@ -131,7 +132,11 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool { · 110 unmodified lines | ||
| 131 | 132 | func runPushSync(ctx context.Context, m *repo_model.PushMirror) error { |
| 132 | 133 | timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second |
| 133 | 134 | |
| 134 | − performPush := func(path string) error { | |
| 135 | + performPush := func(repo *repo_model.Repository, isWiki bool) error { | |
| 136 | + path := repo.RepoPath() | |
| 137 | + if isWiki { | |
| 138 | + path = repo.WikiPath() | |
| 139 | + } | |
| 135 | 140 | remoteURL, err := git.GetRemoteURL(ctx, path, m.RemoteName) |
| 136 | 141 | if err != nil { |
| 137 | 142 | log.Error("GetRemoteAddress(%s) Error %v", path, err) |
| @@ -141,7 +146,12 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error { · 3 unmodified lines | ||
| 141 | 146 | if setting.LFS.StartServer { |
| 142 | 147 | log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo) |
| 143 | 148 | |
| 144 | − gitRepo, err := git.OpenRepository(ctx, path) | |
| 149 | + var gitRepo *git.Repository | |
| 150 | + if isWiki { | |
| 151 | + gitRepo, err = gitrepo.OpenWikiRepository(ctx, repo) | |
| 152 | + } else { | |
| 153 | + gitRepo, err = gitrepo.OpenRepository(ctx, repo) | |
| 154 | + } | |
| 145 | 155 | if err != nil { |
| 146 | 156 | log.Error("OpenRepository: %v", err) |
| 147 | 157 | return errors.New("Unexpected error") |
| @@ -171,16 +181,15 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error { · 23 unmodified lines | ||
| 171 | 181 | return nil |
| 172 | 182 | } |
| 173 | 183 | |
| 174 | − err := performPush(m.Repo.RepoPath()) | |
| 184 | + err := performPush(m.Repo, false) | |
| 175 | 185 | if err != nil { |
| 176 | 186 | return err |
| 177 | 187 | } |
| 178 | 188 | |
| 179 | 189 | if m.Repo.HasWiki() { |
| 180 | − wikiPath := m.Repo.WikiPath() | |
| 181 | − _, err := git.GetRemoteAddress(ctx, wikiPath, m.RemoteName) | |
| 190 | + _, err := git.GetRemoteAddress(ctx, m.Repo.WikiPath(), m.RemoteName) | |
| 182 | 191 | if err == nil { |
| 183 | − err := performPush(wikiPath) | |
| 192 | + err := performPush(m.Repo, true) | |
| 184 | 193 | if err != nil { |
| 185 | 194 | return err |
| 186 | 195 | } |
| @@ -20,6 +20,7 @@ import ( · 19 unmodified lines | ||
| 20 | 20 | "code.gitea.io/gitea/models/unit" |
| 21 | 21 | user_model "code.gitea.io/gitea/models/user" |
| 22 | 22 | "code.gitea.io/gitea/modules/git" |
| 23 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 23 | 24 | "code.gitea.io/gitea/modules/graceful" |
| 24 | 25 | "code.gitea.io/gitea/modules/log" |
| 25 | 26 | "code.gitea.io/gitea/modules/process" |
| @@ -215,7 +216,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com · 189 unmodified lines | ||
| 215 | 216 | return nil, fmt.Errorf("GetFullCommitID(%s) in %s: %w", prHeadRef, pr.BaseRepo.FullName(), err) |
| 216 | 217 | } |
| 217 | 218 | |
| 218 | − gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 219 | + gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 219 | 220 | if err != nil { |
| 220 | 221 | return nil, fmt.Errorf("%-v OpenRepository: %w", pr.BaseRepo, err) |
| 221 | 222 | } |
| @@ -9,7 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | issues_model "code.gitea.io/gitea/models/issues" |
| 10 | 10 | repo_model "code.gitea.io/gitea/models/repo" |
| 11 | 11 | user_model "code.gitea.io/gitea/models/user" |
| 12 | − "code.gitea.io/gitea/modules/git" | |
| 12 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 13 | 13 | "code.gitea.io/gitea/modules/json" |
| 14 | 14 | ) |
| 15 | 15 | |
| @@ -17,8 +17,7 @@ import ( · 1 unmodified line | ||
| 17 | 17 | // isForcePush will be true if oldCommit isn't on the branch |
| 18 | 18 | // Commit on baseBranch will skip |
| 19 | 19 | func getCommitIDsFromRepo(ctx context.Context, repo *repo_model.Repository, oldCommitID, newCommitID, baseBranch string) (commitIDs []string, isForcePush bool, err error) { |
| 20 | − repoPath := repo.RepoPath() | |
| 21 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath) | |
| 20 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 22 | 21 | if err != nil { |
| 23 | 22 | return nil, false, err |
| 24 | 23 | } |
| @@ -11,6 +11,7 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | git_model "code.gitea.io/gitea/models/git" |
| 12 | 12 | issues_model "code.gitea.io/gitea/models/issues" |
| 13 | 13 | "code.gitea.io/gitea/modules/git" |
| 14 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 14 | 15 | "code.gitea.io/gitea/modules/log" |
| 15 | 16 | "code.gitea.io/gitea/modules/structs" |
| 16 | 17 | |
| @@ -116,7 +117,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR · 99 unmodified lines | ||
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | // check if all required status checks are successful |
| 119 | − headGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath()) | |
| 120 | + headGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo) | |
| 120 | 121 | if err != nil { |
| 121 | 122 | return "", errors.Wrap(err, "OpenRepository") |
| 122 | 123 | } |
| @@ -9,6 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | repo_model "code.gitea.io/gitea/models/repo" |
| 11 | 11 | "code.gitea.io/gitea/modules/git" |
| 12 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 12 | 13 | "code.gitea.io/gitea/modules/log" |
| 13 | 14 | ) |
| 14 | 15 | |
| @@ -57,7 +58,7 @@ func doMergeRebaseFastForward(ctx *mergeContext) error { · 42 unmodified lines | ||
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | // Original repo to read template from. |
| 60 | − baseGitRepo, err := git.OpenRepository(ctx, ctx.pr.BaseRepo.RepoPath()) | |
| 61 | + baseGitRepo, err := gitrepo.OpenRepository(ctx, ctx.pr.BaseRepo) | |
| 61 | 62 | if err != nil { |
| 62 | 63 | log.Error("Unable to get Git repo for rebase: %v", err) |
| 63 | 64 | return err |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | user_model "code.gitea.io/gitea/models/user" |
| 11 | 11 | "code.gitea.io/gitea/modules/container" |
| 12 | 12 | "code.gitea.io/gitea/modules/git" |
| 13 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 13 | 14 | "code.gitea.io/gitea/modules/log" |
| 14 | 15 | "code.gitea.io/gitea/modules/setting" |
| 15 | 16 | ) |
| @@ -24,7 +25,7 @@ func getAuthorSignatureSquash(ctx *mergeContext) (*git.Signature, error) { · 8 unmodified lines | ||
| 24 | 25 | // Try to get an signature from the same user in one of the commits, as the |
| 25 | 26 | // poster email might be private or commits might have a different signature |
| 26 | 27 | // than the primary email address of the poster. |
| 27 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, ctx.tmpBasePath) | |
| 28 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpenPath(ctx, ctx.tmpBasePath) | |
| 28 | 29 | if err != nil { |
| 29 | 30 | log.Error("%-v Unable to open base repository: %v", ctx.pr, err) |
| 30 | 31 | return nil, err |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | "code.gitea.io/gitea/models/unit" |
| 20 | 20 | "code.gitea.io/gitea/modules/container" |
| 21 | 21 | "code.gitea.io/gitea/modules/git" |
| 22 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 23 | "code.gitea.io/gitea/modules/graceful" |
| 23 | 24 | "code.gitea.io/gitea/modules/log" |
| 24 | 25 | "code.gitea.io/gitea/modules/process" |
| @@ -35,7 +36,7 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io · 10 unmodified lines | ||
| 35 | 36 | return err |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) | |
| 39 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo) | |
| 39 | 40 | if err != nil { |
| 40 | 41 | return fmt.Errorf("OpenRepository: %w", err) |
| 41 | 42 | } |
| @@ -23,6 +23,7 @@ import ( · 22 unmodified lines | ||
| 23 | 23 | "code.gitea.io/gitea/modules/container" |
| 24 | 24 | gitea_context "code.gitea.io/gitea/modules/context" |
| 25 | 25 | "code.gitea.io/gitea/modules/git" |
| 26 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 26 | 27 | "code.gitea.io/gitea/modules/graceful" |
| 27 | 28 | "code.gitea.io/gitea/modules/json" |
| 28 | 29 | "code.gitea.io/gitea/modules/log" |
| @@ -62,7 +63,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss · 33 unmodified lines | ||
| 62 | 63 | assigneeCommentMap := make(map[int64]*issues_model.Comment) |
| 63 | 64 | |
| 64 | 65 | // add first push codes comment |
| 65 | − baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 66 | + baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 66 | 67 | if err != nil { |
| 67 | 68 | return err |
| 68 | 69 | } |
| @@ -269,9 +270,9 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest · 200 unmodified lines | ||
| 269 | 270 | if err != nil { |
| 270 | 271 | return fmt.Errorf("GetRepositoryByIDCtx: %w", err) |
| 271 | 272 | } |
| 272 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 273 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 273 | 274 | if err != nil { |
| 274 | − return fmt.Errorf("git.OpenRepository: %w", err) | |
| 275 | + return fmt.Errorf("gitrepo.OpenRepository: %w", err) | |
| 275 | 276 | } |
| 276 | 277 | go func() { |
| 277 | 278 | // FIXME: graceful: We need to tell the manager we're doing something... |
| @@ -614,7 +615,7 @@ func CloseBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, · 336 unmodified lines | ||
| 614 | 615 | |
| 615 | 616 | // CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository |
| 616 | 617 | func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) error { |
| 617 | − branches, _, err := git.GetBranchesByPath(ctx, repo.RepoPath(), 0, 0) | |
| 618 | + branches, _, err := gitrepo.GetBranchesByPath(ctx, repo, 0, 0) | |
| 618 | 619 | if err != nil { |
| 619 | 620 | return err |
| 620 | 621 | } |
| @@ -671,7 +672,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ · 50 unmodified lines | ||
| 671 | 672 | } |
| 672 | 673 | } |
| 673 | 674 | |
| 674 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath()) | |
| 675 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo) | |
| 675 | 676 | if err != nil { |
| 676 | 677 | log.Error("Unable to open head repository: Error: %v", err) |
| 677 | 678 | return "" |
| @@ -845,7 +846,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList · 167 unmodified lines | ||
| 845 | 846 | } |
| 846 | 847 | gitRepo, ok := gitRepos[issue.RepoID] |
| 847 | 848 | if !ok { |
| 848 | − gitRepo, err = git.OpenRepository(ctx, issue.Repo.RepoPath()) | |
| 849 | + gitRepo, err = gitrepo.OpenRepository(ctx, issue.Repo) | |
| 849 | 850 | if err != nil { |
| 850 | 851 | log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err) |
| 851 | 852 | continue |
| @@ -882,7 +883,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br · 30 unmodified lines | ||
| 882 | 883 | if err = pr.LoadBaseRepo(ctx); err != nil { |
| 883 | 884 | return false, err |
| 884 | 885 | } |
| 885 | − baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) | |
| 886 | + baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo) | |
| 886 | 887 | if err != nil { |
| 887 | 888 | return false, err |
| 888 | 889 | } |
| @@ -902,7 +903,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br · 13 unmodified lines | ||
| 902 | 903 | } else { |
| 903 | 904 | var closer io.Closer |
| 904 | 905 | |
| 905 | − headGitRepo, closer, err = git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath()) | |
| 906 | + headGitRepo, closer, err = gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo) | |
| 906 | 907 | if err != nil { |
| 907 | 908 | return false, err |
| 908 | 909 | } |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models/unit" |
| 14 | 14 | "code.gitea.io/gitea/models/unittest" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | |
| 17 | 18 | "github.com/stretchr/testify/assert" |
| 18 | 19 | ) |
| @@ -41,7 +42,7 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) { · 22 unmodified lines | ||
| 41 | 42 | pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}) |
| 42 | 43 | |
| 43 | 44 | assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext)) |
| 44 | − gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath()) | |
| 45 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo) | |
| 45 | 46 | assert.NoError(t, err) |
| 46 | 47 | defer gitRepo.Close() |
| 47 | 48 | |
| @@ -71,7 +72,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) { · 23 unmodified lines | ||
| 71 | 72 | pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo}) |
| 72 | 73 | |
| 73 | 74 | assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext)) |
| 74 | − gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath()) | |
| 75 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo) | |
| 75 | 76 | assert.NoError(t, err) |
| 76 | 77 | defer gitRepo.Close() |
| 77 | 78 | |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/setting" |
| 21 | 22 | "code.gitea.io/gitea/modules/util" |
| @@ -170,7 +171,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo · 148 unmodified lines | ||
| 170 | 171 | if err := pr.LoadBaseRepo(ctx); err != nil { |
| 171 | 172 | return nil, fmt.Errorf("LoadBaseRepo: %w", err) |
| 172 | 173 | } |
| 173 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) | |
| 174 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo) | |
| 174 | 175 | if err != nil { |
| 175 | 176 | return nil, fmt.Errorf("RepositoryFromContextOrOpen: %w", err) |
| 176 | 177 | } |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 17 | "code.gitea.io/gitea/modules/container" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/graceful" |
| 20 | 21 | "code.gitea.io/gitea/modules/log" |
| 21 | 22 | "code.gitea.io/gitea/modules/repository" |
| @@ -168,7 +169,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R · 146 unmodified lines | ||
| 168 | 169 | } |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 172 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 172 | 173 | if err != nil { |
| 173 | 174 | return err |
| 174 | 175 | } |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models/unittest" |
| 14 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/services/attachment" |
| 17 | 18 | |
| 18 | 19 | _ "code.gitea.io/gitea/models/actions" |
| @@ -29,9 +30,8 @@ func TestRelease_Create(t *testing.T) { · 10 unmodified lines | ||
| 29 | 30 | |
| 30 | 31 | user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) |
| 31 | 32 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 32 | − repoPath := repo_model.RepoPath(user.Name, repo.Name) | |
| 33 | 33 | |
| 34 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) | |
| 34 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 35 | 35 | assert.NoError(t, err) |
| 36 | 36 | defer gitRepo.Close() |
| 37 | 37 | |
| @@ -135,9 +135,8 @@ func TestRelease_Update(t *testing.T) { · 97 unmodified lines | ||
| 135 | 135 | |
| 136 | 136 | user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) |
| 137 | 137 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 138 | − repoPath := repo_model.RepoPath(user.Name, repo.Name) | |
| 139 | 138 | |
| 140 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) | |
| 139 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 141 | 140 | assert.NoError(t, err) |
| 142 | 141 | defer gitRepo.Close() |
| 143 | 142 | |
| @@ -278,9 +277,8 @@ func TestRelease_createTag(t *testing.T) { · 134 unmodified lines | ||
| 278 | 277 | |
| 279 | 278 | user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) |
| 280 | 279 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 281 | − repoPath := repo_model.RepoPath(user.Name, repo.Name) | |
| 282 | 280 | |
| 283 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) | |
| 281 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 284 | 282 | assert.NoError(t, err) |
| 285 | 283 | defer gitRepo.Close() |
| 286 | 284 | |
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/container" |
| 19 | 19 | "code.gitea.io/gitea/modules/git" |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 20 | 21 | "code.gitea.io/gitea/modules/log" |
| 21 | 22 | repo_module "code.gitea.io/gitea/modules/repository" |
| 22 | 23 | "code.gitea.io/gitea/modules/setting" |
| @@ -126,7 +127,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r · 103 unmodified lines | ||
| 126 | 127 | repo.IsEmpty = false |
| 127 | 128 | |
| 128 | 129 | // Don't bother looking this repo in the context it won't be there |
| 129 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 130 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 130 | 131 | if err != nil { |
| 131 | 132 | return fmt.Errorf("openRepository: %w", err) |
| 132 | 133 | } |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "code.gitea.io/gitea/models/db" |
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | "code.gitea.io/gitea/modules/git" |
| 18 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 18 | 19 | "code.gitea.io/gitea/modules/graceful" |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/process" |
| @@ -209,7 +210,7 @@ func doArchive(ctx context.Context, r *ArchiveRequest) (*repo_model.RepoArchiver · 188 unmodified lines | ||
| 209 | 210 | return nil, fmt.Errorf("archiver.LoadRepo failed: %w", err) |
| 210 | 211 | } |
| 211 | 212 | |
| 212 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 213 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 213 | 214 | if err != nil { |
| 214 | 215 | return nil, err |
| 215 | 216 | } |
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 19 | 19 | "code.gitea.io/gitea/modules/git" |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 20 | 21 | "code.gitea.io/gitea/modules/graceful" |
| 21 | 22 | "code.gitea.io/gitea/modules/log" |
| 22 | 23 | "code.gitea.io/gitea/modules/queue" |
| @@ -160,7 +161,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g · 137 unmodified lines | ||
| 160 | 161 | if pr.HasMerged { |
| 161 | 162 | baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID] |
| 162 | 163 | if !ok { |
| 163 | − baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) | |
| 164 | + baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo) | |
| 164 | 165 | if err != nil { |
| 165 | 166 | return nil, fmt.Errorf("OpenRepository: %v", err) |
| 166 | 167 | } |
| @@ -190,13 +191,9 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g · 23 unmodified lines | ||
| 190 | 191 | }, nil |
| 191 | 192 | } |
| 192 | 193 | |
| 193 | −func GetBranchCommitID(ctx context.Context, repo *repo_model.Repository, branch string) (string, error) { | |
| 194 | − return git.GetBranchCommitID(ctx, repo.RepoPath(), branch) | |
| 195 | −} | |
| 196 | − | |
| 197 | 194 | // checkBranchName validates branch name with existing repository branches |
| 198 | 195 | func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error { |
| 199 | − _, err := git.WalkReferences(ctx, repo.RepoPath(), func(_, refName string) error { | |
| 196 | + _, err := gitrepo.WalkReferences(ctx, repo, func(_, refName string) error { | |
| 200 | 197 | branchRefName := strings.TrimPrefix(refName, git.BranchPrefix) |
| 201 | 198 | switch { |
| 202 | 199 | case branchRefName == name: |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/options" |
| 21 | 22 | repo_module "code.gitea.io/gitea/modules/repository" |
| @@ -175,7 +176,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re · 153 unmodified lines | ||
| 175 | 176 | |
| 176 | 177 | if len(opts.DefaultBranch) > 0 { |
| 177 | 178 | repo.DefaultBranch = opts.DefaultBranch |
| 178 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 179 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 179 | 180 | if err != nil { |
| 180 | 181 | return fmt.Errorf("openRepository: %w", err) |
| 181 | 182 | } |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | repo_model "code.gitea.io/gitea/models/repo" |
| 13 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | "code.gitea.io/gitea/modules/structs" |
| 16 | 17 | "code.gitea.io/gitea/services/automerge" |
| 17 | 18 | ) |
| @@ -23,7 +24,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato · 5 unmodified lines | ||
| 23 | 24 | repoPath := repo.RepoPath() |
| 24 | 25 | |
| 25 | 26 | // confirm that commit is exist |
| 26 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 27 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 27 | 28 | if err != nil { |
| 28 | 29 | return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err) |
| 29 | 30 | } |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models" |
| 14 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/modules/setting" |
| 17 | 18 | api "code.gitea.io/gitea/modules/structs" |
| 18 | 19 | "code.gitea.io/gitea/modules/util" |
| @@ -58,7 +59,7 @@ func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, treePat · 39 unmodified lines | ||
| 58 | 59 | } |
| 59 | 60 | treePath = cleanTreePath |
| 60 | 61 | |
| 61 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 62 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 62 | 63 | if err != nil { |
| 63 | 64 | return nil, err |
| 64 | 65 | } |
| @@ -133,7 +134,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref · 68 unmodified lines | ||
| 133 | 134 | } |
| 134 | 135 | treePath = cleanTreePath |
| 135 | 136 | |
| 136 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 137 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 137 | 138 | if err != nil { |
| 138 | 139 | return nil, err |
| 139 | 140 | } |
| @@ -6,10 +6,9 @@ package files · 5 unmodified lines | ||
| 6 | 6 | import ( |
| 7 | 7 | "testing" |
| 8 | 8 | |
| 9 | − repo_model "code.gitea.io/gitea/models/repo" | |
| 10 | 9 | "code.gitea.io/gitea/models/unittest" |
| 11 | 10 | "code.gitea.io/gitea/modules/contexttest" |
| 12 | − "code.gitea.io/gitea/modules/git" | |
| 11 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 13 | 12 | api "code.gitea.io/gitea/modules/structs" |
| 14 | 13 | |
| 15 | 14 | _ "code.gitea.io/gitea/models/actions" |
| @@ -235,7 +234,7 @@ func TestGetBlobBySHA(t *testing.T) { · 219 unmodified lines | ||
| 235 | 234 | ctx.SetParams(":id", "1") |
| 236 | 235 | ctx.SetParams(":sha", sha) |
| 237 | 236 | |
| 238 | − gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) | |
| 237 | + gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | |
| 239 | 238 | if err != nil { |
| 240 | 239 | t.Fail() |
| 241 | 240 | } |
| @@ -8,7 +8,7 @@ import ( · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | "code.gitea.io/gitea/models/unittest" |
| 10 | 10 | "code.gitea.io/gitea/modules/contexttest" |
| 11 | − "code.gitea.io/gitea/modules/git" | |
| 11 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 12 | 12 | "code.gitea.io/gitea/modules/setting" |
| 13 | 13 | api "code.gitea.io/gitea/modules/structs" |
| 14 | 14 | |
| @@ -109,7 +109,7 @@ func TestGetFileResponseFromCommit(t *testing.T) { · 94 unmodified lines | ||
| 109 | 109 | repo := ctx.Repo.Repository |
| 110 | 110 | branch := repo.DefaultBranch |
| 111 | 111 | treePath := "README.md" |
| 112 | − gitRepo, _ := git.OpenRepository(ctx, repo.RepoPath()) | |
| 112 | + gitRepo, _ := gitrepo.OpenRepository(ctx, repo) | |
| 113 | 113 | defer gitRepo.Close() |
| 114 | 114 | commit, _ := gitRepo.GetBranchCommit(branch) |
| 115 | 115 | expectedFileResponse := getExpectedFileResponse() |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | "code.gitea.io/gitea/modules/log" |
| 17 | 18 | "code.gitea.io/gitea/modules/structs" |
| 18 | 19 | asymkey_service "code.gitea.io/gitea/services/asymkey" |
| @@ -42,7 +43,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode · 23 unmodified lines | ||
| 42 | 43 | opts.NewBranch = opts.OldBranch |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 46 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 46 | 47 | if err != nil { |
| 47 | 48 | return err |
| 48 | 49 | } |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/lfs" |
| 20 | 21 | "code.gitea.io/gitea/modules/log" |
| 21 | 22 | "code.gitea.io/gitea/modules/setting" |
| @@ -78,7 +79,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 56 unmodified lines | ||
| 78 | 79 | opts.NewBranch = opts.OldBranch |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | − gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) | |
| 82 | + gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo) | |
| 82 | 83 | if err != nil { |
| 83 | 84 | return nil, err |
| 84 | 85 | } |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 15 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 16 | "code.gitea.io/gitea/modules/git" |
| 17 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 18 | "code.gitea.io/gitea/modules/log" |
| 18 | 19 | repo_module "code.gitea.io/gitea/modules/repository" |
| 19 | 20 | "code.gitea.io/gitea/modules/structs" |
| @@ -167,7 +168,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork · 147 unmodified lines | ||
| 167 | 168 | return fmt.Errorf("createDelegateHooks: %w", err) |
| 168 | 169 | } |
| 169 | 170 | |
| 170 | − gitRepo, err := git.OpenRepository(txCtx, repo.RepoPath()) | |
| 171 | + gitRepo, err := gitrepo.OpenRepository(txCtx, repo) | |
| 171 | 172 | if err != nil { |
| 172 | 173 | return fmt.Errorf("OpenRepository: %w", err) |
| 173 | 174 | } |
| @@ -190,7 +191,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork · 16 unmodified lines | ||
| 190 | 191 | log.Error("Copy language stat from oldRepo failed: %v", err) |
| 191 | 192 | } |
| 192 | 193 | |
| 193 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 194 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 194 | 195 | if err != nil { |
| 195 | 196 | log.Error("Open created git repository failed: %v", err) |
| 196 | 197 | } else { |
| @@ -10,7 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "code.gitea.io/gitea/models/db" |
| 11 | 11 | repo_model "code.gitea.io/gitea/models/repo" |
| 12 | 12 | "code.gitea.io/gitea/models/webhook" |
| 13 | − "code.gitea.io/gitea/modules/git" | |
| 13 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 14 | 14 | "code.gitea.io/gitea/modules/log" |
| 15 | 15 | repo_module "code.gitea.io/gitea/modules/repository" |
| 16 | 16 | |
| @@ -52,13 +52,13 @@ func SyncRepositoryHooks(ctx context.Context) error { · 35 unmodified lines | ||
| 52 | 52 | |
| 53 | 53 | // GenerateGitHooks generates git hooks from a template repository |
| 54 | 54 | func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error { |
| 55 | − generateGitRepo, err := git.OpenRepository(ctx, generateRepo.RepoPath()) | |
| 55 | + generateGitRepo, err := gitrepo.OpenRepository(ctx, generateRepo) | |
| 56 | 56 | if err != nil { |
| 57 | 57 | return err |
| 58 | 58 | } |
| 59 | 59 | defer generateGitRepo.Close() |
| 60 | 60 | |
| 61 | − templateGitRepo, err := git.OpenRepository(ctx, templateRepo.RepoPath()) | |
| 61 | + templateGitRepo, err := gitrepo.OpenRepository(ctx, templateRepo) | |
| 62 | 62 | if err != nil { |
| 63 | 63 | return err |
| 64 | 64 | } |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | git_model "code.gitea.io/gitea/models/git" |
| 13 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | "code.gitea.io/gitea/modules/lfs" |
| 16 | 17 | "code.gitea.io/gitea/modules/log" |
| 17 | 18 | "code.gitea.io/gitea/modules/setting" |
| @@ -69,7 +70,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R · 51 unmodified lines | ||
| 69 | 70 | } |
| 70 | 71 | }() |
| 71 | 72 | |
| 72 | − gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) | |
| 73 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 73 | 74 | if err != nil { |
| 74 | 75 | log.Error("Unable to open git repository %-v: %v", repo, err) |
| 75 | 76 | return err |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 17 | "code.gitea.io/gitea/modules/cache" |
| 18 | 18 | "code.gitea.io/gitea/modules/git" |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 19 | 20 | "code.gitea.io/gitea/modules/graceful" |
| 20 | 21 | "code.gitea.io/gitea/modules/log" |
| 21 | 22 | "code.gitea.io/gitea/modules/process" |
| @@ -86,17 +87,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { · 64 unmodified lines | ||
| 86 | 87 | return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err) |
| 87 | 88 | } |
| 88 | 89 | |
| 89 | − repoPath := repo.RepoPath() | |
| 90 | − | |
| 91 | − gitRepo, err := git.OpenRepository(ctx, repoPath) | |
| 90 | + gitRepo, err := gitrepo.OpenRepository(ctx, repo) | |
| 92 | 91 | if err != nil { |
| 93 | − return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err) | |
| 92 | + return fmt.Errorf("OpenRepository[%s]: %w", repo.FullName(), err) | |
| 94 | 93 | } |
| 95 | 94 | defer gitRepo.Close() |
| 96 | 95 | |
| 97 | 96 | objectFormat, err := gitRepo.GetObjectFormat() |
| 98 | 97 | if err != nil { |
| 99 | − return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repoPath, err) | |
| 98 | + return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repo.FullName(), err) | |
| 100 | 99 | } |
| 101 | 100 | |
| 102 | 101 | if err = repo_module.UpdateRepoSize(ctx, repo); err != nil { |
| @@ -191,7 +191,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model · 190 unmodified lines | ||
| 191 | 191 | |
| 192 | 192 | committer := doer.NewGitSig() |
| 193 | 193 | |
| 194 | − sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer) | |
| 194 | + sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer) | |
| 195 | 195 | if sign { |
| 196 | 196 | commitTreeOpts.KeyID = signingKey |
| 197 | 197 | if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { |
| @@ -314,7 +314,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model · 116 unmodified lines | ||
| 314 | 314 | |
| 315 | 315 | committer := doer.NewGitSig() |
| 316 | 316 | |
| 317 | − sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer) | |
| 317 | + sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer) | |
| 318 | 318 | if sign { |
| 319 | 319 | commitTreeOpts.KeyID = signingKey |
| 320 | 320 | if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "code.gitea.io/gitea/models/unittest" |
| 13 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | |
| 16 | 17 | _ "code.gitea.io/gitea/models/actions" |
| 17 | 18 | |
| @@ -164,7 +165,7 @@ func TestRepository_AddWikiPage(t *testing.T) { · 146 unmodified lines | ||
| 164 | 165 | webPath := UserTitleToWebPath("", userTitle) |
| 165 | 166 | assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg)) |
| 166 | 167 | // Now need to show that the page has been added: |
| 167 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) | |
| 168 | + gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) | |
| 168 | 169 | if !assert.NoError(t, err) { |
| 169 | 170 | return |
| 170 | 171 | } |
| @@ -212,7 +213,7 @@ func TestRepository_EditWikiPage(t *testing.T) { · 41 unmodified lines | ||
| 212 | 213 | assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg)) |
| 213 | 214 | |
| 214 | 215 | // Now need to show that the page has been added: |
| 215 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) | |
| 216 | + gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) | |
| 216 | 217 | assert.NoError(t, err) |
| 217 | 218 | masterTree, err := gitRepo.GetTree(DefaultBranch) |
| 218 | 219 | assert.NoError(t, err) |
| @@ -236,7 +237,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) { · 17 unmodified lines | ||
| 236 | 237 | assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home")) |
| 237 | 238 | |
| 238 | 239 | // Now need to show that the page has been added: |
| 239 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) | |
| 240 | + gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) | |
| 240 | 241 | if !assert.NoError(t, err) { |
| 241 | 242 | return |
| 242 | 243 | } |
| @@ -251,7 +252,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) { · 8 unmodified lines | ||
| 251 | 252 | func TestPrepareWikiFileName(t *testing.T) { |
| 252 | 253 | unittest.PrepareTestEnv(t) |
| 253 | 254 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 254 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) | |
| 255 | + gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) | |
| 255 | 256 | if !assert.NoError(t, err) { |
| 256 | 257 | return |
| 257 | 258 | } |
| @@ -18,7 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | repo_model "code.gitea.io/gitea/models/repo" |
| 19 | 19 | "code.gitea.io/gitea/models/unittest" |
| 20 | 20 | user_model "code.gitea.io/gitea/models/user" |
| 21 | − "code.gitea.io/gitea/modules/git" | |
| 21 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 22 | "code.gitea.io/gitea/modules/json" |
| 23 | 23 | cargo_module "code.gitea.io/gitea/modules/packages/cargo" |
| 24 | 24 | "code.gitea.io/gitea/modules/setting" |
| @@ -78,7 +78,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) { · 53 unmodified lines | ||
| 78 | 78 | assert.NoError(t, err) |
| 79 | 79 | |
| 80 | 80 | readGitContent := func(t *testing.T, path string) string { |
| 81 | − gitRepo, err := git.OpenRepository(db.DefaultContext, repo.RepoPath()) | |
| 81 | + gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo) | |
| 82 | 82 | assert.NoError(t, err) |
| 83 | 83 | defer gitRepo.Close() |
| 84 | 84 | |
| @@ -18,6 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | "code.gitea.io/gitea/models/unittest" |
| 19 | 19 | user_model "code.gitea.io/gitea/models/user" |
| 20 | 20 | "code.gitea.io/gitea/modules/git" |
| 21 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 21 | 22 | api "code.gitea.io/gitea/modules/structs" |
| 22 | 23 | "code.gitea.io/gitea/tests" |
| 23 | 24 | |
| @@ -109,7 +110,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) { · 85 unmodified lines | ||
| 109 | 110 | session := loginUser(t, owner.LowerName) |
| 110 | 111 | token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) |
| 111 | 112 | |
| 112 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 113 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 113 | 114 | assert.NoError(t, err) |
| 114 | 115 | defer gitRepo.Close() |
| 115 | 116 | |
| @@ -172,7 +173,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) { · 56 unmodified lines | ||
| 172 | 173 | session := loginUser(t, owner.LowerName) |
| 173 | 174 | token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) |
| 174 | 175 | |
| 175 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 176 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 176 | 177 | assert.NoError(t, err) |
| 177 | 178 | defer gitRepo.Close() |
| 178 | 179 | |
| @@ -18,7 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | "code.gitea.io/gitea/models/unittest" |
| 19 | 19 | user_model "code.gitea.io/gitea/models/user" |
| 20 | 20 | "code.gitea.io/gitea/modules/context" |
| 21 | − "code.gitea.io/gitea/modules/git" | |
| 21 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 22 | 22 | "code.gitea.io/gitea/modules/setting" |
| 23 | 23 | api "code.gitea.io/gitea/modules/structs" |
| 24 | 24 | |
| @@ -167,7 +167,7 @@ func TestAPICreateFile(t *testing.T) { · 142 unmodified lines | ||
| 167 | 167 | req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). |
| 168 | 168 | AddTokenAuth(token2) |
| 169 | 169 | resp := MakeRequest(t, req, http.StatusCreated) |
| 170 | − gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath()) | |
| 170 | + gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1) | |
| 171 | 171 | commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName) |
| 172 | 172 | latestCommit, _ := gitRepo.GetCommitByPath(treePath) |
| 173 | 173 | expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String()) |
| @@ -285,7 +285,7 @@ func TestAPICreateFile(t *testing.T) { · 111 unmodified lines | ||
| 285 | 285 | AddTokenAuth(token2) |
| 286 | 286 | resp = MakeRequest(t, req, http.StatusCreated) |
| 287 | 287 | emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo |
| 288 | − gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath()) | |
| 288 | + gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo) | |
| 289 | 289 | commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName) |
| 290 | 290 | latestCommit, _ := gitRepo.GetCommitByPath(treePath) |
| 291 | 291 | expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String()) |
| @@ -17,7 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | "code.gitea.io/gitea/models/unittest" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 19 | 19 | "code.gitea.io/gitea/modules/context" |
| 20 | − "code.gitea.io/gitea/modules/git" | |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 21 | 21 | "code.gitea.io/gitea/modules/setting" |
| 22 | 22 | api "code.gitea.io/gitea/modules/structs" |
| 23 | 23 | |
| @@ -135,7 +135,7 @@ func TestAPIUpdateFile(t *testing.T) { · 111 unmodified lines | ||
| 135 | 135 | req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). |
| 136 | 136 | AddTokenAuth(token2) |
| 137 | 137 | resp := MakeRequest(t, req, http.StatusOK) |
| 138 | − gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath()) | |
| 138 | + gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1) | |
| 139 | 139 | commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName) |
| 140 | 140 | lasCommit, _ := gitRepo.GetCommitByPath(treePath) |
| 141 | 141 | expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String()) |
| @@ -16,7 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | "code.gitea.io/gitea/models/unittest" |
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | "code.gitea.io/gitea/modules/context" |
| 19 | − "code.gitea.io/gitea/modules/git" | |
| 19 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 20 | 20 | "code.gitea.io/gitea/modules/setting" |
| 21 | 21 | api "code.gitea.io/gitea/modules/structs" |
| 22 | 22 | |
| @@ -96,7 +96,7 @@ func TestAPIChangeFiles(t *testing.T) { · 73 unmodified lines | ||
| 96 | 96 | req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions). |
| 97 | 97 | AddTokenAuth(token2) |
| 98 | 98 | resp := MakeRequest(t, req, http.StatusCreated) |
| 99 | − gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath()) | |
| 99 | + gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1) | |
| 100 | 100 | commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName) |
| 101 | 101 | createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath) |
| 102 | 102 | updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath) |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | "code.gitea.io/gitea/models/unittest" |
| 15 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 16 | "code.gitea.io/gitea/modules/git" |
| 17 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 18 | "code.gitea.io/gitea/modules/setting" |
| 18 | 19 | api "code.gitea.io/gitea/modules/structs" |
| 19 | 20 | repo_service "code.gitea.io/gitea/services/repository" |
| @@ -71,7 +72,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { · 51 unmodified lines | ||
| 71 | 72 | token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) |
| 72 | 73 | |
| 73 | 74 | // Get the commit ID of the default branch |
| 74 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath()) | |
| 75 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1) | |
| 75 | 76 | assert.NoError(t, err) |
| 76 | 77 | defer gitRepo.Close() |
| 77 | 78 | |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | "code.gitea.io/gitea/models/unittest" |
| 15 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 16 | "code.gitea.io/gitea/modules/git" |
| 17 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 18 | "code.gitea.io/gitea/modules/setting" |
| 18 | 19 | api "code.gitea.io/gitea/modules/structs" |
| 19 | 20 | repo_service "code.gitea.io/gitea/services/repository" |
| @@ -73,7 +74,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) { · 53 unmodified lines | ||
| 73 | 74 | token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) |
| 74 | 75 | |
| 75 | 76 | // Get the commit ID of the default branch |
| 76 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath()) | |
| 77 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1) | |
| 77 | 78 | assert.NoError(t, err) |
| 78 | 79 | defer gitRepo.Close() |
| 79 | 80 | |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/models/unittest" |
| 14 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 16 | 17 | api "code.gitea.io/gitea/modules/structs" |
| 17 | 18 | "code.gitea.io/gitea/modules/util" |
| 18 | 19 | "code.gitea.io/gitea/tests" |
| @@ -32,7 +33,7 @@ func TestAPIGitTags(t *testing.T) { · 13 unmodified lines | ||
| 32 | 33 | _ = git.NewCommand(git.DefaultContext, "config", "user.name").AddDynamicArguments(user.Name).Run(&git.RunOpts{Dir: repo.RepoPath()}) |
| 33 | 34 | _ = git.NewCommand(git.DefaultContext, "config", "user.email").AddDynamicArguments(user.Email).Run(&git.RunOpts{Dir: repo.RepoPath()}) |
| 34 | 35 | |
| 35 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 36 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 36 | 37 | defer gitRepo.Close() |
| 37 | 38 | |
| 38 | 39 | commit, _ := gitRepo.GetBranchCommit("master") |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "code.gitea.io/gitea/models/unittest" |
| 13 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 14 | "code.gitea.io/gitea/modules/git" |
| 15 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 15 | 16 | "code.gitea.io/gitea/modules/migration" |
| 16 | 17 | "code.gitea.io/gitea/modules/repository" |
| 17 | 18 | mirror_service "code.gitea.io/gitea/services/mirror" |
| @@ -54,7 +55,7 @@ func TestMirrorPull(t *testing.T) { · 36 unmodified lines | ||
| 54 | 55 | mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil) |
| 55 | 56 | assert.NoError(t, err) |
| 56 | 57 | |
| 57 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) | |
| 58 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 58 | 59 | assert.NoError(t, err) |
| 59 | 60 | defer gitRepo.Close() |
| 60 | 61 | |
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 18 | gitea_context "code.gitea.io/gitea/modules/context" |
| 19 | 19 | "code.gitea.io/gitea/modules/git" |
| 20 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 20 | 21 | "code.gitea.io/gitea/modules/setting" |
| 21 | 22 | "code.gitea.io/gitea/services/migrations" |
| 22 | 23 | mirror_service "code.gitea.io/gitea/services/mirror" |
| @@ -55,14 +56,14 @@ func testMirrorPush(t *testing.T, u *url.URL) { · 32 unmodified lines | ||
| 55 | 56 | ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID) |
| 56 | 57 | assert.True(t, ok) |
| 57 | 58 | |
| 58 | − srcGitRepo, err := git.OpenRepository(git.DefaultContext, srcRepo.RepoPath()) | |
| 59 | + srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo) | |
| 59 | 60 | assert.NoError(t, err) |
| 60 | 61 | defer srcGitRepo.Close() |
| 61 | 62 | |
| 62 | 63 | srcCommit, err := srcGitRepo.GetBranchCommit("master") |
| 63 | 64 | assert.NoError(t, err) |
| 64 | 65 | |
| 65 | − mirrorGitRepo, err := git.OpenRepository(git.DefaultContext, mirrorRepo.RepoPath()) | |
| 66 | + mirrorGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, mirrorRepo) | |
| 66 | 67 | assert.NoError(t, err) |
| 67 | 68 | defer mirrorGitRepo.Close() |
| 68 | 69 | |
| @@ -25,6 +25,7 @@ import ( · 24 unmodified lines | ||
| 25 | 25 | user_model "code.gitea.io/gitea/models/user" |
| 26 | 26 | "code.gitea.io/gitea/models/webhook" |
| 27 | 27 | "code.gitea.io/gitea/modules/git" |
| 28 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 28 | 29 | api "code.gitea.io/gitea/modules/structs" |
| 29 | 30 | "code.gitea.io/gitea/modules/test" |
| 30 | 31 | "code.gitea.io/gitea/modules/translation" |
| @@ -255,7 +256,7 @@ func TestCantMergeConflict(t *testing.T) { · 224 unmodified lines | ||
| 255 | 256 | BaseBranch: "base", |
| 256 | 257 | }) |
| 257 | 258 | |
| 258 | − gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name)) | |
| 259 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1) | |
| 259 | 260 | assert.NoError(t, err) |
| 260 | 261 | |
| 261 | 262 | err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false) |
| @@ -348,7 +349,7 @@ func TestCantMergeUnrelated(t *testing.T) { · 86 unmodified lines | ||
| 348 | 349 | session.MakeRequest(t, req, http.StatusCreated) |
| 349 | 350 | |
| 350 | 351 | // Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point... |
| 351 | − gitRepo, err := git.OpenRepository(git.DefaultContext, path) | |
| 352 | + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1) | |
| 352 | 353 | assert.NoError(t, err) |
| 353 | 354 | pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ |
| 354 | 355 | HeadRepoID: repo1.ID, |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | "code.gitea.io/gitea/models/unittest" |
| 15 | 15 | "code.gitea.io/gitea/modules/contexttest" |
| 16 | 16 | "code.gitea.io/gitea/modules/git" |
| 17 | + "code.gitea.io/gitea/modules/gitrepo" | |
| 17 | 18 | "code.gitea.io/gitea/modules/setting" |
| 18 | 19 | api "code.gitea.io/gitea/modules/structs" |
| 19 | 20 | files_service "code.gitea.io/gitea/services/repository/files" |
| @@ -262,7 +263,7 @@ func TestChangeRepoFilesForCreate(t *testing.T) { · 242 unmodified lines | ||
| 262 | 263 | |
| 263 | 264 | // asserts |
| 264 | 265 | assert.NoError(t, err) |
| 265 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 266 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 266 | 267 | defer gitRepo.Close() |
| 267 | 268 | |
| 268 | 269 | commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch) |
| @@ -299,7 +300,7 @@ func TestChangeRepoFilesForUpdate(t *testing.T) { · 30 unmodified lines | ||
| 299 | 300 | |
| 300 | 301 | // asserts |
| 301 | 302 | assert.NoError(t, err) |
| 302 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 303 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 303 | 304 | defer gitRepo.Close() |
| 304 | 305 | |
| 305 | 306 | commit, _ := gitRepo.GetBranchCommit(opts.NewBranch) |
| @@ -335,7 +336,7 @@ func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) { · 29 unmodified lines | ||
| 335 | 336 | |
| 336 | 337 | // asserts |
| 337 | 338 | assert.NoError(t, err) |
| 338 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 339 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 339 | 340 | defer gitRepo.Close() |
| 340 | 341 | |
| 341 | 342 | commit, _ := gitRepo.GetBranchCommit(opts.NewBranch) |
| @@ -386,7 +387,7 @@ func TestChangeRepoFilesWithoutBranchNames(t *testing.T) { · 44 unmodified lines | ||
| 386 | 387 | |
| 387 | 388 | // asserts |
| 388 | 389 | assert.NoError(t, err) |
| 389 | − gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) | |
| 390 | + gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo) | |
| 390 | 391 | defer gitRepo.Close() |
| 391 | 392 | |
| 392 | 393 | commit, _ := gitRepo.GetBranchCommit(repo.DefaultBranch) |