Skip to main content

Module function_xray

Module function_xray 

Expand description

function-xray analysis.

Per-function change frequency for a single target file: for each function (or method) that exists at HEAD in the target file, counts the number of distinct revisions where at least one hunk overlapped the function’s line span.

Hunk-overlap attribution: a function at [start_line, end_line] is “changed” in revision R if any hunk for that path at R satisfies new_start <= end_line && new_start + new_lines > start_line. Pure deletions (new_lines = 0) are attributed to the function whose span contains new_start; they are skipped if new_start is outside every function span (e.g., a file-level deletion in the preamble). A single revision that produces multiple overlapping hunks is counted once per function — run_function_xray deduplicates on (function, rev) after the overlap test.

HEAD-alive filter: only functions whose span is detected in the HEAD blob by compute_for_file are included. The HEAD blob is fetched via crate::repo::Repo::read_blob_at("HEAD", target) and re-parsed with the same tree-sitter extractor used during ingest. Functions that existed at some point but are absent from the HEAD tree are excluded.

Rename limitation: hunk attribution uses WHERE h.path = ? (the current HEAD-relative path). Pre-rename history is not attributed — the function receives a new identity after a rename and prior hunk records live under the old path. change_freq therefore reflects activity since the most recent rename, not the full file lifetime.

Span source: reuses compute_for_file (the same tree-sitter extractor used by the ingest pass) applied to the HEAD blob of the target file, rather than materializing yet another temp table — the target is a single file, so the overhead is negligible compared to a full ingest scan.

Research basis: HistoryFinder-style function-level churn (Gall et al., ICSM 2003 “Predicting faults from cached history”; extended to hunk attribution by Skoulis et al., MSR 2014).

Structs§

FunctionXrayRow
One row per HEAD-alive function/method in the target file.

Functions§

run_function_xray
Run the function-xray analysis.