|
1 | 1 | //!
|
2 | 2 | #![allow(clippy::empty_docs)]
|
3 |
| -use std::borrow::Cow; |
4 | 3 |
|
5 |
| -use gix_ref::{bstr::BStr, file::ReferenceExt}; |
| 4 | +use gix_path::relative_path::RelativePath; |
| 5 | +use gix_ref::file::ReferenceExt; |
6 | 6 |
|
7 | 7 | /// A platform to create iterators over references.
|
8 | 8 | #[must_use = "Iterators should be obtained from this iterator platform"]
|
@@ -45,32 +45,41 @@ impl Platform<'_> {
|
45 | 45 | /// These are of the form `refs/heads/` or `refs/remotes/origin`, and must not contain relative paths components like `.` or `..`.
|
46 | 46 | // TODO: Create a custom `Path` type that enforces the requirements of git naturally, this type is surprising possibly on windows
|
47 | 47 | // and when not using a trailing '/' to signal directories.
|
48 |
| - pub fn prefixed<'a>(&self, prefix: impl Into<Cow<'a, BStr>>) -> Result<Iter<'_>, init::Error> { |
49 |
| - Ok(Iter::new(self.repo, self.platform.prefixed(prefix.into().as_ref())?)) |
| 48 | + pub fn prefixed<'a>( |
| 49 | + &self, |
| 50 | + prefix: impl TryInto<&'a RelativePath, Error = gix_path::relative_path::Error>, |
| 51 | + ) -> Result<Iter<'_>, init::Error> { |
| 52 | + Ok(Iter::new(self.repo, self.platform.prefixed(prefix.try_into()?)?)) |
50 | 53 | }
|
51 | 54 |
|
52 | 55 | // TODO: tests
|
53 | 56 | /// Return an iterator over all references that are tags.
|
54 | 57 | ///
|
55 | 58 | /// They are all prefixed with `refs/tags`.
|
56 | 59 | pub fn tags(&self) -> Result<Iter<'_>, init::Error> {
|
57 |
| - Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/tags/")?)) |
| 60 | + Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/tags/".try_into()?)?)) |
58 | 61 | }
|
59 | 62 |
|
60 | 63 | // TODO: tests
|
61 | 64 | /// Return an iterator over all local branches.
|
62 | 65 | ///
|
63 | 66 | /// They are all prefixed with `refs/heads`.
|
64 | 67 | pub fn local_branches(&self) -> Result<Iter<'_>, init::Error> {
|
65 |
| - Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/heads/")?)) |
| 68 | + Ok(Iter::new( |
| 69 | + self.repo, |
| 70 | + self.platform.prefixed(b"refs/heads/".try_into()?)?, |
| 71 | + )) |
66 | 72 | }
|
67 | 73 |
|
68 | 74 | // TODO: tests
|
69 | 75 | /// Return an iterator over all remote branches.
|
70 | 76 | ///
|
71 | 77 | /// They are all prefixed with `refs/remotes`.
|
72 | 78 | pub fn remote_branches(&self) -> Result<Iter<'_>, init::Error> {
|
73 |
| - Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/remotes/")?)) |
| 79 | + Ok(Iter::new( |
| 80 | + self.repo, |
| 81 | + self.platform.prefixed(b"refs/remotes/".try_into()?)?, |
| 82 | + )) |
74 | 83 | }
|
75 | 84 | }
|
76 | 85 |
|
@@ -123,6 +132,8 @@ pub mod init {
|
123 | 132 | pub enum Error {
|
124 | 133 | #[error(transparent)]
|
125 | 134 | Io(#[from] std::io::Error),
|
| 135 | + #[error(transparent)] |
| 136 | + RelativePath(#[from] gix_path::relative_path::Error), |
126 | 137 | }
|
127 | 138 | }
|
128 | 139 |
|
|
0 commit comments