pub struct Mode { /* private fields */ }
Expand description
The kind of file of an entry.
Implementations§
source§impl Mode
impl Mode
sourcepub const DIR: Self = _
pub const DIR: Self = _
directory (only used for sparse checkouts), equivalent to a tree, which is excluded from the index via cone-mode.
sourcepub const FILE_EXECUTABLE: Self = _
pub const FILE_EXECUTABLE: Self = _
regular file, executable
sourcepub const fn bits(&self) -> u32
pub const fn bits(&self) -> u32
Returns the raw value of the flags currently stored.
Examples found in repository?
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
pub fn write_to(&self, mut out: impl std::io::Write, state: &State) -> std::io::Result<()> {
let stat = self.stat;
out.write_all(&stat.ctime.secs.to_be_bytes())?;
out.write_all(&stat.ctime.nsecs.to_be_bytes())?;
out.write_all(&stat.mtime.secs.to_be_bytes())?;
out.write_all(&stat.mtime.nsecs.to_be_bytes())?;
out.write_all(&stat.dev.to_be_bytes())?;
out.write_all(&stat.ino.to_be_bytes())?;
out.write_all(&self.mode.bits().to_be_bytes())?;
out.write_all(&stat.uid.to_be_bytes())?;
out.write_all(&stat.gid.to_be_bytes())?;
out.write_all(&stat.size.to_be_bytes())?;
out.write_all(self.id.as_bytes())?;
let path = self.path(state);
let path_len: u16 = if path.len() >= entry::Flags::PATH_LEN.bits() as usize {
entry::Flags::PATH_LEN.bits() as u16
} else {
path.len()
.try_into()
.expect("we just checked that the length is smaller than 0xfff")
};
out.write_all(&(self.flags.to_storage().bits() | path_len).to_be_bytes())?;
if self.flags.contains(entry::Flags::EXTENDED) {
out.write_all(
&entry::at_rest::FlagsExtended::from_flags(self.flags)
.bits()
.to_be_bytes(),
)?;
}
out.write_all(path)?;
out.write_all(b"\0")
}
sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
Examples found in repository?
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
fn load_one<'a>(
data: &'a [u8],
path_backing: &mut Vec<u8>,
hash_len: usize,
has_delta_paths: bool,
prev_path_and_buf: Option<(Range<usize>, &mut Vec<u8>)>,
) -> Option<(Entry, &'a [u8])> {
let first_byte_of_entry = data.as_ptr() as usize;
let (ctime_secs, data) = read_u32(data)?;
let (ctime_nsecs, data) = read_u32(data)?;
let (mtime_secs, data) = read_u32(data)?;
let (mtime_nsecs, data) = read_u32(data)?;
let (dev, data) = read_u32(data)?;
let (ino, data) = read_u32(data)?;
let (mode, data) = read_u32(data)?;
let (uid, data) = read_u32(data)?;
let (gid, data) = read_u32(data)?;
let (size, data) = read_u32(data)?;
let (hash, data) = split_at_pos(data, hash_len)?;
let (flags, data) = read_u16(data)?;
let flags = entry::at_rest::Flags::from_bits(flags)?;
let (flags, data) = if flags.contains(entry::at_rest::Flags::EXTENDED) {
let (extended_flags, data) = read_u16(data)?;
let extended_flags = entry::at_rest::FlagsExtended::from_bits(extended_flags)?;
let extended_flags = extended_flags.to_flags()?;
(flags.to_memory() | extended_flags, data)
} else {
(flags.to_memory(), data)
};
let start = path_backing.len();
let data = if has_delta_paths {
let (strip_len, data) = var_int(data)?;
if let Some((prev_path, buf)) = prev_path_and_buf {
let end = prev_path.end.checked_sub(strip_len.try_into().ok()?)?;
let copy_len = end.checked_sub(prev_path.start)?;
if copy_len > 0 {
buf.resize(copy_len, 0);
buf.copy_from_slice(&path_backing[prev_path.start..end]);
path_backing.extend_from_slice(buf);
}
}
let (path, data) = split_at_byte_exclusive(data, 0)?;
path_backing.extend_from_slice(path);
data
} else {
let (path, data) = if flags.contains(entry::Flags::PATH_LEN) {
split_at_byte_exclusive(data, 0)?
} else {
let path_len = (flags.bits() & entry::Flags::PATH_LEN.bits()) as usize;
let (path, data) = split_at_pos(data, path_len)?;
(path, skip_padding(data, first_byte_of_entry))
};
path_backing.extend_from_slice(path);
data
};
let path_range = start..path_backing.len();
Some((
Entry {
stat: entry::Stat {
ctime: entry::Time {
secs: ctime_secs,
nsecs: ctime_nsecs,
},
mtime: entry::Time {
secs: mtime_secs,
nsecs: mtime_nsecs,
},
dev,
ino,
uid,
gid,
size,
},
id: git_hash::ObjectId::from(hash),
flags: flags & !entry::Flags::PATH_LEN,
// This forces us to add the bits we need before being able to use them.
mode: entry::Mode::from_bits_truncate(mode),
path: path_range,
},
data,
))
}
sourcepub const unsafe fn from_bits_unchecked(bits: u32) -> Self
pub const unsafe fn from_bits_unchecked(bits: u32) -> Self
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Safety
The caller of the bitflags!
macro can chose to allow or
disallow extra bits for their bitflags type.
The caller of from_bits_unchecked()
has to ensure that
all bits correspond to a defined flag or that extra bits
are valid for this bitflags type.
sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Returns true
if there are flags common to both self
and other
.
sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Returns true
if all of the flags in other
are contained within self
.
sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Inserts or removes the specified flags depending on the passed value.
sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Returns the intersection between the flags in self
and
other
.
Specifically, the returned set contains only the flags which are
present in both self
and other
.
This is equivalent to using the &
operator (e.g.
ops::BitAnd
), as in flags & other
.
sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Returns the union of between the flags in self
and other
.
Specifically, the returned set contains all flags which are
present in either self
or other
, including any which are
present in both (see Self::symmetric_difference
if that
is undesirable).
This is equivalent to using the |
operator (e.g.
ops::BitOr
), as in flags | other
.
sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
Returns the difference between the flags in self
and other
.
Specifically, the returned set contains all flags present in
self
, except for the ones present in other
.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other
(and this syntax is also supported).
This is equivalent to using the -
operator (e.g.
ops::Sub
), as in flags - other
.
sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference between the flags
in self
and other
.
Specifically, the returned set contains the flags present which
are present in self
or other
, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self
and other
.
This is equivalent to using the ^
operator (e.g.
ops::BitXor
), as in flags ^ other
.
sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self
, but which are allowed for this type.
Alternatively, it can be thought of as the set difference
between Self::all()
and self
(e.g. Self::all() - self
)
This is equivalent to using the !
operator (e.g.
ops::Not
), as in !flags
.
source§impl Mode
impl Mode
sourcepub fn is_sparse(&self) -> bool
pub fn is_sparse(&self) -> bool
Return true if this is a sparse entry, as it points to a directory which usually isn’t what an unsparse index tracks.
Examples found in repository?
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
pub fn chunk<'a>(
mut data: &'a [u8],
entries: &mut Vec<Entry>,
path_backing: &mut Vec<u8>,
num_entries: u32,
object_hash: git_hash::Kind,
version: Version,
) -> Result<(Outcome, &'a [u8]), decode::Error> {
let mut is_sparse = false;
let has_delta_paths = version == Version::V4;
let mut prev_path = None;
let mut delta_buf = Vec::<u8>::with_capacity(AVERAGE_V4_DELTA_PATH_LEN_IN_BYTES);
for idx in 0..num_entries {
let (entry, remaining) = load_one(
data,
path_backing,
object_hash.len_in_bytes(),
has_delta_paths,
prev_path,
)
.ok_or(decode::Error::Entry { index: idx })?;
data = remaining;
if entry.mode.is_sparse() {
is_sparse = true;
}
// TODO: entries are actually in an intrusive collection, with path as key. Could be set for us. This affects 'ignore_case' which we
// also don't yet handle but probably could, maybe even smartly with the collection.
// For now it's unclear to me how they access the index, they could iterate quickly, and have fast access by path.
entries.push(entry);
prev_path = entries.last().map(|e| (e.path.clone(), &mut delta_buf));
}
Ok((Outcome { is_sparse }, data))
}
Trait Implementations§
source§impl BitAndAssign<Mode> for Mode
impl BitAndAssign<Mode> for Mode
source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Disables all flags disabled in the set.
source§impl BitOrAssign<Mode> for Mode
impl BitOrAssign<Mode> for Mode
source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Adds the set of flags.
source§impl BitXorAssign<Mode> for Mode
impl BitXorAssign<Mode> for Mode
source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Toggles the set of flags.
source§impl Extend<Mode> for Mode
impl Extend<Mode> for Mode
source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<Mode> for Mode
impl FromIterator<Mode> for Mode
source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
source§impl Ord for Mode
impl Ord for Mode
source§impl PartialEq<Mode> for Mode
impl PartialEq<Mode> for Mode
source§impl PartialOrd<Mode> for Mode
impl PartialOrd<Mode> for Mode
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Mode> for Mode
impl SubAssign<Mode> for Mode
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Disables all flags enabled in the set.