History

Merge pull request #1909 from cruessler/take-to-components-in-fs-stack

Accept `ToComponents` in `gix_fs::Stack`

Sebastian Thiel committed 1 year ago

Commit 5cb53372 parents bfa3253 1f98edb20 files · +177 −102Browse files

Unified · Split

20 files
  1. .github/workflows/msrv.yml +1 −1
  2. Cargo.lock +3 −0
  3. etc/msrv-badge.svg +3 −3
  4. gitoxide-core/src/repository/attributes/query.rs +3 −3
  5. gitoxide-core/src/repository/exclude.rs +1 −1
  6. gix-fs/Cargo.toml +4 −1
  7. gix-fs/src/stack.rs +93 −18
  8. gix-fs/tests/fs/stack.rs +33 −31
  9. gix-protocol/src/fetch/response/async_io.rs +1 −1
  10. gix-status/src/stack.rs +4 −4
  11. gix-status/tests/status/stack.rs +6 −12
  12. gix-worktree-state/src/checkout/entry.rs +1 −1
  13. gix-worktree/Cargo.toml +1 −1
  14. gix-worktree/src/stack/mod.rs +4 −11
  15. gix-worktree/tests/worktree/stack/create_directory.rs +4 −2
  16. gix-worktree/tests/worktree/stack/ignore.rs +6 −3
  17. gix/Cargo.toml +1 −1
  18. gix/src/attribute_stack.rs +6 −6
  19. gix/src/id.rs +1 −1
  20. tests/it/src/commands/copy_royal.rs +1 −1
