summaryrefslogtreecommitdiffstats
path: root/vendor/gix-ref/src/raw.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix-ref/src/raw.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-ref/src/raw.rs')
-rw-r--r--vendor/gix-ref/src/raw.rs103
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/gix-ref/src/raw.rs b/vendor/gix-ref/src/raw.rs
new file mode 100644
index 000000000..fd1f9db34
--- /dev/null
+++ b/vendor/gix-ref/src/raw.rs
@@ -0,0 +1,103 @@
+use gix_hash::ObjectId;
+
+use crate::{FullName, Target};
+
+/// A fully owned backend agnostic reference
+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+pub struct Reference {
+ /// The path to uniquely identify this ref within its store.
+ pub name: FullName,
+ /// The target of the reference, either a symbolic reference by full name or a possibly intermediate object by its id.
+ pub target: Target,
+ /// The fully peeled object to which this reference ultimately points to. Only guaranteed to be set after `peel_to_id_in_place()` was called.
+ pub peeled: Option<ObjectId>,
+}
+
+mod convert {
+ use gix_hash::ObjectId;
+
+ use crate::{
+ raw::Reference,
+ store_impl::{file::loose, packed},
+ Target,
+ };
+
+ impl From<Reference> for loose::Reference {
+ fn from(value: Reference) -> Self {
+ loose::Reference {
+ name: value.name,
+ target: value.target,
+ }
+ }
+ }
+
+ impl From<loose::Reference> for Reference {
+ fn from(value: loose::Reference) -> Self {
+ Reference {
+ name: value.name,
+ target: value.target,
+ peeled: None,
+ }
+ }
+ }
+
+ impl<'p> From<packed::Reference<'p>> for Reference {
+ fn from(value: packed::Reference<'p>) -> Self {
+ Reference {
+ name: value.name.into(),
+ target: Target::Peeled(value.target()),
+ peeled: value
+ .object
+ .map(|hex| ObjectId::from_hex(hex).expect("parser validation")),
+ }
+ }
+ }
+}
+
+mod access {
+ use gix_object::bstr::ByteSlice;
+
+ use crate::{raw::Reference, FullNameRef, Namespace, Target};
+
+ impl Reference {
+ /// Returns the kind of reference based on its target
+ pub fn kind(&self) -> crate::Kind {
+ self.target.kind()
+ }
+
+ /// Return the full validated name of the reference, with the given namespace stripped if possible.
+ ///
+ /// If the reference name wasn't prefixed with `namespace`, `None` is returned instead.
+ pub fn name_without_namespace(&self, namespace: &Namespace) -> Option<&FullNameRef> {
+ self.name
+ .0
+ .as_bstr()
+ .strip_prefix(namespace.0.as_bytes())
+ .map(|stripped| FullNameRef::new_unchecked(stripped.as_bstr()))
+ }
+
+ /// Strip the given namespace from our name as well as the name, but not the reference we point to.
+ pub fn strip_namespace(&mut self, namespace: &Namespace) -> &mut Self {
+ self.name.strip_namespace(namespace);
+ if let Target::Symbolic(name) = &mut self.target {
+ name.strip_namespace(namespace);
+ }
+ self
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn size_of_reference() {
+ assert_eq!(
+ std::mem::size_of::<Reference>(),
+ 80,
+ "let's not let it change size undetected"
+ );
+ }
+}