-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify how git repositories are opened #28937
Conversation
…epositories, use the method on repository module package. For others, use git.OpenRepository as before
I think it's a good idea to do this; however, I'm afraid it's not enough. The package
I believe all of them should be removed to prevent misuse and keep only |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've no idea about whether the design is good enough, some points look really strange to me.
But at least, I do not think it is right to introduce a dependency between modules/gitrepo
and models/repo
. Isn't there already a guideline saying to avoid making modules
calls models
? To make the code maintainable, it could use some interfaces, eg: interface { GitRepoStoragePath() string }
@wxiaoguang @delvh Introduce an interface respository and removed the dependency on respotiroy package. |
There is no design currently. It's just refactor to move all managed git repositories operations into the single package to make further implementation easier. |
* giteaofficial/main: [skip ci] Updated licenses and gitignores Fix bug for generated repository object format (go-gitea#28969) Fixing small space missing in sample config file (go-gitea#28967) Fix inconsistent naming of OAuth 2.0 `ENABLE` setting (go-gitea#28951) Add screenshot for "Profile Readmes" to docs (go-gitea#28964) Simplify how git repositories are opened (go-gitea#28937) Preserve BOM in web editor (go-gitea#28935) Make loading animation less aggressive (go-gitea#28955) Fix SSPI user creation (go-gitea#28948) Strip `/` from relative links (go-gitea#28932) Fix non-alphabetic sorting of repo topics (go-gitea#28938) Don't remove all mirror repository's releases when mirroring (go-gitea#28817) Use new RPM constants (go-gitea#28931) Check for sha256 support to use --object-format flag (go-gitea#28928) fix: update enable_prune even if mirror_interval is not provided (go-gitea#28905) Implement `MigrateRepository` for the actions notifier (go-gitea#28920) Respect branch info for relative links (go-gitea#28909)
## 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. go-gitea#28940 - Remove the `RepoPath()`/`WikiPath()` functions to reduce the possibility of mistakes. --------- Co-authored-by: delvh <dev.lh@web.de>
## 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. go-gitea#28940 - Remove the `RepoPath()`/`WikiPath()` functions to reduce the possibility of mistakes. --------- Co-authored-by: delvh <dev.lh@web.de>
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:
Gitea managed repositories having a record in the database in the
repository
table are moved into the new packagegitrepo
: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
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. Move git command run on a special repository to standalone methods to hide the implemention detail #28940RepoPath()
/WikiPath()
functions to reduce the possibility of mistakes.