pub fn group_by_stack(stacks: &[Option<Stack>]) -> StackGroupingExpand description
Partition a slice of optional stack descriptors into groups sharing the same connected stack.
The grouping key is (trunk, sorted diff set), so worktrees in the same connected stack
always collapse into one group regardless of the Stack::diffs vector order returned
by current_stack. Members within each group are ordered by their branch’s position in
the representative stack’s diffs list (bottom→top).
Groups are returned in deterministic order: sorted by (trunk, sorted branch set).
When all entries are None (stack model inactive or --no-stack), groups is empty and
every index appears in ungrouped — callers get identical flat-list behavior.