Module function_coupling
Expand description
function-coupling analysis.
For a single target file, identifies pairs of functions that co-change
(appear together in the same revision’s hunk-attributed change set) and
ranks them by Fisher exact significance. Only pairs with co_changes ≥ 2
are emitted.
Algorithm: for each revision that touched the target file, the set of
HEAD-alive functions whose line spans overlapped any hunk is computed via
the same hunk-overlap logic used by function-xray. Co-change counts are
then accumulated over all revisions. For each pair (a, b) the Fisher
2×2 contingency table is:
b touched b not touched
a touched co a_only
a not b_only neitherwhere n = total distinct revisions touching the file (from the hunks
table, regardless of which functions they touched) and
neither = n − co − a_only − b_only.
Rename limitation: hunk attribution uses WHERE h.path = ? (current
HEAD-relative path). Pre-rename history is not attributed — see
function_xray module doc.
Output: sorted by p_value ASC (None first — degenerate marginal
implies p → 0, i.e. perfectly coupled) then confidence DESC for
determinism. confidence = co_changes / min(a_changes, b_changes).
Research basis: Adams et al., ICSM 2006 “The Co-Change Rule”; Fisher significance adapts the coupling analysis in Tornhill, “Your Code as a Crime Scene” (2015) to function granularity.
Structs§
- Function
Coupling Row - One row per function pair with
co_changes ≥ 2, sorted byp_valueASC.
Functions§
- run_
function_ coupling - Run the
function-couplinganalysis.