use crate::ObjectId;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub struct Entry {
pub path: Vec<u8>,
pub mode: Mode,
pub id: ObjectId,
pub stage: Stage,
pub assume_valid: bool,
pub intent_to_add: bool,
pub skip_worktree: bool,
pub stat: Stat,
}
impl Entry {
#[must_use]
pub fn with_stage(mut self, stage: Stage) -> Self {
self.stage = stage;
self
}
#[must_use]
pub fn with_assume_valid(mut self, assume_valid: bool) -> Self {
self.assume_valid = assume_valid;
self
}
#[must_use]
pub fn with_intent_to_add(mut self, intent_to_add: bool) -> Self {
self.intent_to_add = intent_to_add;
self
}
#[must_use]
pub fn with_skip_worktree(mut self, skip_worktree: bool) -> Self {
self.skip_worktree = skip_worktree;
self
}
#[must_use]
pub fn with_stat(mut self, stat: Stat) -> Self {
self.stat = stat;
self
}
pub fn new(path: Vec<u8>, mode: Mode, id: ObjectId) -> Self {
Self {
path,
mode,
id,
stage: Stage::Normal,
assume_valid: false,
intent_to_add: false,
skip_worktree: false,
stat: Stat::default(),
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[repr(u32)]
#[non_exhaustive]
pub enum Mode {
SparseDirectory = 0o040000,
Regular = 0o100644,
Executable = 0o100755,
Symlink = 0o120000,
Gitlink = 0o160000,
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[repr(u16)]
pub enum Stage {
#[default]
Normal = 0,
Base = 1,
Ours = 2,
Theirs = 3,
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct Timestamp {
pub seconds: u32,
pub nanoseconds: u32,
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct Stat {
pub ctime: Timestamp,
pub mtime: Timestamp,
pub device: u32,
pub inode: u32,
pub uid: u32,
pub gid: u32,
pub size: u32,
}