Skip to content

merge_check: scan main history once per batch of pull requests - #6762

Merged
shayderrr merged 2 commits into
ItsNotRexed:mainfrom
Solthodox:perf/merge-check-history-once
Nov 23, 2026
Merged

shayderrr merged 2 commits into
ItsNotRexed:mainfrom
Solthodox:perf/merge-check-history-once

Conversation

@Solthodox

@Solthodox Solthodox commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: item 4 in this claim.

Depends on: #6669 (textual overlap only).

What and why

A merge round checking N PRs ran the same git log --first-parent N times. Index only the requested PR numbers during one history scan, then pass each list of matches to its individual merge check. Preserve input order, duplicate arguments, history depth, and every existing verdict. This does not change which commit subjects count as prior merges.

Tested

9 tests passed in python3.12 -I tests/test_merge_check.py, including a mixed batch in a real temporary Git repository. For an eight-argument CLI invocation against the same commit, GIT_TRACE2_EVENT counted eight first-parent history scans on main and one on this head, with identical JSON reports. #6669 changes which subjects qualify (squash merges); the trial merge has a textual conflict, not a code prerequisite.

Independent Windows verification on cd5b0c8751: identical reports and eight scans reduced to one. At the updated head c8203c921f the test also requires one history scan; it fails on the baseline (3 versus 1).

Head c8203c921f, Linux x86-64, Python 3.12.13. Synthetic inputs; no GPU or driver used. git diff --check and the changed-file no-game-data check passed; clean trial merge with main.

AI-assisted: yes.

  • No game data, keys or decryption, including in test inputs or quoted results.
  • Translator rule: not applicable.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested cd5b0c8 on Windows 11, CPython 3.14.7, CPU only: pass.

I used one temporary Git repository with a merged branch and an open branch. I passed the pair 7=landed 8=open four times in one batch. I counted calls to git log while running the real Git commands. The parent 1cc6e3c1 made eight history scans. This head made one. Both returned the same eight JSON rows in the same order and exit code 1.

py -3.14 -I tests/test_merge_check.py passed all nine tests. The new batch test also passes with the parent implementation. It checks the reports. To cover the performance change, the same test can count calls to git log --first-parent and require one scan for the batch.

AI-assisted.

@Solthodox

Copy link
Copy Markdown
Contributor Author

Thanks @shdann. In c8203c921f the mixed-batch regression now counts real git log --first-parent invocations in addition to checking verdicts, order and merge SHAs. It fails on parent 1cc6e3c12 (three scans for three arguments, expected one); all nine module tests pass on Linux/Python 3.12.13 at the new head.

@kapitche

Copy link
Copy Markdown
Contributor

Tested c8203c9 merged with main 1cc6e3c on native Windows/Python 3.13.1 (Git 2.48.1) and Linux/Python 3.12.16: pass on Windows; Linux could not run it here

  • Linux/Python 3.12.16: the tool needs git merge-tree --write-tree (Git 2.38+) and this box has Git 2.34.1, so ~/src/Leonida/.venv/bin/python -I tests/test_merge_check.py errors (fatal: unknown rev --write-tree) on the merged tree and also on plain upstream/main (7 errors there). So that is an environment limit, not a result for or against the PR.
  • Windows 3.13.1 + Git 2.48.1.windows.1: copied the merged scripts/merge_check.py and tests/test_merge_check.py to a scratch folder and ran python -I tests\test_merge_check.py -> Ran 9 tests, OK (including test_batch_keeps_prior_merges_separate).
  • Negative control: same run with scripts/merge_check.py replaced by upstream/main's version -> FAILED (failures=1), test_batch_keeps_prior_merges_separate, AssertionError: 3 != 1 (three history scans for the three arguments). Restored afterwards.

Diff read: no concern. prior_merges now takes all PR numbers and fills one dict from a single git log --first-parent --merges; check takes the already-computed list, so repeated or mixed numbers in one batch keep separate results (the test asserts the verdicts and merge SHAs per row). Minor: args.pairs is consumed lazily twice via a generator only once, so there is no exhaustion issue.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: scripts/merge_check.py prior_merges() now accepts all PR numbers and performs one git log --merges --first-parent scan for the whole batch, returning a number-keyed dict. check() takes the precomputed merge list and main() runs the scan once before iterating pairs. tests/test_merge_check.py adds test_batch_keeps_prior_merges_separate, which patches mc.git and asserts exactly one first-parent log scan even when a PR number repeats, with per-PR merge results kept distinct.

Why merge: Avoids repeating the same history scan for every PR in a batch while preserving correct per-PR results.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary: scripts/merge_check.py prior_merges() now accepts all PR numbers and performs one git log --merges --first-parent scan for the whole batch, returning a number-keyed dict. check() takes the precomputed merge list and main() runs the scan once before iterating pairs. tests/test_merge_check.py adds test_batch_keeps_prior_merges_separate, which patches mc.git and asserts exactly one first-parent log scan even when a PR number repeats, with per-PR merge results kept distinct.

Why merge: Avoids repeating the same history scan for every PR in a batch while preserving correct per-PR results.

Verdict: Approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants