1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Shared helper for routing complexity-metric reads through
//! `complexity_metrics_grouped` when `opts.group_file` is set.
//!
//! `apply_grouping` rewrites `changes.path` to group names (hunks are
//! never path-rewritten — hunks of grouped-away paths are dropped,
//! identity-mapped paths keep theirs), but `complexity_metrics` is
//! populated at HEAD-time keyed on raw file paths. Without an analogous
//! rewrite, the `MAX(cognitive) GROUP BY path` reads in `hotspots`,
//! `code_health`, `god_classes`, and `stale_code` silently produced `0`
//! cognitive for grouped entities because `changes.path` (group name)
//! never matched `complexity_metrics.path` (raw path). `apply_grouping`
//! therefore also materialises `complexity_metrics_grouped`: one row per
//! group carrying the per-group `MAX` of every complexity column the
//! `{cm_src}` consumers read (`cognitive`, `cyclomatic`, `loc`, `sloc`,
//! `nargs`, `max_nesting`, `bool_ops`) plus `MAX` `kind='unit'` MI —
//! analyses opt in
//! by reading from the table named here.
//!
//! Centralised so the four affected analyses share one dispatch. This
//! solves the same class of problem as `analyses::lineage` (swap an
//! analysis's source table based on an `Options` flag) but with a
//! deliberately different mechanism: `lineage` regex-rewrites `FROM
//! changes` in place, whereas this exposes a table name that callers
//! substitute into an explicit `{cm_src}` placeholder. A placeholder is
//! simpler and safer than a general SQL rewrite for the small, fixed set
//! of complexity-reading analyses — they are NOT mirror images.
use crateOptions;
/// Returns the complexity-metric source table for `opts`.
///
/// When grouping is active, this names the pre-aggregated
/// `complexity_metrics_grouped` materialised by `apply_grouping`; the
/// table has one row per group with cognitive + MI already collapsed
/// via `MAX`. Wrapping the read in `MAX(cognitive) GROUP BY path` is a
/// no-op on this source, so analyses can use the SAME CTE shape under
/// either source — only the `FROM` table swaps.