Draft: Extract ManualMergeDetector from RefreshService (reference for !264935)

Reference only - closed on creation, not for merge. It's !264935 (merged) with the manual merge detection moved out of RefreshService#post_merge_manually_merged into Gitlab::MergeRequests::ManualMergeDetector. Behaviour is unchanged, and with the flag off it is faster than master.

Built on !264935 (merged)'s head (bb5197fe). The last commit (c5f6bf1a) is the only new one.

Detailed context for AI agents
  • ManualMergeDetector#execute returns {merge_request => merge_commit_sha}. It owns the candidate query (moved from RefreshService#post_merge_candidates), the empty-diff filter, the stored diff head check (stored_head_landed), the flagged source branch tip fallback (current_branch_tip_landed, detect_manual_merge_by_source_branch_tip) and BranchPushMergeCommitAnalyzer.
  • RefreshService#post_merge_manually_merged keeps only commits_by, the merge source lookup and the per-MR PostMergeService loop, so it sits next to the MergeSourceResolver extraction in !260499 (merged). The two merge without conflicts.
  • Push commit ids are a Set, and MRs with an empty or missing diff are dropped before their diff head is read, so there is no FindCommit call for MRs without a diff.
  • No unit spec for the detector yet.

Verification

  • spec/services/merge_requests/refresh_service_spec.rb: 110 examples, 0 failures. Rubocop clean.
  • Break matrix, 25 scenarios x flag off/on (50 examples, 0 failures). Flag off is compared against master and flag on against bb5197fe, each in a fresh project. MR states, merge SHAs, merged events, errors, ListRefs patterns and processing order all match, and it never makes more Gitaly calls. Scenarios: stored head vs branch tip, empty/no-diff/fork/orphan filters, non-ASCII branch, deleted source branch, mixed and batch pushes, closed/locked MRs, target create/delete/rewind pushes, PostMergeService and ListRefs failures.

Performance (test env, local Gitaly, 30k branches, PostMergeService stubbed, median ms of post_merge_manually_merged, push with no manual merge; relative numbers only)

Open MRs, push size master !264935 (merged) flag off !264935 (merged) flag on this, flag off this, flag on
2,000 MRs, 29 commits 312 314 477 258 457
2,000 MRs, 10k commits 540 492 773 267 551
5,000 MRs, 29 commits 1,102 1,058 1,927 616 1,383
5,000 MRs, 10k commits 1,530 1,405 2,256 657 1,415
  • Flag off is never slower than master. It is up to 2x faster on large pushes and makes 0 FindCommit calls instead of 1 per MR with no diff.
  • Flag on adds one ListRefs call with one pattern per unmatched open MR: about 40 ms at 267 patterns, 150-290 ms at 1,780 (gitlab-org/gitlab scale: 1,987 open MRs target master, 29.6k branches) and 600-900 ms at 4,450, on every push to the target branch.
Edited by Marc Shaw

Merge request reports

Loading
Loading