improve: show whole-diff totals alongside file stats
This commit is contained in:
+14
@@ -135,6 +135,8 @@ pub struct ChangedFile {
|
||||
pub status: FileStatus,
|
||||
/// False means text, EOF flags, hunks and notices have not been prepared.
|
||||
pub loaded: bool,
|
||||
/// Frozen (added, removed) counts for catalog entries whose text is unloaded.
|
||||
pub stats: Option<(usize, usize)>,
|
||||
pub before: Vec<String>,
|
||||
pub after: Vec<String>,
|
||||
pub before_eof: bool,
|
||||
@@ -142,6 +144,17 @@ pub struct ChangedFile {
|
||||
pub hunks: Vec<Hunk>,
|
||||
pub notice: Option<String>,
|
||||
}
|
||||
impl ChangedFile {
|
||||
pub(crate) fn line_counts(&self) -> Option<(usize, usize)> {
|
||||
if self.loaded {
|
||||
Some(self.hunks.iter().fold((0, 0), |(added, removed), hunk| {
|
||||
(added + hunk.after_len, removed + hunk.before_len)
|
||||
}))
|
||||
} else {
|
||||
self.stats
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct BlameRevision {
|
||||
pub store: PathBuf,
|
||||
@@ -690,6 +703,7 @@ impl DiffState {
|
||||
comparison.root = root.clone();
|
||||
comparison.files.resize_with(paths.len(), || ChangedFile {
|
||||
review_revisions: None,
|
||||
stats: None,
|
||||
path: PathBuf::new(),
|
||||
old_path: None,
|
||||
status: FileStatus::Modified,
|
||||
|
||||
Reference in New Issue
Block a user