Enum git_object::tree::EntryMode
source · #[repr(u16)]
pub enum EntryMode {
Tree,
Blob,
BlobExecutable,
Link,
Commit,
}
Expand description
The mode of items storable in a tree, similar to the file mode on a unix file system.
Used in mutable::Entry and EntryRef.
Variants§
Tree
A tree, or directory
Blob
A file that is not executable
BlobExecutable
A file that is executable
Link
A symbolic link
Commit
A commit of a git submodule
Implementations§
source§impl EntryMode
impl EntryMode
sourcepub fn is_no_tree(&self) -> bool
pub fn is_no_tree(&self) -> bool
Return true if this entry mode represents anything BUT Tree/directory
source§impl EntryMode
impl EntryMode
Serialization
sourcepub fn as_bytes(&self) -> &'static [u8] ⓘ
pub fn as_bytes(&self) -> &'static [u8] ⓘ
Return the representation as used in the git internal format.
Examples found in repository?
src/tree/write.rs (line 39)
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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
fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
debug_assert_eq!(
&{
let mut entries_sorted = self.entries.clone();
entries_sorted.sort();
entries_sorted
},
&self.entries,
"entries for serialization must be sorted by filename"
);
for Entry { mode, filename, oid } in &self.entries {
out.write_all(mode.as_bytes())?;
out.write_all(SPACE)?;
if filename.find_byte(b'\n').is_some() {
return Err(Error::NewlineInFilename {
name: (*filename).to_owned(),
}
.into());
}
out.write_all(filename)?;
out.write_all(&[b'\0'])?;
out.write_all(oid.as_bytes())?;
}
Ok(())
}
fn size(&self) -> usize {
self.entries
.iter()
.map(|Entry { mode, filename, oid }| mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len())
.sum()
}
fn kind(&self) -> Kind {
Kind::Tree
}
}
/// Serialization
impl<'a> crate::WriteTo for TreeRef<'a> {
/// Serialize this tree to `out` in the git internal format.
fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
debug_assert_eq!(
&{
let mut entries_sorted = self.entries.clone();
entries_sorted.sort();
entries_sorted
},
&self.entries,
"entries for serialization must be sorted by filename"
);
for EntryRef { mode, filename, oid } in &self.entries {
out.write_all(mode.as_bytes())?;
out.write_all(SPACE)?;
if filename.find_byte(b'\n').is_some() {
return Err(Error::NewlineInFilename {
name: (*filename).to_owned(),
}
.into());
}
out.write_all(filename)?;
out.write_all(&[b'\0'])?;
out.write_all(oid.as_bytes())?;
}
Ok(())
}
fn size(&self) -> usize {
self.entries
.iter()
.map(|EntryRef { mode, filename, oid }| {
mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len()
})
.sum()
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for EntryMode
impl<'de> Deserialize<'de> for EntryMode
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for EntryMode
impl Ord for EntryMode
source§impl PartialEq<EntryMode> for EntryMode
impl PartialEq<EntryMode> for EntryMode
source§impl PartialOrd<EntryMode> for EntryMode
impl PartialOrd<EntryMode> for EntryMode
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more