Skip to content

Commit c241859

Browse files
committed
Attempt to speed up pull request conflict checking
By skipping fetch from the head repository, and instead using the ref that we already assume exists in the base repository.
1 parent ebd172d commit c241859

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

services/pull/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func testPR(id int64) {
357357
return
358358
}
359359

360-
if err := TestPatch(pr); err != nil {
360+
if err := TestPatch(pr, true); err != nil {
361361
log.Error("testPatch[%-v]: %v", pr, err)
362362
pr.Status = issues_model.PullRequestStatusError
363363
if err := pr.UpdateCols("status"); err != nil {

services/pull/merge_prepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (ctx *mergeContext) RunOpts() *git.RunOpts {
4545

4646
func createTemporaryRepoForMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, expectedHeadCommitID string) (mergeCtx *mergeContext, cancel context.CancelFunc, err error) {
4747
// Clone base repo.
48-
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr)
48+
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr, false)
4949
if err != nil {
5050
log.Error("createTemporaryRepoForPR: %v", err)
5151
return nil, cancel, err

services/pull/patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ var patchErrorSuffices = []string{
5858
}
5959

6060
// TestPatch will test whether a simple patch will apply
61-
func TestPatch(pr *issues_model.PullRequest) error {
61+
func TestPatch(pr *issues_model.PullRequest, skipHeadRepoFetch bool) error {
6262
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("TestPatch: %s", pr))
6363
defer finished()
6464

6565
// Clone base repo.
66-
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr)
66+
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr, skipHeadRepoFetch)
6767
if err != nil {
6868
log.Error("createTemporaryRepoForPR %-v: %v", pr, err)
6969
return err

services/pull/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var pullWorkingPool = sync.NewExclusivePool()
3636

3737
// NewPullRequest creates new pull request with labels for repository.
3838
func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs []int64) error {
39-
if err := TestPatch(pr); err != nil {
39+
if err := TestPatch(pr, false); err != nil {
4040
return err
4141
}
4242

@@ -190,7 +190,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
190190
pr.BaseBranch = targetBranch
191191

192192
// Refresh patch
193-
if err := TestPatch(pr); err != nil {
193+
if err := TestPatch(pr, false); err != nil {
194194
return err
195195
}
196196

@@ -350,7 +350,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
350350
// checkIfPRContentChanged checks if diff to target branch has changed by push
351351
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
352352
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
353-
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr)
353+
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr, false)
354354
if err != nil {
355355
log.Error("CreateTemporaryRepoForPR %-v: %v", pr, err)
356356
return false, err

services/pull/temp_repo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (ctx *prContext) RunOpts() *git.RunOpts {
4747

4848
// createTemporaryRepoForPR creates a temporary repo with "base" for pr.BaseBranch and "tracking" for pr.HeadBranch
4949
// it also create a second base branch called "original_base"
50-
func createTemporaryRepoForPR(ctx context.Context, pr *issues_model.PullRequest) (prCtx *prContext, cancel context.CancelFunc, err error) {
50+
func createTemporaryRepoForPR(ctx context.Context, pr *issues_model.PullRequest, skipHeadRepoFetch bool) (prCtx *prContext, cancel context.CancelFunc, err error) {
5151
if err := pr.LoadHeadRepo(ctx); err != nil {
5252
log.Error("%-v LoadHeadRepo: %v", pr, err)
5353
return nil, nil, fmt.Errorf("%v LoadHeadRepo: %w", pr, err)
@@ -171,7 +171,15 @@ func createTemporaryRepoForPR(ctx context.Context, pr *issues_model.PullRequest)
171171
// Fetch head branch
172172
var headBranch string
173173
if pr.Flow == issues_model.PullRequestFlowGithub {
174-
headBranch = git.BranchPrefix + pr.HeadBranch
174+
if skipHeadRepoFetch {
175+
// Blender: for conflict checking on changes to the base branch, skip slow
176+
// fetching from the head repository and instead use the ref that already
177+
// exists in the base repository.
178+
headBranch = pr.GetGitRefName()
179+
remoteRepoName = "origin"
180+
} else {
181+
headBranch = git.BranchPrefix + pr.HeadBranch
182+
}
175183
} else if len(pr.HeadCommitID) == git.SHAFullLength { // for not created pull request
176184
headBranch = pr.HeadCommitID
177185
} else {

services/pull/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
166166
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
167167
func GetDiverging(ctx context.Context, pr *issues_model.PullRequest) (*git.DivergeObject, error) {
168168
log.Trace("GetDiverging[%-v]: compare commits", pr)
169-
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr)
169+
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr, false)
170170
if err != nil {
171171
if !models.IsErrBranchDoesNotExist(err) {
172172
log.Error("CreateTemporaryRepoForPR %-v: %v", pr, err)

templates/repo/issue/view_title.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
</div>
9999
</div>
100100
</div>
101-
<div class="desc"><br/>When changing the target branch, be careful to rebase the branch in your fork to match. See <a href="https://wiki.blender.org/wiki/Tools/Pull_Requests">documentation</a>.</div>
101+
<div class="desc"><br/>When changing the target branch, be careful to rebase the branch in your fork to match. See <a href="https://wiki.blender.org/wiki/Tools/Pull_Requests">documentation</a>.</div>
102102
</span>
103103
{{end}}
104104
{{else}}

0 commit comments

Comments
 (0)