aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_tree_gogit.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-12 12:21:27 +0800
committerGitHub <noreply@github.com>2024-03-12 04:21:27 +0000
commite84e5db6de0306d514b1f1a9657931fb7197a188 (patch)
tree98baff1bb68b2af272e32b74abaa721523c2e519 /modules/git/repo_tree_gogit.go
parent7f856d5d742dcb6febdb8a3f22cd9a8fecc69a4d (diff)
downloadgitea-e84e5db6de0306d514b1f1a9657931fb7197a188.tar.gz
gitea-e84e5db6de0306d514b1f1a9657931fb7197a188.zip
Lazy load object format with command line and don't do it in OpenRepository (#29712)
Most time, when invoking `git.OpenRepository`, `objectFormat` will not be used, so it's a waste to invoke commandline to get the object format. This PR make it a lazy operation, only invoke that when necessary.
Diffstat (limited to 'modules/git/repo_tree_gogit.go')
-rw-r--r--modules/git/repo_tree_gogit.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/git/repo_tree_gogit.go b/modules/git/repo_tree_gogit.go
index 6391959e6a..dc97ce1344 100644
--- a/modules/git/repo_tree_gogit.go
+++ b/modules/git/repo_tree_gogit.go
@@ -21,7 +21,12 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
// GetTree find the tree object in the repository.
func (repo *Repository) GetTree(idStr string) (*Tree, error) {
- if len(idStr) != repo.objectFormat.FullLength() {
+ objectFormat, err := repo.GetObjectFormat()
+ if err != nil {
+ return nil, err
+ }
+
+ if len(idStr) != objectFormat.FullLength() {
res, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify").AddDynamicArguments(idStr).RunStdString(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err