Skip to content

Commit

Permalink
make summary available for Item.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 14, 2024
1 parent 2dc373f commit e95c6d6
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion gix/src/status/index_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub mod iter {
use crate::status::index_worktree::{iter, BuiltinSubmoduleStatus};
use crate::status::{index_worktree, Platform};
use crate::worktree::IndexPersistedOrInMemory;
use gix_status::index_as_worktree::{Change, EntryStatus};

pub(super) enum ApplyChange {
SetSizeToZero,
Expand Down Expand Up @@ -505,6 +506,41 @@ pub mod iter {
},
}

impl Item {
/// Return a simplified summary of the item as digest of its status, or `None` if this item is
/// created from the directory walk and is *not untracked*, or if it is merely to communicate
/// a needed update to the index entry.
pub fn summary(&self) -> Option<gix_status::index_as_worktree_with_renames::Summary> {
use gix_status::index_as_worktree_with_renames::Summary::*;
Some(match self {
Item::Modification { status, .. } => match status {
EntryStatus::Conflict(_) => Conflict,
EntryStatus::Change(change) => match change {
Change::Removed => Removed,
Change::Type => TypeChange,
Change::Modification { .. } | Change::SubmoduleModification(_) => Modified,
},
EntryStatus::NeedsUpdate(_) => return None,
EntryStatus::IntentToAdd => IntentToAdd,
},
Item::DirectoryContents { entry, .. } => {
if matches!(entry.status, gix_dir::entry::Status::Untracked) {
Added
} else {
return None;
}
}
Item::Rewrite { copy, .. } => {
if *copy {
Copied
} else {
Renamed
}
}
})
}
}

impl<'index> From<gix_status::index_as_worktree_with_renames::Entry<'index, (), SubmoduleStatus>> for Item {
fn from(value: gix_status::index_as_worktree_with_renames::Entry<'index, (), SubmoduleStatus>) -> Self {
match value {
Expand Down Expand Up @@ -675,7 +711,7 @@ pub mod iter {
}

impl Iterator for super::Iter {
type Item = Result<Item, crate::status::index_worktree::Error>;
type Item = Result<Item, index_worktree::Error>;

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

0 comments on commit e95c6d6

Please sign in to comment.