Skip to content

Commit da45d92

Browse files
committed
make summary available for Item.
1 parent 2dc373f commit da45d92

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

gix/src/status/index_worktree.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ pub mod iter {
315315
use crate::status::index_worktree::{iter, BuiltinSubmoduleStatus};
316316
use crate::status::{index_worktree, Platform};
317317
use crate::worktree::IndexPersistedOrInMemory;
318+
use gix_status::index_as_worktree::{Change, EntryStatus};
319+
320+
pub use gix_status::index_as_worktree_with_renames::Summary;
318321

319322
pub(super) enum ApplyChange {
320323
SetSizeToZero,
@@ -377,7 +380,7 @@ pub mod iter {
377380
/// This can also happen for copies.
378381
RewriteFromIndex {
379382
/// The entry that is the source of the rewrite, which means it was removed on disk,
380-
/// equivalent to [Change::Removed](gix_status::index_as_worktree::Change::Removed).
383+
/// equivalent to [Change::Removed].
381384
///
382385
/// Note that the [entry-id](gix_index::Entry::id) is the content-id of the source of the rewrite.
383386
source_entry: gix_index::Entry,
@@ -505,6 +508,41 @@ pub mod iter {
505508
},
506509
}
507510

511+
impl Item {
512+
/// Return a simplified summary of the item as digest of its status, or `None` if this item is
513+
/// created from the directory walk and is *not untracked*, or if it is merely to communicate
514+
/// a needed update to the index entry.
515+
pub fn summary(&self) -> Option<Summary> {
516+
use gix_status::index_as_worktree_with_renames::Summary::*;
517+
Some(match self {
518+
Item::Modification { status, .. } => match status {
519+
EntryStatus::Conflict(_) => Conflict,
520+
EntryStatus::Change(change) => match change {
521+
Change::Removed => Removed,
522+
Change::Type => TypeChange,
523+
Change::Modification { .. } | Change::SubmoduleModification(_) => Modified,
524+
},
525+
EntryStatus::NeedsUpdate(_) => return None,
526+
EntryStatus::IntentToAdd => IntentToAdd,
527+
},
528+
Item::DirectoryContents { entry, .. } => {
529+
if matches!(entry.status, gix_dir::entry::Status::Untracked) {
530+
Added
531+
} else {
532+
return None;
533+
}
534+
}
535+
Item::Rewrite { copy, .. } => {
536+
if *copy {
537+
Copied
538+
} else {
539+
Renamed
540+
}
541+
}
542+
})
543+
}
544+
}
545+
508546
impl<'index> From<gix_status::index_as_worktree_with_renames::Entry<'index, (), SubmoduleStatus>> for Item {
509547
fn from(value: gix_status::index_as_worktree_with_renames::Entry<'index, (), SubmoduleStatus>) -> Self {
510548
match value {
@@ -675,7 +713,7 @@ pub mod iter {
675713
}
676714

677715
impl Iterator for super::Iter {
678-
type Item = Result<Item, crate::status::index_worktree::Error>;
716+
type Item = Result<Item, index_worktree::Error>;
679717

680718
fn next(&mut self) -> Option<Self::Item> {
681719
#[cfg(feature = "parallel")]

0 commit comments

Comments
 (0)