Skip to content

Commit 2e426d2

Browse files
brechtvltechknowlogick
authored andcommitted
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.
1 parent 3d8412d commit 2e426d2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

services/pull/temp_repo.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
6767
remoteRepoName := "head_repo"
6868
baseBranch := "base"
6969

70+
fetchArgs := git.TrustedCmdArgs{"--no-tags"}
71+
if git.CheckGitVersionAtLeast("2.25.0") == nil {
72+
// Writing the commit graph can be slow and is not needed here
73+
fetchArgs = append(fetchArgs, "--no-write-commit-graph")
74+
}
75+
7076
// Add head repo remote.
7177
addCacheRepo := func(staging, cache string) error {
7278
p := filepath.Join(staging, ".git", "objects", "info", "alternates")
@@ -108,7 +114,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
108114
outbuf.Reset()
109115
errbuf.Reset()
110116

111-
if err := git.NewCommand(ctx, "fetch", "origin", "--no-tags").AddDashesAndList(pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).
117+
if err := git.NewCommand(ctx, "fetch", "origin").AddArguments(fetchArgs...).AddDashesAndList(pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).
112118
Run(&git.RunOpts{
113119
Dir: tmpBasePath,
114120
Stdout: &outbuf,
@@ -171,7 +177,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
171177
} else {
172178
headBranch = pr.GetGitRefName()
173179
}
174-
if err := git.NewCommand(ctx, "fetch", "--no-tags").AddDynamicArguments(remoteRepoName, headBranch+":"+trackingBranch).
180+
if err := git.NewCommand(ctx, "fetch").AddArguments(fetchArgs...).AddDynamicArguments(remoteRepoName, headBranch+":"+trackingBranch).
175181
Run(&git.RunOpts{
176182
Dir: tmpBasePath,
177183
Stdout: &outbuf,

0 commit comments

Comments
 (0)