.github/workflows/msrv.yml+1−1
@@ -31,7 +31,7 @@ jobs: · 30 unmodified lines
3131 env:
3232 # dictated by `firefox` to support the `helix` editor, but now probably effectively be controlled by `jiff`, which also aligns with `regex`.
3333 # IMPORTANT: adjust etc/msrv-badge.svg as well
34− rust_version: 1.74.0
34+ rust_version: 1.75.0
3535
3636 steps:
3737 - uses: actions/checkout@v4
Cargo.lock+3−0
@@ -1901,13 +1901,16 @@ dependencies = [ · 1900 unmodified lines
19011901 name = "gix-fs"
19021902 version = "0.13.0"
19031903 dependencies = [
1904+ "bstr",
19041905 "crossbeam-channel",
19051906 "fastrand",
19061907 "gix-features 0.40.0",
1908+ "gix-path 0.10.14",
19071909 "gix-utils 0.1.14",
19081910 "is_ci",
19091911 "serde",
19101912 "tempfile",
1913+ "thiserror 2.0.12",
19111914 ]
19121915
19131916 [[package]]
etc/msrv-badge.svg+3−3
@@ -1,5 +1,5 @@
11 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="92" height="20" role="img" aria-label="rustc: 1.70.0+">
2− <title>rustc: 1.74.0+</title>
2+ <title>rustc: 1.75.0+</title>
33 <linearGradient id="s" x2="0" y2="100%">
44 <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
55 <stop offset="1" stop-opacity=".1"/>
@@ -15,7 +15,7 @@ · 9 unmodified lines
1515 <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
1616 <text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">rustc</text>
1717 <text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">rustc</text>
18− <text aria-hidden="true" x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="450">1.74.0+</text>
19− <text x="635" y="140" transform="scale(.1)" fill="#fff" textLength="450">1.74.0+</text>
18+ <text aria-hidden="true" x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="450">1.75.0+</text>
19+ <text x="635" y="140" transform="scale(.1)" fill="#fff" textLength="450">1.75.0+</text>
2020 </g>
2121 </svg>
gitoxide-core/src/repository/attributes/query.rs+3−3
@@ -8,10 +8,10 @@ pub struct Options { · 7 unmodified lines
88 }
99
1010 pub(crate) mod function {
11− use std::{borrow::Cow, io, path::Path};
12−
1311 use anyhow::bail;
1412 use gix::bstr::BStr;
13+ use std::borrow::Cow;
14+ use std::{io, path::Path};
1515
1616 use crate::{
1717 is_dir_to_mode,
@@ -44,7 +44,7 @@ pub(crate) mod function { · 26 unmodified lines
4444 .ok()
4545 .map(|m| is_dir_to_mode(m.is_dir()));
4646
47− let entry = cache.at_entry(path.as_slice(), mode)?;
47+ let entry = cache.at_entry(&path, mode)?;
4848 if !entry.matching_attributes(&mut matches) {
4949 continue;
5050 }
gitoxide-core/src/repository/exclude.rs+1−1
@@ -48,7 +48,7 @@ pub fn query( · 47 unmodified lines
4848 .metadata()
4949 .ok()
5050 .map(|m| is_dir_to_mode(m.is_dir()));
51− let entry = cache.at_entry(path.as_slice(), mode)?;
51+ let entry = cache.at_entry(&path, mode)?;
5252 let match_ = entry
5353 .matching_exclude_pattern()
5454 .and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
gix-fs/Cargo.toml+4−1
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" · 7 unmodified lines
88 description = "A crate providing file system specific utilities to `gitoxide`"
99 authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
1010 edition = "2021"
11−rust-version = "1.70"
11+rust-version = "1.75"
1212 include = ["src/**/*", "LICENSE-*"]
1313
1414 [lib]
@@ -19,8 +19,11 @@ doctest = false · 4 unmodified lines
1919 serde = ["dep:serde"]
2020
2121 [dependencies]
22+bstr = "1.5.0"
23+gix-path = { version = "^0.10.14", path = "../gix-path" }
2224 gix-features = { version = "^0.40.0", path = "../gix-features", features = ["fs-read-dir"] }
2325 gix-utils = { version = "^0.1.14", path = "../gix-utils" }
26+thiserror = "2.0.0"
2427 serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"] }
2528
2629 # For `Capabilities` to assure parallel operation works.
gix-fs/src/stack.rs+93−18
@@ -1,6 +1,80 @@
1+use crate::Stack;
2+use bstr::{BStr, BString, ByteSlice};
3+use std::ffi::OsStr;
14 use std::path::{Component, Path, PathBuf};
25
3−use crate::Stack;
6+///
7+pub mod to_normal_path_components {
8+ use std::ffi::OsString;
9+
10+ /// The error used in [`ToNormalPathComponents::to_normal_path_components()`](super::ToNormalPathComponents::to_normal_path_components()).
11+ #[derive(Debug, thiserror::Error)]
12+ #[allow(missing_docs)]
13+ pub enum Error {
14+ #[error("Input path \"{path}\" contains relative or absolute components", path = std::path::Path::new(.0.as_os_str()).display())]
15+ NotANormalComponent(OsString),
16+ #[error("Could not convert to UTF8 or from UTF8 due to ill-formed input")]
17+ IllegalUtf8,
18+ }
19+}
20+
21+/// Obtain an iterator over `OsStr`-components which are normal, none-relative and not absolute.
22+pub trait ToNormalPathComponents {
23+ /// Return an iterator over the normal components of a path, without the separator.
24+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>>;
25+}
26+
27+impl ToNormalPathComponents for &Path {
28+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>> {
29+ self.components().map(|component| match component {
30+ Component::Normal(os_str) => Ok(os_str),
31+ _ => Err(to_normal_path_components::Error::NotANormalComponent(
32+ self.as_os_str().to_owned(),
33+ )),
34+ })
35+ }
36+}
37+
38+impl ToNormalPathComponents for PathBuf {
39+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>> {
40+ self.components().map(|component| match component {
41+ Component::Normal(os_str) => Ok(os_str),
42+ _ => Err(to_normal_path_components::Error::NotANormalComponent(
43+ self.as_os_str().to_owned(),
44+ )),
45+ })
46+ }
47+}
48+
49+impl ToNormalPathComponents for &BStr {
50+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>> {
51+ self.split(|b| *b == b'/').filter(|c| !c.is_empty()).map(|component| {
52+ gix_path::try_from_byte_slice(component.as_bstr())
53+ .map_err(|_| to_normal_path_components::Error::IllegalUtf8)
54+ .map(Path::as_os_str)
55+ })
56+ }
57+}
58+
59+impl ToNormalPathComponents for &str {
60+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>> {
61+ self.split('/').filter(|c| !c.is_empty()).map(|component| {
62+ gix_path::try_from_byte_slice(component.as_bytes())
63+ .map_err(|_| to_normal_path_components::Error::IllegalUtf8)
64+ .map(Path::as_os_str)
65+ })
66+ }
67+}
68+
69+impl ToNormalPathComponents for &BString {
70+ fn to_normal_path_components(&self) -> impl Iterator<Item = Result<&OsStr, to_normal_path_components::Error>> {
71+ self.split(|b| *b == b'/').filter(|c| !c.is_empty()).map(|component| {
72+ gix_path::try_from_byte_slice(component.as_bstr())
73+ .map_err(|_| to_normal_path_components::Error::IllegalUtf8)
74+ .map(Path::as_os_str)
75+ })
76+ }
77+}
478
579 /// Access
680 impl Stack {
@@ -62,8 +136,13 @@ impl Stack { · 55 unmodified lines
62136 /// `relative` paths are terminal, so point to their designated file or directory.
63137 /// The path is also expected to be normalized, and should not contain extra separators, and must not contain `..`
64138 /// or have leading or trailing slashes (or additionally backslashes on Windows).
65− pub fn make_relative_path_current(&mut self, relative: &Path, delegate: &mut dyn Delegate) -> std::io::Result<()> {
66− if self.valid_components != 0 && relative.as_os_str().is_empty() {
139+ pub fn make_relative_path_current(
140+ &mut self,
141+ relative: impl ToNormalPathComponents,
142+ delegate: &mut dyn Delegate,
143+ ) -> std::io::Result<()> {
144+ let mut components = relative.to_normal_path_components().peekable();
145+ if self.valid_components != 0 && components.peek().is_none() {
67146 return Err(std::io::Error::new(
68147 std::io::ErrorKind::Other,
69148 "empty inputs are not allowed",
@@ -73,15 +152,19 @@ impl Stack { · 3 unmodified lines
73152 delegate.push_directory(self)?;
74153 }
75154
76− let mut components = relative.components().peekable();
77155 let mut existing_components = self.current_relative.components();
78156 let mut matching_components = 0;
79157 while let (Some(existing_comp), Some(new_comp)) = (existing_components.next(), components.peek()) {
80− if existing_comp == *new_comp {
81− components.next();
82− matching_components += 1;
83− } else {
84− break;
158+ match new_comp {
159+ Ok(new_comp) => {
160+ if existing_comp.as_os_str() == *new_comp {
161+ components.next();
162+ matching_components += 1;
163+ } else {
164+ break;
165+ }
166+ }
167+ Err(err) => return Err(std::io::Error::other(format!("{err}"))),
85168 }
86169 }
87170
@@ -100,15 +183,7 @@ impl Stack { · 12 unmodified lines
100183 }
101184
102185 while let Some(comp) = components.next() {
103− if !matches!(comp, Component::Normal(_)) {
104− return Err(std::io::Error::new(
105− std::io::ErrorKind::Other,
106− format!(
107− "Input path \"{}\" contains relative or absolute components",
108− relative.display()
109− ),
110− ));
111− }
186+ let comp = comp.map_err(std::io::Error::other)?;
112187 let is_last_component = components.peek().is_none();
113188 self.current_is_directory = !is_last_component;
114189 self.current.push(comp);
gix-fs/tests/fs/stack.rs+33−31
@@ -182,7 +182,7 @@ fn empty_paths_are_noop_if_no_path_was_pushed_before() { · 181 unmodified lines
182182 let mut s = Stack::new(root.clone());
183183
184184 let mut r = Record::default();
185− s.make_relative_path_current("".as_ref(), &mut r).unwrap();
185+ s.make_relative_path_current("", &mut r).unwrap();
186186 assert_eq!(
187187 s.current_relative().to_string_lossy(),
188188 "",
@@ -196,7 +196,7 @@ fn relative_components_are_invalid() { · 7 unmodified lines
196196 let mut s = Stack::new(root.clone());
197197
198198 let mut r = Record::default();
199− let err = s.make_relative_path_current("a/..".as_ref(), &mut r).unwrap_err();
199+ let err = s.make_relative_path_current(p("a/.."), &mut r).unwrap_err();
200200 assert_eq!(
201201 err.to_string(),
202202 format!(
@@ -205,7 +205,7 @@ fn relative_components_are_invalid() { · 2 unmodified lines
205205 )
206206 );
207207
208− s.make_relative_path_current("a/./b".as_ref(), &mut r)
208+ s.make_relative_path_current(p("a/./b"), &mut r)
209209 .expect("dot is ignored");
210210 assert_eq!(
211211 r,
@@ -221,7 +221,7 @@ fn relative_components_are_invalid() { · 9 unmodified lines
221221 if cfg!(windows) { r".\a\b" } else { "./a/b" },
222222 "dot is silently ignored"
223223 );
224− s.make_relative_path_current("a//b/".as_ref(), &mut r)
224+ s.make_relative_path_current(p("a//b/"), &mut r)
225225 .expect("multiple-slashes are ignored");
226226 assert_eq!(
227227 r,
@@ -240,19 +240,19 @@ fn absolute_paths_are_invalid() -> crate::Result { · 12 unmodified lines
240240 let mut s = Stack::new(root.clone());
241241
242242 let mut r = Record::default();
243− let err = s.make_relative_path_current("/".as_ref(), &mut r).unwrap_err();
243+ let err = s.make_relative_path_current(p("/"), &mut r).unwrap_err();
244244 assert_eq!(
245245 err.to_string(),
246246 r#"Input path "/" contains relative or absolute components"#,
247247 "a leading slash is always considered absolute"
248248 );
249− s.make_relative_path_current("a/".as_ref(), &mut r)?;
249+ s.make_relative_path_current(p("a/"), &mut r)?;
250250 assert_eq!(
251251 s.current(),
252252 p("./a/"),
253253 "trailing slashes aren't a problem at this stage, as they cannot cause a 'breakout'"
254254 );
255− s.make_relative_path_current(r"b\".as_ref(), &mut r)?;
255+ s.make_relative_path_current(p(r"b\"), &mut r)?;
256256 assert_eq!(
257257 s.current(),
258258 p(r"./b\"),
@@ -261,7 +261,7 @@ fn absolute_paths_are_invalid() -> crate::Result { · 2 unmodified lines
261261
262262 #[cfg(windows)]
263263 {
264− let err = s.make_relative_path_current(r"\".as_ref(), &mut r).unwrap_err();
264+ let err = s.make_relative_path_current(Path::new(r"\"), &mut r).unwrap_err();
265265 assert_eq!(
266266 err.to_string(),
267267 r#"Input path "\" contains relative or absolute components"#,
@@ -269,20 +269,20 @@ fn absolute_paths_are_invalid() -> crate::Result { · 1 unmodified line
269269 hence they are forbidden."
270270 );
271271
272− let err = s.make_relative_path_current("c:".as_ref(), &mut r).unwrap_err();
272+ let err = s.make_relative_path_current(Path::new("c:"), &mut r).unwrap_err();
273273 assert_eq!(
274274 err.to_string(),
275275 r#"Input path "c:" contains relative or absolute components"#,
276276 "on Windows, drive-letters without trailing backslash or slash are also absolute (even though they ought to be relative)"
277277 );
278− let err = s.make_relative_path_current(r"c:\".as_ref(), &mut r).unwrap_err();
278+ let err = s.make_relative_path_current(Path::new(r"c:\"), &mut r).unwrap_err();
279279 assert_eq!(
280280 err.to_string(),
281281 r#"Input path "c:\" contains relative or absolute components"#,
282282 "on Windows, drive-letters are absolute, which is expected"
283283 );
284284
285− s.make_relative_path_current("֍:".as_ref(), &mut r)?;
285+ s.make_relative_path_current(Path::new("֍:"), &mut r)?;
286286 assert_eq!(
287287 s.current().to_string_lossy(),
288288 ".\\֍:",
@@ -290,7 +290,7 @@ fn absolute_paths_are_invalid() -> crate::Result { · 1 unmodified line
290290 but we just turn it into a presumably invalid path which is fine, i.e. we get a joined path"
291291 );
292292 let err = s
293− .make_relative_path_current(r"\\localhost\hello".as_ref(), &mut r)
293+ .make_relative_path_current(Path::new(r"\\localhost\hello"), &mut r)
294294 .unwrap_err();
295295 assert_eq!(
296296 err.to_string(),
@@ -298,7 +298,9 @@ fn absolute_paths_are_invalid() -> crate::Result { · 1 unmodified line
298298 "there is UNC paths as well"
299299 );
300300
301− let err = s.make_relative_path_current(r#"\\?\C:"#.as_ref(), &mut r).unwrap_err();
301+ let err = s
302+ .make_relative_path_current(Path::new(r#"\\?\C:"#), &mut r)
303+ .unwrap_err();
302304 assert_eq!(
303305 err.to_string(),
304306 r#"Input path "\\?\C:" contains relative or absolute components"#,
@@ -314,10 +316,10 @@ fn delegate_calls_are_consistent() -> crate::Result { · 9 unmodified lines
314316 let mut s = Stack::new(root.clone());
315317
316318 assert_eq!(s.current(), root);
317− assert_eq!(s.current_relative(), Path::new(""));
319+ assert_eq!(s.current_relative(), p(""));
318320
319321 let mut r = Record::default();
320− s.make_relative_path_current("a/b".as_ref(), &mut r)?;
322+ s.make_relative_path_current("a/b", &mut r)?;
321323 let mut dirs = vec![root.clone(), root.join("a")];
322324 assert_eq!(
323325 r,
@@ -329,7 +331,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
329331 "it pushes the root-directory first, then the intermediate one"
330332 );
331333
332− s.make_relative_path_current("a/b2".as_ref(), &mut r)?;
334+ s.make_relative_path_current("a/b2", &mut r)?;
333335 assert_eq!(
334336 r,
335337 Record {
@@ -340,7 +342,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 4 unmodified lines
340342 "dirs remain the same as b2 is a leaf/file, hence the new `push`"
341343 );
342344
343− s.make_relative_path_current("c/d/e".as_ref(), &mut r)?;
345+ s.make_relative_path_current("c/d/e", &mut r)?;
344346 dirs.pop();
345347 dirs.extend([root.join("c"), root.join("c").join("d")]);
346348 assert_eq!(
@@ -354,7 +356,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 7 unmodified lines
354356 );
355357
356358 dirs.push(root.join("c").join("d").join("x"));
357− s.make_relative_path_current("c/d/x/z".as_ref(), &mut r)?;
359+ s.make_relative_path_current("c/d/x/z", &mut r)?;
358360 assert_eq!(
359361 r,
360362 Record {
@@ -366,8 +368,8 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
366368 );
367369
368370 dirs.drain(1..).count();
369− s.make_relative_path_current("f".as_ref(), &mut r)?;
370− assert_eq!(s.current_relative(), Path::new("f"));
371+ s.make_relative_path_current("f", &mut r)?;
372+ assert_eq!(s.current_relative(), p("f"));
371373 assert_eq!(
372374 r,
373375 Record {
@@ -379,7 +381,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
379381 );
380382
381383 dirs.push(root.join("x"));
382− s.make_relative_path_current("x/z".as_ref(), &mut r)?;
384+ s.make_relative_path_current("x/z", &mut r)?;
383385 assert_eq!(
384386 r,
385387 Record {
@@ -391,7 +393,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
391393 );
392394
393395 dirs.push(root.join("x").join("z"));
394− s.make_relative_path_current("x/z/a".as_ref(), &mut r)?;
396+ s.make_relative_path_current("x/z/a", &mut r)?;
395397 assert_eq!(
396398 r,
397399 Record {
@@ -404,7 +406,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 6 unmodified lines
404406
405407 dirs.push(root.join("x").join("z").join("a"));
406408 dirs.push(root.join("x").join("z").join("a").join("b"));
407− s.make_relative_path_current("x/z/a/b/c".as_ref(), &mut r)?;
409+ s.make_relative_path_current("x/z/a/b/c", &mut r)?;
408410 assert_eq!(
409411 r,
410412 Record {
@@ -416,7 +418,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
416418 );
417419
418420 dirs.drain(1 /*root*/ + 1 /*x*/ + 1 /*x/z*/ ..).count();
419− s.make_relative_path_current("x/z".as_ref(), &mut r)?;
421+ s.make_relative_path_current("x/z", &mut r)?;
420422 assert_eq!(
421423 r,
422424 Record {
@@ -432,7 +434,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 9 unmodified lines
432434 "the stack is state so keeps thinking it's a directory which is consistent. Git does it differently though."
433435 );
434436
435− let err = s.make_relative_path_current("".as_ref(), &mut r).unwrap_err();
437+ let err = s.make_relative_path_current(p(""), &mut r).unwrap_err();
436438 assert_eq!(
437439 err.to_string(),
438440 "empty inputs are not allowed",
@@ -440,7 +442,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 1 unmodified line
440442 and besides that really shouldn't happen"
441443 );
442444
443− s.make_relative_path_current("leaf".as_ref(), &mut r)?;
445+ s.make_relative_path_current("leaf", &mut r)?;
444446 dirs.drain(1..).count();
445447 assert_eq!(
446448 r,
@@ -452,7 +454,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 5 unmodified lines
452454 "reset as much as possible, with just a leaf-component and the root directory"
453455 );
454456
455− s.make_relative_path_current("a//b".as_ref(), &mut r)?;
457+ s.make_relative_path_current(p("a//b"), &mut r)?;
456458 dirs.push(root.join("a"));
457459 assert_eq!(
458460 r,
@@ -466,7 +468,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 7 unmodified lines
466468
467469 #[cfg(not(windows))]
468470 {
469− s.make_relative_path_current(r"\/b".as_ref(), &mut r)?;
471+ s.make_relative_path_current(r"\/b", &mut r)?;
470472 dirs.pop();
471473 dirs.push(root.join(r"\"));
472474 assert_eq!(
@@ -479,7 +481,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 6 unmodified lines
479481 "a backslash is a normal character outside of Windows, so it's fine to have it as component"
480482 );
481483
482− s.make_relative_path_current(r"\".as_ref(), &mut r)?;
484+ s.make_relative_path_current(r"\", &mut r)?;
483485 assert_eq!(
484486 r,
485487 Record {
@@ -494,7 +496,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 8 unmodified lines
494496 r"a backslash can also be a valid leaf component - here we only popped the 'b', leaving the \ 'directory'"
495497 );
496498
497− s.make_relative_path_current(r"\\".as_ref(), &mut r)?;
499+ s.make_relative_path_current(r"\\", &mut r)?;
498500 dirs.pop();
499501 assert_eq!(
500502 r,
@@ -513,7 +515,7 @@ fn delegate_calls_are_consistent() -> crate::Result { · 12 unmodified lines
513515
514516 #[cfg(windows)]
515517 {
516− s.make_relative_path_current(r"c\/d".as_ref(), &mut r)?;
518+ s.make_relative_path_current(Path::new(r"c\/d"), &mut r)?;
517519 dirs.pop();
518520 dirs.push(root.join("c"));
519521 assert_eq!(
gix-protocol/src/fetch/response/async_io.rs+1−1
@@ -124,7 +124,7 @@ impl Response { · 123 unmodified lines
124124 io::ErrorKind::UnexpectedEof,
125125 "Could not read message headline",
126126 )));
127− };
127+ }
128128
129129 match line.trim_end() {
130130 "acknowledgments" => {
gix-status/src/stack.rs+4−4
@@ -1,10 +1,10 @@
1+use crate::SymlinkCheck;
12 use bstr::BStr;
3+use gix_fs::stack::ToNormalPathComponents;
24 use gix_fs::Stack;
35 use std::borrow::Cow;
46 use std::path::{Path, PathBuf};
57
6−use crate::SymlinkCheck;
7−
88 impl SymlinkCheck {
99 /// Create a new stack that starts operating at `root`.
1010 pub fn new(root: PathBuf) -> Self {
@@ -24,7 +24,7 @@ impl SymlinkCheck { · 13 unmodified lines
2424 /// ### Note
2525 ///
2626 /// On windows, no verification is performed, instead only the combined path is provided as usual.
27− pub fn verified_path(&mut self, relative_path: &Path) -> std::io::Result<&Path> {
27+ pub fn verified_path(&mut self, relative_path: impl ToNormalPathComponents) -> std::io::Result<&Path> {
2828 self.inner.make_relative_path_current(relative_path, &mut Delegate)?;
2929 Ok(self.inner.current())
3030 }
@@ -34,7 +34,7 @@ impl SymlinkCheck { · 3 unmodified lines
3434 /// For convenience, this incarnation is tuned to be easy to use with Git paths, i.e. slash-separated `BString` path.
3535 pub fn verified_path_allow_nonexisting(&mut self, relative_path: &BStr) -> std::io::Result<Cow<'_, Path>> {
3636 let rela_path = gix_path::try_from_bstr(relative_path).map_err(std::io::Error::other)?;
37− if let Err(err) = self.verified_path(&rela_path) {
37+ if let Err(err) = self.verified_path(rela_path.as_ref()) {
3838 if err.kind() == std::io::ErrorKind::NotFound {
3939 Ok(Cow::Owned(self.inner.root().join(rela_path)))
4040 } else {
gix-status/tests/status/stack.rs+6−12
@@ -25,7 +25,7 @@ fn paths_not_going_through_symlink_directories_are_ok_and_point_to_correct_item( · 24 unmodified lines
2525 ("dir/dirlink", is_symlinked_dir),
2626 ] {
2727 assert!(
28− expectation(&stack.verified_path(rela_path.as_ref())?.symlink_metadata()?),
28+ expectation(&stack.verified_path(rela_path)?.symlink_metadata()?),
2929 "{rela_path:?} expectation failed"
3030 );
3131 }
@@ -35,7 +35,7 @@ fn paths_not_going_through_symlink_directories_are_ok_and_point_to_correct_item( · 3 unmodified lines
3535
3636 #[test]
3737 fn leaf_file_does_not_have_to_exist() -> crate::Result {
38− assert!(!stack().verified_path("dir/does-not-exist".as_ref())?.exists());
38+ assert!(!stack().verified_path("dir/does-not-exist")?.exists());
3939 Ok(())
4040 }
4141
@@ -43,10 +43,7 @@ fn leaf_file_does_not_have_to_exist() -> crate::Result { · 1 unmodified line
4343 #[cfg(not(windows))]
4444 fn intermediate_directories_have_to_exist_or_not_found_error() -> crate::Result {
4545 assert_eq!(
46− stack()
47− .verified_path("nonexisting-dir/file".as_ref())
48− .unwrap_err()
49− .kind(),
46+ stack().verified_path("nonexisting-dir/file").unwrap_err().kind(),
5047 std::io::ErrorKind::NotFound
5148 );
5249 Ok(())
@@ -55,7 +52,7 @@ fn intermediate_directories_have_to_exist_or_not_found_error() -> crate::Result · 2 unmodified lines
5552 #[test]
5653 #[cfg(windows)]
5754 fn intermediate_directories_do_not_have_exist_for_success() -> crate::Result {
58− assert!(stack().verified_path("nonexisting-dir/file".as_ref()).is_ok());
55+ assert!(stack().verified_path("nonexisting-dir/file").is_ok());
5956 Ok(())
6057 }
6158
@@ -67,16 +64,13 @@ fn intermediate_directories_do_not_have_exist_for_success() -> crate::Result { · 5 unmodified lines
6764 fn paths_leading_through_symlinks_are_rejected() {
6865 let mut stack = stack();
6966 assert_eq!(
70− stack
71− .verified_path("root-dirlink/file-in-dir".as_ref())
72− .unwrap_err()
73− .kind(),
67+ stack.verified_path("root-dirlink/file-in-dir").unwrap_err().kind(),
7468 std::io::ErrorKind::Other,
7569 "root-dirlink is a symlink to a directory"
7670 );
7771
7872 assert_eq!(
79− stack.verified_path("dir/dirlink/nothing".as_ref()).unwrap_err().kind(),
73+ stack.verified_path("dir/dirlink/nothing").unwrap_err().kind(),
8074 std::io::ErrorKind::Other,
8175 "root-dirlink is a symlink to a directory"
8276 );
gix-worktree-state/src/checkout/entry.rs+1−1
@@ -80,7 +80,7 @@ where · 79 unmodified lines
8080 let dest_relative = gix_path::try_from_bstr(entry_path).map_err(|_| crate::checkout::Error::IllformedUtf8 {
8181 path: entry_path.to_owned(),
8282 })?;
83− let path_cache = path_cache.at_path(dest_relative, Some(entry.mode), &*objects)?;
83+ let path_cache = path_cache.at_path(dest_relative.as_ref(), Some(entry.mode), &*objects)?;
8484 let dest = path_cache.path();
8585
8686 let object_size = match entry.mode {
gix-worktree/Cargo.toml+1−1
@@ -9,7 +9,7 @@ description = "A crate of the gitoxide project for shared worktree related types · 8 unmodified lines
99 authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
1010 edition = "2021"
1111 include = ["src/**/*", "LICENSE-*"]
12−rust-version = "1.70"
12+rust-version = "1.74"
1313 autotests = false
1414
1515 [lib]
gix-worktree/src/stack/mod.rs+4−11
@@ -113,7 +113,7 @@ impl Stack { · 112 unmodified lines
113113 /// Provide access to cached information for that `relative` path via the returned platform.
114114 pub fn at_path(
115115 &mut self,
116− relative: impl AsRef<Path>,
116+ relative: impl ToNormalPathComponents,
117117 mode: Option<gix_index::entry::Mode>,
118118 objects: &dyn gix_object::Find,
119119 ) -> std::io::Result<Platform<'_>> {
@@ -127,8 +127,7 @@ impl Stack { · 7 unmodified lines
127127 case: self.case,
128128 statistics: &mut self.statistics,
129129 };
130− self.stack
131− .make_relative_path_current(relative.as_ref(), &mut delegate)?;
130+ self.stack.make_relative_path_current(relative, &mut delegate)?;
132131 Ok(Platform {
133132 parent: self,
134133 is_dir: mode_is_dir(mode),
@@ -148,15 +147,8 @@ impl Stack { · 13 unmodified lines
148147 objects: &dyn gix_object::Find,
149148 ) -> std::io::Result<Platform<'_>> {
150149 let relative = relative.into();
151− let relative_path = gix_path::try_from_bstr(relative).map_err(|_err| {
152− std::io::Error::new(
153− std::io::ErrorKind::Other,
154− format!("The path \"{relative}\" contained invalid UTF-8 and could not be turned into a path"),
155− )
156− })?;
157−
158150 self.at_path(
159− relative_path,
151+ relative,
160152 mode.or_else(|| relative.ends_with_str("/").then_some(gix_index::entry::Mode::DIR)),
161153 objects,
162154 )
@@ -210,6 +202,7 @@ impl Stack { · 47 unmodified lines
210202 ///
211203 pub mod delegate;
212204 use delegate::StackDelegate;
205+use gix_fs::stack::ToNormalPathComponents;
213206
214207 mod platform;
215208 ///
gix-worktree/tests/worktree/stack/create_directory.rs+4−2
@@ -92,7 +92,7 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R · 91 unmodified lines
9292 let relative_path = format!("{dirname}/file");
9393 assert_eq!(
9494 cache
95− .at_path(&relative_path, IS_FILE, &gix_object::find::Never)
95+ .at_path(&*relative_path, IS_FILE, &gix_object::find::Never)
9696 .unwrap_err()
9797 .kind(),
9898 std::io::ErrorKind::AlreadyExists
@@ -112,7 +112,9 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R · 13 unmodified lines
112112 *unlink_on_collision = true;
113113 }
114114 let relative_path = format!("{dirname}/file");
115− let path = cache.at_path(&relative_path, IS_FILE, &gix_object::find::Never)?.path();
115+ let path = cache
116+ .at_path(&*relative_path, IS_FILE, &gix_object::find::Never)?
117+ .path();
116118 assert!(path.parent().unwrap().is_dir(), "directory was forcefully created");
117119 assert!(!path.exists());
118120 }
gix-worktree/tests/worktree/stack/ignore.rs+6−3
@@ -1,10 +1,10 @@
1+use crate::{hex_to_id, worktree::stack::probe_case};
12 use bstr::{BStr, ByteSlice};
3+use gix_fs::stack::ToNormalPathComponents;
24 use gix_index::entry::Mode;
35 use gix_worktree::{stack::state::ignore::Source, Stack};
46 use std::fs::Metadata;
57
6−use crate::{hex_to_id, worktree::stack::probe_case};
7−
88 struct IgnoreExpectations<'a> {
99 lines: bstr::Lines<'a>,
1010 }
@@ -170,7 +170,10 @@ fn check_against_baseline() -> crate::Result { · 159 unmodified lines
170170 // OK: we provide negative patterns that matched on paths if there was no other match, while git doesn't.
171171 }
172172 (actual, expected) => {
173− panic!("actual {actual:?} didn't match {expected:?} at '{relative_entry}'");
173+ panic!(
174+ "actual {actual:?} didn't match {expected:?} at '{relative_entry}': {components:?}",
175+ components = relative_entry.to_normal_path_components().collect::<Vec<_>>()
176+ );
174177 }
175178 }
176179 }
gix/Cargo.toml+1−1
@@ -9,7 +9,7 @@ version = "0.70.0" · 8 unmodified lines
99 authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
1010 edition = "2021"
1111 include = ["src/**/*", "LICENSE-*"]
12−rust-version = "1.70"
12+rust-version = "1.75"
1313
1414 [lib]
1515 doctest = false
gix/src/attribute_stack.rs+6−6
@@ -1,7 +1,7 @@
1+use crate::{types::AttributeStack, Repository};
2+use gix_fs::stack::ToNormalPathComponents;
13 use std::ops::{Deref, DerefMut};
24
3−use crate::{bstr::BStr, types::AttributeStack, Repository};
4−
55 /// Lifecycle
66 impl<'repo> AttributeStack<'repo> {
77 /// Create a new instance from a `repo` and the underlying pre-configured `stack`.
@@ -44,18 +44,18 @@ impl AttributeStack<'_> { · 36 unmodified lines
4444 relative: impl AsRef<std::path::Path>,
4545 mode: Option<gix_index::entry::Mode>,
4646 ) -> std::io::Result<gix_worktree::stack::Platform<'_>> {
47− self.inner.at_path(relative, mode, &self.repo.objects)
47+ self.inner.at_path(relative.as_ref(), mode, &self.repo.objects)
4848 }
4949
5050 /// Obtain a platform for attribute or ignore lookups from a repo-`relative` path, typically obtained from an index entry.
5151 /// `mode` should reflect whether it's a directory or not, or left at `None` if unknown.
5252 ///
5353 /// If `relative` ends with `/` and `mode` is `None`, it is automatically assumed to be a directory.
54− pub fn at_entry<'r>(
54+ pub fn at_entry(
5555 &mut self,
56− relative: impl Into<&'r BStr>,
56+ relative: impl ToNormalPathComponents,
5757 mode: Option<gix_index::entry::Mode>,
5858 ) -> std::io::Result<gix_worktree::stack::Platform<'_>> {
59− self.inner.at_entry(relative, mode, &self.repo.objects)
59+ self.inner.at_path(relative, mode, &self.repo.objects)
6060 }
6161 }
gix/src/id.rs+1−1
@@ -64,7 +64,7 @@ impl<'repo> Id<'repo> { · 63 unmodified lines
6464
6565 fn calculate_auto_hex_len(num_packed_objects: u64) -> usize {
6666 let mut len = 64 - num_packed_objects.leading_zeros();
67− len = (len + 1) / 2;
67+ len = len.div_ceil(2);
6868 len.max(7) as usize
6969 }
7070
tests/it/src/commands/copy_royal.rs+1−1
@@ -29,7 +29,7 @@ pub(super) mod function { · 28 unmodified lines
2929 {
3030 let rela_path = gix::path::from_bstr(rela_path);
3131 let src = worktree_dir.join(&rela_path);
32− stack.make_relative_path_current(&rela_path, &mut create_dir)?;
32+ stack.make_relative_path_current(&*rela_path, &mut create_dir)?;
3333 let dst = stack.current();
3434
3535 eprintln!(

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