pub struct FullName(_);
Expand description
Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target of a symbolic reference
Implementations§
source§impl FullName
impl FullName
sourcepub fn to_path(&self) -> &Path
pub fn to_path(&self) -> &Path
Convert this name into the relative path, lossily, identifying the reference location relative to a repository
Examples found in repository?
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
fn follow_packed(
&self,
store: &file::Store,
packed: Option<&packed::Buffer>,
) -> Option<Result<Reference, file::find::existing::Error>> {
match self.peeled {
Some(peeled) => Some(Ok(Reference {
name: self.name.clone(),
target: Target::Peeled(peeled),
peeled: None,
})),
None => match &self.target {
Target::Peeled(_) => None,
Target::Symbolic(full_name) => match store.try_find_packed(full_name.as_ref(), packed) {
Ok(Some(next)) => Some(Ok(next)),
Ok(None) => Some(Err(file::find::existing::Error::NotFound {
name: full_name.to_path().to_owned(),
})),
Err(err) => Some(Err(file::find::existing::Error::Find(err))),
},
},
}
}
sourcepub fn into_inner(self) -> BString
pub fn into_inner(self) -> BString
Dissolve this instance and return the buffer.
Examples found in repository?
196 197 198 199 200 201 202 203 204 205 206 207
pub(crate) fn reference_path_with_base<'b>(&self, name: &'b FullNameRef) -> (Cow<'_, Path>, Cow<'b, Path>) {
let (base, name) = self.to_base_dir_and_relative_name(name, false);
(
base,
match &self.namespace {
None => git_path::to_native_path_on_windows(name.as_bstr()),
Some(namespace) => {
git_path::to_native_path_on_windows(namespace.to_owned().into_namespaced_name(name).into_inner())
}
},
)
}
More examples
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
pub(in crate::store_impl::file) fn reflog_base_and_relative_path<'a>(
&self,
name: &'a FullNameRef,
) -> (PathBuf, Cow<'a, Path>) {
let is_reflog = true;
let (base, name) = self.to_base_dir_and_relative_name(name, is_reflog);
(
base.join("logs"),
match &self.namespace {
None => git_path::to_native_path_on_windows(name.as_bstr()),
Some(namespace) => git_path::to_native_path_on_windows(
namespace.to_owned().into_namespaced_name(name).into_inner(),
),
},
)
}
sourcepub fn as_bstr(&self) -> &BStr
pub fn as_bstr(&self) -> &BStr
Return ourselves as byte string which is a valid refname
Examples found in repository?
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
fn eq(&self, other: &TargetRef<'a>) -> bool {
match (self, other) {
(Target::Peeled(lhs), TargetRef::Peeled(rhs)) => lhs == rhs,
(Target::Symbolic(lhs), TargetRef::Symbolic(rhs)) => lhs.as_bstr() == rhs.as_bstr(),
_ => false,
}
}
}
impl From<ObjectId> for Target {
fn from(id: ObjectId) -> Self {
Target::Peeled(id)
}
}
impl TryFrom<Target> for ObjectId {
type Error = Target;
fn try_from(value: Target) -> Result<Self, Self::Error> {
match value {
Target::Peeled(id) => Ok(id),
Target::Symbolic(_) => Err(value),
}
}
}
impl From<FullName> for Target {
fn from(name: FullName) -> Self {
Target::Symbolic(name)
}
}
impl fmt::Display for Target {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Target::Peeled(oid) => oid.fmt(f),
Target::Symbolic(name) => write!(f, "ref: {}", name.as_bstr()),
}
}
More examples
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
pub fn commit(self) -> Result<(), commit::Error> {
let mut edits = self.edits.expect("BUG: cannot call commit() before prepare(…)");
if edits.is_empty() {
return Ok(());
}
let mut file = self.lock.expect("a write lock for applying changes");
let refs_sorted: Box<dyn Iterator<Item = Result<packed::Reference<'_>, packed::iter::Error>>> =
match self.buffer.as_ref() {
Some(buffer) => Box::new(buffer.iter()?),
None => Box::new(std::iter::empty()),
};
let mut refs_sorted = refs_sorted.peekable();
edits.sort_by(|l, r| l.inner.name.as_bstr().cmp(r.inner.name.as_bstr()));
let mut peekable_sorted_edits = edits.iter().peekable();
file.with_mut(|f| f.write_all(HEADER_LINE))?;
let mut num_written_lines = 0;
loop {
match (refs_sorted.peek(), peekable_sorted_edits.peek()) {
(Some(Err(_)), _) => {
let err = refs_sorted.next().expect("next").expect_err("err");
return Err(commit::Error::Iteration(err));
}
(None, None) => {
break;
}
(Some(Ok(_)), None) => {
let pref = refs_sorted.next().expect("next").expect("no err");
num_written_lines += 1;
file.with_mut(|out| write_packed_ref(out, pref))?;
}
(Some(Ok(pref)), Some(edit)) => {
use std::cmp::Ordering::*;
match pref.name.as_bstr().cmp(edit.inner.name.as_bstr()) {
Less => {
let pref = refs_sorted.next().expect("next").expect("valid");
num_written_lines += 1;
file.with_mut(|out| write_packed_ref(out, pref))?;
}
Greater => {
let edit = peekable_sorted_edits.next().expect("next");
file.with_mut(|out| write_edit(out, edit, &mut num_written_lines))?;
}
Equal => {
let _pref = refs_sorted.next().expect("next").expect("valid");
let edit = peekable_sorted_edits.next().expect("next");
file.with_mut(|out| write_edit(out, edit, &mut num_written_lines))?;
}
}
}
(None, Some(_)) => {
let edit = peekable_sorted_edits.next().expect("next");
file.with_mut(|out| write_edit(out, edit, &mut num_written_lines))?;
}
}
}
if num_written_lines == 0 {
std::fs::remove_file(file.resource_path())?;
} else {
file.commit()?;
}
drop(refs_sorted);
Ok(())
}
}
fn write_packed_ref(mut out: impl std::io::Write, pref: packed::Reference<'_>) -> std::io::Result<()> {
write!(out, "{} ", pref.target)?;
out.write_all(pref.name.as_bstr())?;
out.write_all(b"\n")?;
if let Some(object) = pref.object {
writeln!(out, "^{}", object)?;
}
Ok(())
}
fn write_edit(mut out: impl std::io::Write, edit: &Edit, lines_written: &mut i32) -> std::io::Result<()> {
match edit.inner.change {
Change::Delete { .. } => {}
Change::Update {
new: Target::Peeled(target_oid),
..
} => {
write!(out, "{} ", target_oid)?;
out.write_all(edit.inner.name.as_bstr())?;
out.write_all(b"\n")?;
if let Some(object) = edit.peeled {
writeln!(out, "^{}", object)?;
}
*lines_written += 1;
}
Change::Update {
new: Target::Symbolic(_),
..
} => unreachable!("BUG: packed refs cannot contain symbolic refs, catch that in prepare(…)"),
}
Ok(())
}
sourcepub fn prefix_namespace(&mut self, namespace: &Namespace) -> &mut Self
pub fn prefix_namespace(&mut self, namespace: &Namespace) -> &mut Self
Modify ourself so that we use namespace
as prefix, if it is not yet in the namespace
sourcepub fn strip_namespace(&mut self, namespace: &Namespace) -> &mut Self
pub fn strip_namespace(&mut self, namespace: &Namespace) -> &mut Self
Strip the given namespace
off the beginning of this name, if it is in this namespace.
sourcepub fn shorten(&self) -> &BStr
pub fn shorten(&self) -> &BStr
Strip well-known prefixes from the name and return it.
If there is no such prefix, the original name is returned.
sourcepub fn category(&self) -> Option<Category<'_>>
pub fn category(&self) -> Option<Category<'_>>
Classify this name, or return None
if it’s unclassified.
sourcepub fn category_and_short_name(&self) -> Option<(Category<'_>, &BStr)>
pub fn category_and_short_name(&self) -> Option<(Category<'_>, &BStr)>
Classify this name, or return None
if it’s unclassified. If Some
,
the shortened name is returned as well.
Trait Implementations§
source§impl AsRef<FullNameRef> for FullName
impl AsRef<FullNameRef> for FullName
source§fn as_ref(&self) -> &FullNameRef
fn as_ref(&self) -> &FullNameRef
source§impl Borrow<FullNameRef> for FullName
impl Borrow<FullNameRef> for FullName
source§fn borrow(&self) -> &FullNameRef
fn borrow(&self) -> &FullNameRef
source§impl<'de> Deserialize<'de> for FullName
impl<'de> Deserialize<'de> for FullName
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>,
source§impl<'a> From<&'a FullNameRef> for FullName
impl<'a> From<&'a FullNameRef> for FullName
source§fn from(value: &'a FullNameRef) -> Self
fn from(value: &'a FullNameRef) -> Self
source§impl Ord for FullName
impl Ord for FullName
source§impl PartialEq<FullName> for FullName
impl PartialEq<FullName> for FullName
source§impl PartialOrd<FullName> for FullName
impl PartialOrd<FullName> for FullName
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 more