History

feat!: remove `Spec` type in favor of `gix-pathspec::Pattern`.

The latter isn't included to keep concerns and crates separate.

Sebastian Thiel committed 3 years ago

Commit df83d741 parent f194cfc2 files · +0 −60Browse files

Unified · Split

2 files
  1. gix-path/src/lib.rs +0 −7
  2. gix-path/src/spec.rs +0 −53
gix-path/src/lib.rs+0−7
@@ -50,19 +50,12 @@ · 49 unmodified lines
5050 #![forbid(unsafe_code)]
5151
5252 /// 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−
5853 mod convert;
5954 pub use convert::*;
6055
6156 mod util;
6257 pub use util::is_absolute;
6358
64−mod spec;
65−
6659 ///
6760 pub mod realpath;
6861 pub use realpath::function::{realpath, realpath_opts};
gix-path/src/spec.rs+0−53
@@ -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−}