1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use git_hash::ObjectId;
use git_object::{bstr::BStr, tree};

pub enum Change {
    Addition {
        entry_mode: tree::EntryMode,
        oid: ObjectId,
    },
    Copy,
    Deletion {
        entry_mode: tree::EntryMode,
        oid: ObjectId,
    },
    Modification {
        previous_entry_mode: tree::EntryMode,
        previous_oid: ObjectId,

        entry_mode: tree::EntryMode,
        oid: ObjectId,
    },
    Renaming,
    Type,
}

#[derive(Clone, Copy, PartialOrd, PartialEq, Ord, Eq, Hash)]
pub enum Action {
    Continue,
    Cancel,
}

impl Action {
    pub fn cancelled(&self) -> bool {
        matches!(self, Action::Cancel)
    }
}

pub trait Record {
    type PathId: Clone + Default;

    fn set_current_path(&mut self, path: Self::PathId);
    fn push_tracked_path_component(&mut self, component: &BStr) -> Self::PathId;
    fn push_path_component(&mut self, component: &BStr);
    fn pop_path_component(&mut self);
    fn record(&mut self, change: Change) -> Action;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn size_of_change() {
        assert_eq!(
            std::mem::size_of::<Change>(),
            46,
            "this type shouldn't grow without us knowing"
        )
    }
}