#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum Stage {
#[default]
Unconflicted = 0,
Base = 1,
Ours = 2,
Theirs = 3,
}
pub type StageRaw = u32;
pub mod mode;
mod flags;
pub(crate) use flags::at_rest;
pub use flags::Flags;
pub mod stat;
mod write;
use bitflags::bitflags;
bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct Mode: u32 {
const DIR = 0o040000;
const FILE = 0o100644;
const FILE_EXECUTABLE = 0o100755;
const SYMLINK = 0o120000;
const COMMIT = 0o160000;
}
}
#[derive(Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Stat {
pub mtime: stat::Time,
pub ctime: stat::Time,
pub dev: u32,
pub ino: u32,
pub uid: u32,
pub gid: u32,
pub size: u32,
}
mod access {
use bstr::{BStr, ByteSlice};
use crate::{entry, Entry, State};
impl Entry {
pub fn path<'a>(&self, state: &'a State) -> &'a BStr {
state.path_backing[self.path.clone()].as_bstr()
}
pub fn path_in<'backing>(&self, backing: &'backing crate::PathStorageRef) -> &'backing BStr {
backing[self.path.clone()].as_bstr()
}
pub fn stage(&self) -> entry::Stage {
self.flags.stage()
}
pub fn stage_raw(&self) -> u32 {
self.flags.stage_raw()
}
}
}
mod _impls {
use std::cmp::Ordering;
use bstr::BStr;
use gix_object::tree::EntryKind;
use crate::{entry, Entry, State};
impl From<EntryKind> for entry::Mode {
fn from(value: EntryKind) -> Self {
match value {
EntryKind::Tree => entry::Mode::DIR,
EntryKind::Blob => entry::Mode::FILE,
EntryKind::BlobExecutable => entry::Mode::FILE_EXECUTABLE,
EntryKind::Link => entry::Mode::SYMLINK,
EntryKind::Commit => entry::Mode::COMMIT,
}
}
}
impl Entry {
pub fn cmp(&self, other: &Self, state: &State) -> Ordering {
let lhs = self.path(state);
let rhs = other.path(state);
Entry::cmp_filepaths(lhs, rhs).then_with(|| self.stage().cmp(&other.stage()))
}
pub fn cmp_filepaths(a: &BStr, b: &BStr) -> Ordering {
let common_len = a.len().min(b.len());
a[..common_len]
.cmp(&b[..common_len])
.then_with(|| a.len().cmp(&b.len()))
}
}
}