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
50#![forbid(unsafe_code)]50#![forbid(unsafe_code)]
51 51
52/// A dummy type to represent path specs and help finding all spots that take path specs once it is implemented.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)]
56pub struct Spec(bstr::BString);
57
58mod convert;53mod convert;
59pub use convert::*;54pub use convert::*;
60 55
61mod util;56mod util;
62pub use util::is_absolute;57pub use util::is_absolute;
63 58
64mod spec;
65
66///59///
67pub mod realpath;60pub mod realpath;
68pub use realpath::function::{realpath, realpath_opts};61pub use realpath::function::{realpath, realpath_opts};
gix-path/src/spec.rs+0−53
@@ -1,53 +0,0 @@
1use std::ffi::OsStr;
2
3use bstr::{BStr, ByteSlice, ByteVec};
4
5use crate::Spec;
6
7impl 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
18fn 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
26impl 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}