Part 2 of 13 · 2 min read
A diff is made of hunks, and the reviewer has to read every one of them
Every line in a pull request is a line someone else has to understand before they can say yes.
Think of handing a neighbour a stack of papers to sign: the shorter and cleaner the stack, the faster they can actually read it rather than just skimming and hoping.
In plain words: a diff is the line-by-line difference between two versions of a file, broken into hunks -- contiguous blocks of changed lines -- and parsing a diff into files and hunks is what lets a tool (or a reviewer) measure exactly how much reading a pull request actually demands, file by file and block by block.
A worked example. A minimal fix to a tool-call parsing bug changes 22 lines across 2 files: 12 lines in the source file, 10 in the test file. A version of the same fix with no test changes only 12 lines in 1 file. A bloated version of the identical underlying fix changes 51 lines across 3 files -- the extra 39 lines come entirely from reformatting an unrelated module and renaming a function, not from fixing anything.
The key lines. From code/mini-pr/diffparse.py:
# from code/mini-pr/diffparse.py
def totals(files):
a = sum(f.added for f in files); r = sum(f.removed for f in files)
return {"files": len(files), "hunks": sum(len(f.hunks) for f in files), "added": a, "removed": r, "changed": a + r}
Read it as: changed is added + removed summed across every hunk in every file. This single number is what the 22-vs-51 comparison above actually is. A diff parser turns "this pull request feels big" into a concrete count. A reviewer, or a checker, can act on that count without having to read a single line of the actual code first.
Diff and hunk
A diff is the line-by-line difference between two versions. A hunk is one contiguous block of changes in a file.
Example: the bloated branch's 51 changed lines split across three hunks -- one for the real fix, one for the unrelated reformat, one for the rename -- is a diff where only one hunk is actually the pull request's stated purpose; the other two are review cost with no payoff.