#[non_exhaustive]pub struct DiffStat {
pub files_changed: usize,
pub insertions: usize,
pub deletions: usize,
}Expand description
Aggregate line/file counts from a diff stat (git diff --shortstat,
jj diff --stat).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.files_changed: usizeNumber of files changed.
insertions: usizeLines added (insertions(+)).
deletions: usizeLines removed (deletions(-)).
Implementations§
Source§impl DiffStat
impl DiffStat
Sourcepub fn new(
files_changed: usize,
insertions: usize,
deletions: usize,
) -> DiffStat
pub fn new( files_changed: usize, insertions: usize, deletions: usize, ) -> DiffStat
Build a DiffStat. (A constructor, because the struct is
#[non_exhaustive] — the parser crates and tests can’t use struct-literal
syntax across the crate boundary.)
Sourcepub fn parse(summary: &str) -> DiffStat
pub fn parse(summary: &str) -> DiffStat
Parse a single git diff --shortstat / jj diff --stat summary clause,
e.g. 3 files changed, 12 insertions(+), 4 deletions(-). Any of the
three sub-clauses may be absent (a pure-insertion diff omits deletions;
no changes at all yields an empty string → all zeros) — a missing or
unparsable count defaults to 0 rather than erroring, since this is fed
arbitrary CLI text.
Shared by vcs_git::parse::parse_shortstat and
vcs_jj::parse::parse_diff_stat, which were previously byte-identical
past their own preprocessing (jj additionally selects the last line
mentioning “changed” before calling this). The keyed-substring matching
(“file”/“insertion”/“deletion”) assumes the English/C-locale wording
both CLIs emit under the C locale the callers force — see their own
LC_ALL=C comments at the call site.