Skip to main content

Module standards_review_patch

Module standards_review_patch 

Source
Expand description

The standards-review shadow run: a file’s changed old-side ranges read from the patch. What: Reading one file’s changed new-side line spans out of a git show --patch text, so the review needs no git diff -U0 start per excerpted file. Why: The script runs git diff -U0 <sha>^ <sha> -- <name> for each of up to eight files. A hunk of the three-line-context patch is a list of change runs, and each run is one zero-context hunk, so the same spans follow from the patch the review already holds. The spans are on the new side because the excerpt is cut from the new-side file.

In TS you’d write (pseudocode):

for (const match of git('diff', '-U0', `${sha}^`, sha, '--', name).matchAll(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? /gm)) { ... }

Structs§

NewSpan
What: One run of changed lines on the new side of a file: the first new line the change touches and the last. A pure deletion touches the new line that now stands where the removed lines were. Why: The excerpt window is the union of these spans over the file’s runs, cut from the new-side file the commit produced. The script applied the old-side numbers to the new-side file, which shifts the window after an earlier insertion; this port uses the new side on both ends.

Functions§

new_spans
What: The new-side spans of name in patch_lines, in file order; empty when the patch holds no section for the path or a section without hunks (a binary file, a mode change or a pure rename). Why: These replace the script’s per-file git diff -U0 start, and standards_review_patch_tests.rs checks them against that command’s new-side headers.