From 5d3214e24686506538cd4aeab0ce7f8ee56c0ea9 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 1 Mar 2023 20:19:04 +0100 Subject: [PATCH 1/2] Do not create commit graph for temporary repos (#23219) When fetching remotes for conflict checking, skip unnecessary and potentially slow writing of commit graphs. In a test with the Blender repository, this reduces conflict checking time for one pull request from about 2s to 0.1s. --- services/pull/temp_repo.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index 4bc397cd4cabf..79d29fb7874a8 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -68,6 +68,12 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str remoteRepoName := "head_repo" baseBranch := "base" + fetchArgs := git.TrustedCmdArgs{"--no-tags"} + if git.CheckGitVersionAtLeast("2.25.0") == nil { + // Writing the commit graph can be slow and is not needed here + fetchArgs = append(fetchArgs, "--no-write-commit-graph") + } + // Add head repo remote. addCacheRepo := func(staging, cache string) error { p := filepath.Join(staging, ".git", "objects", "info", "alternates") @@ -109,7 +115,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str outbuf.Reset() errbuf.Reset() - if err := git.NewCommand(ctx, "fetch", "origin", "--no-tags").AddDashesAndList(pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch). + if err := git.NewCommand(ctx, "fetch", "origin").AddArguments(fetchArgs...).AddDashesAndList(pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch). Run(&git.RunOpts{ Dir: tmpBasePath, Stdout: &outbuf, @@ -172,7 +178,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str } else { headBranch = pr.GetGitRefName() } - if err := git.NewCommand(ctx, "fetch", "--no-tags").AddDynamicArguments(remoteRepoName, headBranch+":"+trackingBranch). + if err := git.NewCommand(ctx, "fetch").AddArguments(fetchArgs...).AddDynamicArguments(remoteRepoName, headBranch+":"+trackingBranch). Run(&git.RunOpts{ Dir: tmpBasePath, Stdout: &outbuf, From 25500764cbe3d1ab6f1c9e24a58977ebe03417a5 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 4 Mar 2023 19:19:14 +0000 Subject: [PATCH 2/2] Fix backport for v1.18 Signed-off-by: Andrew Thornton --- services/pull/temp_repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index 79d29fb7874a8..a3cac90aa3f3b 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -68,7 +68,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str remoteRepoName := "head_repo" baseBranch := "base" - fetchArgs := git.TrustedCmdArgs{"--no-tags"} + fetchArgs := []git.CmdArg{"--no-tags"} if git.CheckGitVersionAtLeast("2.25.0") == nil { // Writing the commit graph can be slow and is not needed here fetchArgs = append(fetchArgs, "--no-write-commit-graph")