The latter isn't included to keep concerns and crates separate.
Unified · Split
| @@ -50,19 +50,12 @@ · 49 unmodified lines | ||
| 50 | 50 | #![forbid(unsafe_code)] |
| 51 | 51 | |
| 52 | 52 | /// A dummy type to represent path specs and help finding all spots that take path specs once it is implemented. |
| 53 | − | |
| 54 | −/// A preliminary version of a path-spec based on glances of the code. | |
| 55 | −#[derive(Clone, Debug)] | |
| 56 | −pub struct Spec(bstr::BString); | |
| 57 | − | |
| 58 | 53 | mod convert; |
| 59 | 54 | pub use convert::*; |
| 60 | 55 | |
| 61 | 56 | mod util; |
| 62 | 57 | pub use util::is_absolute; |
| 63 | 58 | |
| 64 | −mod spec; | |
| 65 | − | |
| 66 | 59 | /// |
| 67 | 60 | pub mod realpath; |
| 68 | 61 | pub use realpath::function::{realpath, realpath_opts}; |
| @@ -1,53 +0,0 @@ | ||
| 1 | −use std::ffi::OsStr; | |
| 2 | − | |
| 3 | −use bstr::{BStr, ByteSlice, ByteVec}; | |
| 4 | − | |
| 5 | −use crate::Spec; | |
| 6 | − | |
| 7 | −impl std::convert::TryFrom<&OsStr> for Spec { | |
| 8 | − type Error = crate::Utf8Error; | |
| 9 | − | |
| 10 | − fn try_from(value: &OsStr) -> Result<Self, Self::Error> { | |
| 11 | − crate::os_str_into_bstr(value).map(|value| { | |
| 12 | − assert_valid_hack(value); | |
| 13 | − Spec(value.into()) | |
| 14 | − }) | |
| 15 | − } | |
| 16 | −} | |
| 17 | − | |
| 18 | −fn assert_valid_hack(input: &BStr) { | |
| 19 | − assert!(!input.contains_str(b"/../")); | |
| 20 | − assert!(!input.contains_str(b"/./")); | |
| 21 | − assert!(!input.starts_with_str(b"../")); | |
| 22 | − assert!(!input.starts_with_str(b"./")); | |
| 23 | − assert!(!input.starts_with_str(b"/")); | |
| 24 | −} | |
| 25 | − | |
| 26 | −impl Spec { | |
| 27 | − /// Parse `input` into a `Spec` or `None` if it could not be parsed | |
| 28 | − // TODO: tests, actual implementation probably via `gix-pathspec` to make use of the crate after all. | |
| 29 | − pub fn from_bytes(input: &BStr) -> Option<Self> { | |
| 30 | − assert_valid_hack(input); | |
| 31 | − Spec(input.into()).into() | |
| 32 | − } | |
| 33 | − /// Return all paths described by this path spec, using slashes on all platforms. | |
| 34 | − pub fn items(&self) -> impl Iterator<Item = &BStr> { | |
| 35 | − std::iter::once(self.0.as_bstr()) | |
| 36 | − } | |
| 37 | − /// Adjust this path specification according to the given `prefix`, which may be empty to indicate we are the at work-tree root. | |
| 38 | − // TODO: this is a hack, needs test and time to do according to spec. This is just a minimum version to have -something-. | |
| 39 | − pub fn apply_prefix(&mut self, prefix: &std::path::Path) -> &Self { | |
| 40 | − // many more things we can't handle. `Path` never ends with trailing path separator. | |
| 41 | − let prefix = crate::into_bstr(prefix); | |
| 42 | − if !prefix.is_empty() { | |
| 43 | − let mut prefix = crate::to_unix_separators_on_windows(prefix); | |
| 44 | − { | |
| 45 | − let path = prefix.to_mut(); | |
| 46 | − path.push_byte(b'/'); | |
| 47 | − path.extend_from_slice(&self.0); | |
| 48 | − } | |
| 49 | − self.0 = prefix.into_owned(); | |
| 50 | − } | |
| 51 | − self | |
| 52 | − } | |
| 53 | −} | |