pub fn pack_diff(diff: &str, max_chars: usize) -> (String, Vec<String>)Expand description
Fit diff within max_chars by keeping whole file sections, dropping the
lowest-priority files first. Returns (packed_diff, dropped_paths). If the
diff already fits, returns it unchanged with an empty dropped list.
Sections are ranked by [file_priority] (DESC) then by char-length (ASC, so
more small high-value files fit), then greedily accumulated while the running
total stays within budget. Kept sections are re-emitted in their ORIGINAL
diff order so the packed diff still reads top-to-bottom. If not even the
smallest single section fits, the best one is kept anyway (never returns
empty for a non-empty diff — a downstream safety clamp trims the hard cap).
§Examples
let d = "diff --git a/src/a.rs b/src/a.rs\n+++ b/src/a.rs\n@@ -1 +1 @@\n+y\n";
let (packed, dropped) = pack_diff(d, 10_000);
assert_eq!(packed, d);
assert!(dropped.is_empty());