History

change!: remove `FullName::to_ref()` in favor of `•::as_ref()`. (#301)

This became possible now that `FullNameRef` is a proper ref, not just ref-like.

Sebastian Thiel committed 4 years ago

Commit f1dbb6b1 parent 9cf0c7b10 files · +29 −31Browse files

Unified · Split

10 files
  1. git-ref/src/fullname.rs +3 −13
  2. git-ref/src/lib.rs +8 −0
  3. git-ref/src/store/file/find.rs +1 −1
  4. git-ref/src/store/file/loose/reference/logiter.rs +3 −3
  5. git-ref/src/store/file/raw_ext.rs +3 −3
  6. git-ref/src/store/file/transaction/commit.rs +2 −2
  7. git-ref/src/store/file/transaction/prepare.rs +4 −4
  8. git-ref/src/store/packed/transaction.rs +1 −1
  9. git-ref/src/target.rs +1 −1
  10. git-ref/tests/fullname/mod.rs +3 −3
git-ref/src/fullname.rs+3−13
@@ -69,11 +69,6 @@ impl FullName { · 68 unmodified lines
6969 crate::PartialNameCow(self.0.as_bstr().into())
7070 }
7171
72− /// Interpret this fully qualified reference as shared full name
73− pub fn to_ref(&self) -> &FullNameRef {
74− self.borrow()
75− }
76−
7772 /// Convert this name into the relative path, lossily, identifying the reference location relative to a repository
7873 pub fn to_path(&self) -> &Path {
7974 git_path::from_byte_slice(&self.0)
@@ -111,27 +106,22 @@ impl FullName { · 31 unmodified lines
111106 ///
112107 /// If there is no such prefix, the original name is returned.
113108 pub fn shorten(&self) -> &BStr {
114− self.to_ref().shorten()
109+ self.as_ref().shorten()
115110 }
116111
117112 /// Classify this name, or return `None` if it's unclassified.
118113 pub fn category(&self) -> Option<crate::Category<'_>> {
119− self.to_ref().category()
114+ self.as_ref().category()
120115 }
121116
122117 /// Classify this name, or return `None` if it's unclassified. If `Some`,
123118 /// the shortened name is returned as well.
124119 pub fn category_and_short_name(&self) -> Option<(crate::Category<'_>, &BStr)> {
125− self.to_ref().category_and_short_name()
120+ self.as_ref().category_and_short_name()
126121 }
127122 }
128123
129124 impl FullNameRef {
130− /// Create an owned copy of ourself
131− pub fn to_owned(&self) -> FullName {
132− FullName(self.0.to_owned())
133− }
134−
135125 /// Return the file name portion of a full name, for instance `main` if the
136126 /// full name was `refs/heads/main`.
137127 pub fn file_name(&self) -> &BStr {
git-ref/src/lib.rs+8−0
@@ -111,6 +111,14 @@ pub struct FullNameRef(BStr); · 110 unmodified lines
111111 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
112112 pub struct PartialNameCow<'a>(Cow<'a, BStr>);
113113
114+/// A validated complete and fully qualified referenced reference name, safe to use for all operations.
115+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
116+pub struct PartialNameRef(BStr);
117+
118+/// A validated complete and fully qualified owned reference name, safe to use for all operations.
119+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
120+pub struct PartialName(BString);
121+
114122 /// A _validated_ prefix for references to act as a namespace.
115123 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
116124 pub struct Namespace(BString);
git-ref/src/store/file/find.rs+1−1
@@ -125,7 +125,7 @@ impl file::Store { · 124 unmodified lines
125125 let full_name = match &self.namespace {
126126 Some(namespace) => {
127127 full_name_backing = namespace.to_owned().into_namespaced_name(full_name);
128− full_name_backing.to_ref()
128+ full_name_backing.as_ref()
129129 }
130130 None => full_name,
131131 };
git-ref/src/store/file/loose/reference/logiter.rs+3−3
@@ -18,7 +18,7 @@ impl Reference { · 17 unmodified lines
1818 /// If the caller needs to know if it's readable, try to read the log instead with a reverse or forward iterator.
1919 pub fn log_exists(&self, store: &file::Store) -> bool {
2020 store
21− .reflog_exists(self.name.to_ref())
21+ .reflog_exists(self.name.as_ref())
2222 .expect("name conversion infallible")
2323 }
2424 /// Return a reflog reverse iterator for this ref, reading chunks from the back into the fixed buffer `buf`, in the given `store`.
@@ -30,7 +30,7 @@ impl Reference { · 5 unmodified lines
3030 store: &file::Store,
3131 buf: &'b mut [u8],
3232 ) -> std::io::Result<Option<log::iter::Reverse<'b, std::fs::File>>> {
33− store.reflog_iter_rev(self.name.to_ref(), buf).map_err(must_be_io_err)
33+ store.reflog_iter_rev(self.name.as_ref(), buf).map_err(must_be_io_err)
3434 }
3535
3636 /// Return a reflog forward iterator for this ref and write its file contents into `buf`, in the given `store`.
@@ -42,6 +42,6 @@ impl Reference { · 5 unmodified lines
4242 store: &file::Store,
4343 buf: &'b mut Vec<u8>,
4444 ) -> std::io::Result<Option<impl Iterator<Item = Result<log::LineRef<'b>, log::iter::decode::Error>> + 'a>> {
45− store.reflog_iter(self.name.to_ref(), buf).map_err(must_be_io_err)
45+ store.reflog_iter(self.name.as_ref(), buf).map_err(must_be_io_err)
4646 }
4747 }
git-ref/src/store/file/raw_ext.rs+3−3
@@ -55,14 +55,14 @@ impl ReferenceExt for Reference { · 54 unmodified lines
5555 fn log_iter<'a, 's>(&'a self, store: &'s file::Store) -> log::iter::Platform<'a, 's> {
5656 log::iter::Platform {
5757 store,
58− name: self.name.to_ref(),
58+ name: self.name.as_ref(),
5959 buf: Vec::new(),
6060 }
6161 }
6262
6363 fn log_exists(&self, store: &file::Store) -> bool {
6464 store
65− .reflog_exists(self.name.to_ref())
65+ .reflog_exists(self.name.as_ref())
6666 .expect("infallible name conversion")
6767 }
6868
@@ -95,7 +95,7 @@ impl ReferenceExt for Reference { · 26 unmodified lines
9595 while let Some(next) = cursor.follow_packed(store, packed) {
9696 let next = next?;
9797 if seen.contains(&next.name) {
98− return Err(peel::to_id::Error::Cycle(store.reference_path(cursor.name.to_ref())));
98+ return Err(peel::to_id::Error::Cycle(store.reference_path(cursor.name.as_ref())));
9999 }
100100 *cursor = next;
101101 seen.insert(cursor.name.clone());
git-ref/src/store/file/transaction/commit.rs+2−2
@@ -97,7 +97,7 @@ impl<'s> Transaction<'s> { · 96 unmodified lines
9797 }
9898
9999 for change in updates.iter_mut() {
100− let (reflog_root, relative_name) = self.store.reflog_base_and_relative_path(change.update.name.to_ref());
100+ let (reflog_root, relative_name) = self.store.reflog_base_and_relative_path(change.update.name.as_ref());
101101 match &change.update.change {
102102 Change::Update { .. } => {}
103103 Change::Delete { .. } => {
@@ -139,7 +139,7 @@ impl<'s> Transaction<'s> { · 35 unmodified lines
139139 };
140140 if take_lock_and_delete {
141141 let lock = change.lock.take().expect("lock must still be present in delete mode");
142− let reference_path = self.store.reference_path(change.update.name.to_ref());
142+ let reference_path = self.store.reference_path(change.update.name.as_ref());
143143 if let Err(err) = std::fs::remove_file(reference_path) {
144144 if err.kind() != std::io::ErrorKind::NotFound {
145145 return Err(Error::DeleteReference {
git-ref/src/store/file/transaction/prepare.rs+4−4
@@ -26,7 +26,7 @@ impl<'s> Transaction<'s> { · 25 unmodified lines
2626 );
2727
2828 let existing_ref = store
29− .ref_contents(change.update.name.to_ref())
29+ .ref_contents(change.update.name.as_ref())
3030 .map_err(Error::from)
3131 .and_then(|maybe_loose| {
3232 maybe_loose
@@ -43,7 +43,7 @@ impl<'s> Transaction<'s> { · 10 unmodified lines
4343 })
4444 .and_then(|maybe_loose| match (maybe_loose, packed) {
4545 (None, Some(packed)) => packed
46− .try_find(change.update.name.to_ref())
46+ .try_find(change.update.name.as_ref())
4747 .map(|opt| opt.map(Into::into))
4848 .map_err(Error::from),
4949 (None, None) => Ok(None),
@@ -51,7 +51,7 @@ impl<'s> Transaction<'s> { · 1 unmodified line
5151 });
5252 let lock = match &mut change.update.change {
5353 Change::Delete { expected, .. } => {
54− let (base, relative_path) = store.reference_path_with_base(change.update.name.to_ref());
54+ let (base, relative_path) = store.reference_path_with_base(change.update.name.as_ref());
5555 let lock = git_lock::Marker::acquire_to_hold_resource(
5656 base.join(relative_path),
5757 lock_fail_mode,
@@ -97,7 +97,7 @@ impl<'s> Transaction<'s> { · 39 unmodified lines
9797 lock
9898 }
9999 Change::Update { expected, new, .. } => {
100− let (base, relative_path) = store.reference_path_with_base(change.update.name.to_ref());
100+ let (base, relative_path) = store.reference_path_with_base(change.update.name.as_ref());
101101 let mut lock = git_lock::File::acquire_to_update_resource(
102102 base.join(relative_path),
103103 lock_fail_mode,
git-ref/src/store/packed/transaction.rs+1−1
@@ -45,7 +45,7 @@ impl packed::Transaction { · 44 unmodified lines
4545 .into_iter()
4646 .filter(|edit| {
4747 if let Change::Delete { .. } = edit.change {
48− buffer.as_ref().map_or(true, |b| b.find(edit.name.to_ref()).is_ok())
48+ buffer.as_ref().map_or(true, |b| b.find(edit.name.as_ref()).is_ok())
4949 } else {
5050 true
5151 }
git-ref/src/target.rs+1−1
@@ -61,7 +61,7 @@ impl Target { · 60 unmodified lines
6161 pub fn to_ref(&self) -> crate::TargetRef<'_> {
6262 match self {
6363 Target::Peeled(oid) => crate::TargetRef::Peeled(oid),
64− Target::Symbolic(name) => crate::TargetRef::Symbolic(name.to_ref()),
64+ Target::Symbolic(name) => crate::TargetRef::Symbolic(name.as_ref()),
6565 }
6666 }
6767
git-ref/tests/fullname/mod.rs+3−3
@@ -5,7 +5,7 @@ use git_ref::Category; · 4 unmodified lines
55 #[test]
66 fn file_name() {
77 let name: git_ref::FullName = "refs/heads/main".try_into().unwrap();
8− assert_eq!(name.to_ref().file_name(), "main");
8+ assert_eq!(name.as_ref().file_name(), "main");
99 }
1010 #[test]
1111 fn shorten_and_category() {
@@ -72,14 +72,14 @@ fn shorten_and_category() { · 60 unmodified lines
7272 let name: git_ref::FullName = input.try_into().unwrap();
7373 assert_eq!(category.is_worktree_private(), is_worktree_private);
7474 let category = Some(category);
75− assert_eq!(name.to_ref().shorten(), expected);
75+ assert_eq!(name.as_ref().shorten(), expected);
7676 assert_eq!(name.shorten(), expected);
7777 assert_eq!(name.category(), category);
7878 assert_eq!(
7979 name.category_and_short_name(),
8080 category.map(|cat| (cat, expected.into()))
8181 );
82− assert_eq!(name.to_ref().category(), category);
82+ assert_eq!(name.as_ref().category(), category);
8383 }
8484
8585 for special in ["hello/world", "main-worktree/head"] {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t