Showing the changes to git-ref/src (3 of 6 files). Show all
Unified · Split
| @@ -20,7 +20,7 @@ impl Default for WriteReflog { · 19 unmodified lines | |||
| 20 | pub struct Reference<'a> { | 20 | pub struct Reference<'a> { |
| 21 | parent: &'a Store, | 21 | parent: &'a Store, |
| 22 | /// The path to uniquely identify this ref within its store. | 22 | /// The path to uniquely identify this ref within its store. |
| 23 | pub relative_path: PathBuf, | 23 | relative_path: PathBuf, |
| 24 | state: reference::State, | 24 | state: reference::State, |
| 25 | } | 25 | } |
| 26 | 26 | ||
| @@ -1,6 +1,8 @@ | |||
| 1 | use crate::transaction::FullName; | ||
| 1 | use crate::{file::Reference, Kind, Target}; | 2 | use crate::{file::Reference, Kind, Target}; |
| 2 | use bstr::BString; | 3 | use bstr::BString; |
| 3 | use git_hash::{oid, ObjectId}; | 4 | use git_hash::{oid, ObjectId}; |
| 5 | use std::path::Path; | ||
| 4 | 6 | ||
| 5 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)] | 7 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)] |
| 6 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] | 8 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] |
| @@ -33,6 +35,18 @@ impl<'a> Reference<'a> { · 26 unmodified lines | |||
| 33 | State::Id(ref oid) => Target::Peeled(oid.as_ref()), | 35 | State::Id(ref oid) => Target::Peeled(oid.as_ref()), |
| 34 | } | 36 | } |
| 35 | } | 37 | } |
| 38 | |||
| 39 | /// Return the full name of this reference as path | ||
| 40 | pub fn relative_path(&self) -> &Path { | ||
| 41 | &self.relative_path | ||
| 42 | } | ||
| 43 | |||
| 44 | /// Return the full validated name of the reference | ||
| 45 | pub fn name(&self) -> FullName { | ||
| 46 | use os_str_bytes::OsStrBytes; | ||
| 47 | let name = self.relative_path.as_path().to_raw_bytes(); | ||
| 48 | FullName(name.to_vec().into()) | ||
| 49 | } | ||
| 36 | } | 50 | } |
| 37 | 51 | ||
| 38 | mod iter; | 52 | mod iter; |
| @@ -35,7 +35,7 @@ use std::{borrow::Cow, convert::TryFrom, path::Path}; · 34 unmodified lines | |||
| 35 | /// Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target | 35 | /// Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target |
| 36 | /// of a symbolic reference | 36 | /// of a symbolic reference |
| 37 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] | 37 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] |
| 38 | pub struct FullName(BString); | 38 | pub struct FullName(pub(crate) BString); |
| 39 | 39 | ||
| 40 | impl TryFrom<&str> for FullName { | 40 | impl TryFrom<&str> for FullName { |
| 41 | type Error = git_validate::refname::Error; | 41 | type Error = git_validate::refname::Error; |