Skip to main content

Module szz

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):

  1. deleted_ranges reads the fix’s deleted pre-image lines straight from the hunks table.
  2. LineOriginSource::origins is 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.
  3. 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.
  4. The AG filter drops candidates whose line is cosmetic — blank, or comment-only for the file’s Tier-1 language — see is_cosmetic_line.
  5. The clock-skew guard discards candidates that aren’t strictly older than the fix itself.
  6. 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_rev at path is believed to fix a defect introduced by defect_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§

LineOriginSource
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 hunks table. old_start/old_lines are the pre-image (deleted) side — see schema_v1.sql’s hunks table 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 in MiningStats::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 --porcelain output into (line_number, commit) pairs — pure function so the parser is unit-testable without git.