Module szz
Expand description
The AG-SZZ linkage engine: traces each fix commit’s deleted pre-image
lines back to the commit that last introduced them, behind a pluggable
LineOriginSource seam (the roadmap’s “pluggable SZZ” — this is the
first rung; Neural-SZZ/SmartCommit can slot in later without churn).
No production git-subprocess implementation lives here: this crate never
shells out to git (see Repo::read_blob_at for the one git-reading seam
this module uses). The production LineOriginSource shells
git blame --porcelain from the CLI at artifact-build time; tests use an
in-memory fake.
§Algorithm
For each fix commit (already classified by super::DefectOracle):
deleted_rangesreads the fix’s deleted pre-image lines straight from thehunkstable.LineOriginSource::originsis asked, once per touched file, which commit last introduced each deleted line — queried at the fix’s FIRST PARENT (the revision immediately before the fix), since that’s the tree the deleted lines still existed in.- The tangled-commit guard excludes an oversized fix from linkage
outright (see
TANGLED_MAX_FILES/TANGLED_MAX_CHURN); the ghost guard skips whole-file-deletion blame targets within an otherwise-kept fix. - The AG filter drops candidates whose line is cosmetic — blank, or
comment-only for the file’s Tier-1 language — see
is_cosmetic_line. - The clock-skew guard discards candidates that aren’t strictly older than the fix itself.
- Survivors dedupe into
(defect_rev, fix_rev, path)SzzLinks.
§Tangled and ghost guards
AG-SZZ over-attributes on two shapes of fix commit. A tangled fix bundles the correction with unrelated edits, so most of its deleted lines are not the fix — Herzig, Just & Zeller (“The Impact of Tangled Code Changes on Defect Prediction Models”, MSR 2013) show tangled changes distort defect attribution. A ghost fix’s diff cannot carry a fix at all: a whole-file deletion removes code wholesale, so blaming its removed lines attributes the “defect” to everyone who ever touched the file — extending Kim, Zimmermann, Pan & Whitehead’s AG-SZZ cosmetic filter (ASE 2006) from cosmetic lines to file-level removals. Both guards exclude rather than down-weight (links carry no weight field), and both disclose a mined-vs-excluded count in the command output — never in the artifact.
Per-file blame failures are skip-with-log, never fatal — mining
continues with the fix’s other files and the remaining fixes; failures
are tallied in super::MiningStats::blame_failures.
Structs§
- SzzLink
- One AG-SZZ link:
fix_revatpathis believed to fix a defect introduced bydefect_rev.
Constants§
- TANGLED_
MAX_ CHURN - Tangled-commit guard: a fix changing more than this many lines
(added + deleted, across all its files) is presumed too large to be a
focused fix and is excluded from linkage. The churn companion to
TANGLED_MAX_FILES— a fix concentrated in few files can still be a tree-wide mechanical change. - TANGLED_
MAX_ FILES - Tangled-commit guard: a fix touching more than this many files is presumed
to mix the fix with unrelated edits (Herzig, Just & Zeller, MSR 2013), so
most of its deleted lines are not the fix and it is excluded from linkage.
Deliberately generous — an ordinary multi-file fix passes; the bound drops
only the mega-commits (sweeping refactors, mechanical renames, dependency
bumps) that carry a
fix-word yet fan across the tree.
Traits§
- Line
Origin Source - Pluggable line-origin seam (roadmap’s “pluggable SZZ”). Given a file at a
revision, returns for each requested 1-based line the commit that last
introduced it. The production impl (CLI) shells
git blame --porcelain; tests use an in-memory fake.
Functions§
- deleted_
ranges - A fix commit’s deleted ranges per file, straight from the
hunkstable.old_start/old_linesare the pre-image (deleted) side — seeschema_v1.sql’shunkstable doc. - is_
cosmetic_ line - AG filter: a line is cosmetic when it is blank, or — for a recognized Tier-1 language — starts (after trimming) with that language’s line-comment prefix.
- line_
comment_ prefix - The line-comment prefix for a Tier-1 language’s single-line comments.
- link_
defects - The AG-SZZ engine: for each fix commit, excludes the tangled ones outright
(tallied in
MiningStats::fixes_excluded_tangled), then blames the remaining fixes’ deleted pre-image lines at the fix’s FIRST PARENT — skipping whole-file-deletion blame targets (the ghost guard, tallied inMiningStats::ghost_files_skipped), dropping cosmetic candidates (the AG filter), and discarding candidates that aren’t strictly older than the fix (the clock-skew guard) — and dedupes the survivors into(defect_rev, fix_rev, path)links. - parse_
blame_ porcelain - Parse
git blame --porcelainoutput into (line_number, commit) pairs — pure function so the parser is unit-testable without git.