Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gix-ref/src/fullname.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{borrow::Borrow, path::Path};

use gix_object::bstr::{BStr, BString, ByteSlice};
use std::{borrow::Borrow, path::Path};

use crate::{bstr::ByteVec, name::is_pseudo_ref, Category, FullName, FullNameRef, Namespace, PartialNameRef};

Expand Down Expand Up @@ -73,6 +72,12 @@ impl std::fmt::Display for FullName {
}
}

impl std::fmt::Display for FullNameRef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}

impl FullNameRef {
/// Interpret this fully qualified reference name as partial name.
pub fn as_partial_name(&self) -> &PartialNameRef {
Expand Down
12 changes: 12 additions & 0 deletions gix-ref/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ impl convert::TryFrom<BString> for PartialName {
}
}

impl std::fmt::Display for PartialName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}

impl std::fmt::Display for PartialNameRef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}

/// Note that this method is disagreeing with `gix_validate` as it allows dashes '-' for some reason.
/// Since partial names cannot be created with dashes inside we adjusted this as it's probably unintended or git creates pseudo-refs
/// which wouldn't pass its safety checks.
Expand Down
11 changes: 10 additions & 1 deletion gix-ref/tests/refs/fullname.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use gix_ref::{Category, FullNameRef, PartialNameRef};
use gix_ref::{Category, FullName, FullNameRef, PartialNameRef};

#[test]
fn cow() {
Expand Down Expand Up @@ -137,3 +137,12 @@ fn prefix_with_namespace_and_stripping() {
"idempotent stripping"
);
}

#[test]
fn display() {
let full_name = FullName::try_from("refs/heads/main").unwrap();
assert_eq!(format!("{full_name}"), "refs/heads/main");

let full_name_ref = full_name.as_ref();
assert_eq!(format!("{full_name_ref}"), "refs/heads/main");
}
9 changes: 9 additions & 0 deletions gix-ref/tests/refs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ mod partialname {
);
Ok(())
}

#[test]
fn display() {
let partial_name = PartialName::try_from("heads/main").unwrap();
assert_eq!(format!("{partial_name}"), "heads/main");

let partial_name_ref = partial_name.as_ref();
assert_eq!(format!("{partial_name_ref}"), "heads/main");
}
}
mod namespace;
mod packed;
Expand Down
Loading