|
| 1 | +use crate::object::tree::EntryRef; |
| 2 | +use crate::{bstr::BStr, ext::ObjectIdExt, object::tree::Entry}; |
| 3 | + |
| 4 | +/// Access |
| 5 | +impl<'repo> Entry<'repo> { |
| 6 | + /// The kind of object to which `oid` is pointing to. |
| 7 | + pub fn mode(&self) -> gix_object::tree::EntryMode { |
| 8 | + self.inner.mode |
| 9 | + } |
| 10 | + |
| 11 | + /// The name of the file in the parent tree. |
| 12 | + pub fn filename(&self) -> &BStr { |
| 13 | + self.inner.filename.as_ref() |
| 14 | + } |
| 15 | + |
| 16 | + /// Return the object id of the entry. |
| 17 | + pub fn id(&self) -> crate::Id<'repo> { |
| 18 | + self.inner.oid.attach(self.repo) |
| 19 | + } |
| 20 | + |
| 21 | + /// Return the object this entry points to. |
| 22 | + pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> { |
| 23 | + self.id().object() |
| 24 | + } |
| 25 | + |
| 26 | + /// Return the plain object id of this entry, without access to the repository. |
| 27 | + pub fn oid(&self) -> &gix_hash::oid { |
| 28 | + &self.inner.oid |
| 29 | + } |
| 30 | + |
| 31 | + /// Return the plain object id of this entry, without access to the repository. |
| 32 | + pub fn object_id(&self) -> gix_hash::ObjectId { |
| 33 | + self.inner.oid |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +/// Consuming |
| 38 | +impl Entry<'_> { |
| 39 | + /// Return the contained object. |
| 40 | + pub fn detach(self) -> gix_object::tree::Entry { |
| 41 | + self.inner |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl<'repo, 'a> EntryRef<'repo, 'a> { |
| 46 | + /// The kind of object to which [`id()`][Self::id()] is pointing. |
| 47 | + pub fn mode(&self) -> gix_object::tree::EntryMode { |
| 48 | + self.inner.mode |
| 49 | + } |
| 50 | + |
| 51 | + /// The kind of object to which [`id()`][Self::id()] is pointing, as shortcut to [self.mode().kind()](Self::mode()). |
| 52 | + pub fn kind(&self) -> gix_object::tree::EntryKind { |
| 53 | + self.inner.mode.kind() |
| 54 | + } |
| 55 | + |
| 56 | + /// The name of the file in the parent tree. |
| 57 | + pub fn filename(&self) -> &gix_object::bstr::BStr { |
| 58 | + self.inner.filename |
| 59 | + } |
| 60 | + |
| 61 | + /// Return the entries id, connected to the underlying repository. |
| 62 | + pub fn id(&self) -> crate::Id<'repo> { |
| 63 | + crate::Id::from_id(self.inner.oid, self.repo) |
| 64 | + } |
| 65 | + |
| 66 | + /// Return the plain object id of this entry, without access to the repository. |
| 67 | + pub fn oid(&self) -> &gix_hash::oid { |
| 68 | + self.inner.oid |
| 69 | + } |
| 70 | + |
| 71 | + /// Return the object this entry points to. |
| 72 | + pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> { |
| 73 | + self.id().object() |
| 74 | + } |
| 75 | + |
| 76 | + /// Return the plain object id of this entry, without access to the repository. |
| 77 | + pub fn object_id(&self) -> gix_hash::ObjectId { |
| 78 | + self.inner.oid.to_owned() |
| 79 | + } |
| 80 | + |
| 81 | + /// Detach the repository from this instance. |
| 82 | + pub fn detach(&self) -> gix_object::tree::EntryRef<'a> { |
| 83 | + self.inner |
| 84 | + } |
| 85 | + |
| 86 | + /// Create an instance that doesn't bind to a buffer anymore (but that still contains a repository reference). |
| 87 | + pub fn to_owned(&self) -> Entry<'repo> { |
| 88 | + Entry { |
| 89 | + inner: self.inner.into(), |
| 90 | + repo: self.repo, |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +impl std::fmt::Display for EntryRef<'_, '_> { |
| 96 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 97 | + write!( |
| 98 | + f, |
| 99 | + "{:>6o} {:>6} {}\t{}", |
| 100 | + self.mode(), |
| 101 | + self.mode().as_str(), |
| 102 | + self.id().shorten_or_id(), |
| 103 | + self.filename() |
| 104 | + ) |
| 105 | + } |
| 106 | +} |
0 commit comments