gix_status/index_as_worktree/
recorder.rs

1use bstr::BStr;
2use gix_index as index;
3
4use crate::index_as_worktree::{EntryStatus, VisitEntry};
5
6/// A record of a change.
7///
8/// It's created either if there is a conflict or a change, or both.
9#[derive(Debug, Clone)]
10pub struct Record<'index, T, U> {
11    /// The index entry that is changed.
12    pub entry: &'index index::Entry,
13    /// The index of the `entry` relative to all entries in the input index.
14    pub entry_index: usize,
15    /// The path to the entry.
16    pub relative_path: &'index BStr,
17    /// The status information itself.
18    pub status: EntryStatus<T, U>,
19}
20
21/// Convenience implementation of [`VisitEntry`] that collects all non-trivial changes into a `Vec`.
22#[derive(Debug, Default)]
23pub struct Recorder<'index, T = (), U = ()> {
24    /// collected changes, index entries without conflicts or changes are excluded.
25    pub records: Vec<Record<'index, T, U>>,
26}
27
28impl<'index, T: Send, U: Send> VisitEntry<'index> for Recorder<'index, T, U> {
29    type ContentChange = T;
30    type SubmoduleStatus = U;
31
32    fn visit_entry(
33        &mut self,
34        _entries: &'index [index::Entry],
35        entry: &'index index::Entry,
36        entry_index: usize,
37        relative_path: &'index BStr,
38        status: EntryStatus<Self::ContentChange, Self::SubmoduleStatus>,
39    ) {
40        self.records.push(Record {
41            entry,
42            entry_index,
43            relative_path,
44            status,
45        });
46    }
47}