perf(repo): fetch the initial commit instead of pushing it (#39628)

Creating a repository with an initial commit, via `auto_init` or a
template with git content, pushed that commit through receive-pack and
three server-side hooks that do nothing for this internal push except
refresh server info. Fetching it into the bare repository instead makes
such repository creation about 3.7x faster locally (median 790ms to
214ms). E2E tests that create initialized repositories get about
0.2-0.3s faster each.

1. Run `update-server-info` after template content generation, which the
push's `post-receive` hook did before.
2. Remove the now unused `InternalPushingEnvironment` and
`PushOptions.LocalRefName`.
This commit is contained in:
silverwind authored and GitHub committed 2026-10-06 14:39:36 +00:00
1 parent a835fd78d1
commit 20ea3e204d
6 files changed
+25 -54

No files matched your search

+4 -9
View File
@@ -13,8 +13,8 @@ import (
user_model "gitea.dev/models/user"
"gitea.dev/modules/git"
"gitea.dev/modules/git/gitcmd"
"gitea.dev/modules/git/gitrepo"
"gitea.dev/modules/log"
repo_module "gitea.dev/modules/repository"
asymkey_service "gitea.dev/services/asymkey"
)
@@ -67,14 +67,9 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
return fmt.Errorf("git commit: %w", err)
}
if err := git.PushFromLocal(ctx, tmpPath, repo, git.PushOptions{
LocalRefName: "HEAD",
Branch: repo.DefaultBranch,
Env: repo_module.InternalPushingEnvironment(u, repo),
}); err != nil {
log.Error("Failed to push back to HEAD Error: %v", err)
return fmt.Errorf("git push: %w", err)
if err := git.FetchRemoteCommitUpdateRef(ctx, repo, gitrepo.RepositoryUnmanaged(tmpPath), "HEAD", git.BranchPrefix+repo.DefaultBranch); err != nil {
log.Error("Failed to fetch initial commit: %v", err)
return fmt.Errorf("git fetch: %w", err)
}
return nil
}
+6 -6
View File
@@ -128,12 +128,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
return nil, fmt.Errorf("createDelegateHooks: %w", err)
}
// 4 - Update the git repository
if err = updateGitRepoAfterCreate(ctx, generateRepo); err != nil {
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
}
// 5 - generate the repository contents according to the template
// 4 - generate the repository contents according to the template
// Git Content
if opts.GitContent && !templateRepo.IsEmpty {
if err = GenerateGitContent(ctx, templateRepo, generateRepo); err != nil {
@@ -182,6 +177,11 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
}
}
// 5 - Update the git repository
if err = updateGitRepoAfterCreate(ctx, generateRepo); err != nil {
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
}
// 6 - update repository status to be ready
generateRepo.Status = repo_model.RepositoryReady
if err = repo_model.UpdateRepositoryColsWithAutoTime(ctx, generateRepo, "status"); err != nil {