History

feat!: Use `&dyn gix_object::Find` where possible.

As otherwise, one cannot use `&dyn ` at all in this case as it's unsized.` Additionally, rename top-level `pub use gix_glob` to `glob` to be in-line with other public exports of this kind.

Sebastian Thiel committed 2 years ago

Commit 552bed21 parent 0f03a085 files · +17 −22Browse files

Unified · Split

5 files
  1. gix-worktree/src/lib.rs +2 −1
  2. gix-worktree/src/stack/mod.rs +7 −13
  3. gix-worktree/tests/worktree/stack/attributes.rs +2 −2
  4. gix-worktree/tests/worktree/stack/create_directory.rs +5 −5
  5. gix-worktree/tests/worktree/stack/ignore.rs +1 −1
gix-worktree/src/lib.rs+2−1
@@ -10,7 +10,8 @@ · 9 unmodified lines
10#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]10#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
11#![deny(missing_docs, rust_2018_idioms, unsafe_code)]11#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
12use bstr::BString;12use bstr::BString;
13pub use gix_glob;13/// A way to access the [`Case`](glob::pattern::Case) enum which used throughout this API.
14pub use gix_glob as glob;
14 15
15/// A cache for efficiently executing operations on directories and files which are encountered in sorted order.16/// A cache for efficiently executing operations on directories and files which are encountered in sorted order.
16/// That way, these operations can be re-used for subsequent invocations in the same directory.17/// That way, these operations can be re-used for subsequent invocations in the same directory.
gix-worktree/src/stack/mod.rs+7−13
@@ -108,22 +108,19 @@ impl Stack { · 107 unmodified lines
108 /// `objects` maybe used to lookup objects from an [id mapping][crate::stack::State::id_mappings_from_index()], with mappnigs108 /// `objects` maybe used to lookup objects from an [id mapping][crate::stack::State::id_mappings_from_index()], with mappnigs
109 ///109 ///
110 /// Provide access to cached information for that `relative` path via the returned platform.110 /// Provide access to cached information for that `relative` path via the returned platform.
111 pub fn at_path<Find>(111 pub fn at_path(
112 &mut self,112 &mut self,
113 relative: impl AsRef<Path>,113 relative: impl AsRef<Path>,
114 is_dir: Option<bool>,114 is_dir: Option<bool>,
115 objects: Find,115 objects: &dyn gix_object::Find,
116 ) -> std::io::Result<Platform<'_>>116 ) -> std::io::Result<Platform<'_>> {
117 where
118 Find: gix_object::Find,
119 {
120 self.statistics.platforms += 1;117 self.statistics.platforms += 1;
121 let mut delegate = StackDelegate {118 let mut delegate = StackDelegate {
122 state: &mut self.state,119 state: &mut self.state,
123 buf: &mut self.buf,120 buf: &mut self.buf,
124 is_dir: is_dir.unwrap_or(false),121 is_dir: is_dir.unwrap_or(false),
125 id_mappings: &self.id_mappings,122 id_mappings: &self.id_mappings,
126 objects: &objects,123 objects,
127 case: self.case,124 case: self.case,
128 statistics: &mut self.statistics,125 statistics: &mut self.statistics,
129 };126 };
@@ -142,15 +139,12 @@ impl Stack { · 12 unmodified lines
142 /// ### Panics139 /// ### Panics
143 ///140 ///
144 /// on illformed UTF8 in `relative`141 /// on illformed UTF8 in `relative`
145 pub fn at_entry<'r, Find>(142 pub fn at_entry<'r>(
146 &mut self,143 &mut self,
147 relative: impl Into<&'r BStr>,144 relative: impl Into<&'r BStr>,
148 is_dir: Option<bool>,145 is_dir: Option<bool>,
149 objects: Find,146 objects: &dyn gix_object::Find,
150 ) -> std::io::Result<Platform<'_>>147 ) -> std::io::Result<Platform<'_>> {
151 where
152 Find: gix_object::Find,
153 {
154 let relative = relative.into();148 let relative = relative.into();
155 let relative_path = gix_path::from_bstr(relative);149 let relative_path = gix_path::from_bstr(relative);
156 150
gix-worktree/tests/worktree/stack/attributes.rs+2−2
@@ -29,7 +29,7 @@ fn baseline() -> crate::Result { · 28 unmodified lines
29 let mut actual = cache.attribute_matches();29 let mut actual = cache.attribute_matches();
30 let input = std::fs::read(base.join("baseline"))?;30 let input = std::fs::read(base.join("baseline"))?;
31 for (rela_path, expected) in (baseline::Expectations { lines: input.lines() }) {31 for (rela_path, expected) in (baseline::Expectations { lines: input.lines() }) {
32 let entry = cache.at_entry(rela_path, None, gix_object::find::Never)?;32 let entry = cache.at_entry(rela_path, None, &gix_object::find::Never)?;
33 let has_match = entry.matching_attributes(&mut actual);33 let has_match = entry.matching_attributes(&mut actual);
34 34
35 assert_eq!(35 assert_eq!(
@@ -50,7 +50,7 @@ fn baseline() -> crate::Result { · 14 unmodified lines
50 let mut actual = cache.selected_attribute_matches(["info", "test"]);50 let mut actual = cache.selected_attribute_matches(["info", "test"]);
51 let input = std::fs::read(base.join("baseline.selected"))?;51 let input = std::fs::read(base.join("baseline.selected"))?;
52 for (rela_path, expected) in (baseline::Expectations { lines: input.lines() }) {52 for (rela_path, expected) in (baseline::Expectations { lines: input.lines() }) {
53 let entry = cache.at_entry(rela_path, None, gix_object::find::Never)?;53 let entry = cache.at_entry(rela_path, None, &gix_object::find::Never)?;
54 let has_match = entry.matching_attributes(&mut actual);54 let has_match = entry.matching_attributes(&mut actual);
55 55
56 assert_eq!(56 assert_eq!(
gix-worktree/tests/worktree/stack/create_directory.rs+5−5
@@ -15,7 +15,7 @@ fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory() -> crate · 14 unmodified lines
15 );15 );
16 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);16 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);
17 17
18 let path = cache.at_path("hello", Some(false), gix_object::find::Never)?.path();18 let path = cache.at_path("hello", Some(false), &gix_object::find::Never)?.path();
19 assert!(!path.parent().unwrap().exists(), "prefix itself is never created");19 assert!(!path.parent().unwrap().exists(), "prefix itself is never created");
20 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);20 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);
21 Ok(())21 Ok(())
@@ -33,7 +33,7 @@ fn directory_paths_are_created_in_full() { · 11 unmodified lines
33 ("link", None),33 ("link", None),
34 ] {34 ] {
35 let path = cache35 let path = cache
36 .at_path(Path::new("dir").join(name), *is_dir, gix_object::find::Never)36 .at_path(Path::new("dir").join(name), *is_dir, &gix_object::find::Never)
37 .unwrap()37 .unwrap()
38 .path();38 .path();
39 assert!(path.parent().unwrap().is_dir(), "dir exists");39 assert!(path.parent().unwrap().is_dir(), "dir exists");
@@ -47,7 +47,7 @@ fn existing_directories_are_fine() -> crate::Result { · 7 unmodified lines
47 let (mut cache, tmp) = new_cache();47 let (mut cache, tmp) = new_cache();
48 std::fs::create_dir(tmp.path().join("dir"))?;48 std::fs::create_dir(tmp.path().join("dir"))?;
49 49
50 let path = cache.at_path("dir/file", Some(false), gix_object::find::Never)?.path();50 let path = cache.at_path("dir/file", Some(false), &gix_object::find::Never)?.path();
51 assert!(path.parent().unwrap().is_dir(), "directory is still present");51 assert!(path.parent().unwrap().is_dir(), "directory is still present");
52 assert!(!path.exists(), "it won't create the file");52 assert!(!path.exists(), "it won't create the file");
53 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 1);53 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 1);
@@ -72,7 +72,7 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R · 18 unmodified lines
72 let relative_path = format!("{dirname}/file");72 let relative_path = format!("{dirname}/file");
73 assert_eq!(73 assert_eq!(
74 cache74 cache
75 .at_path(&relative_path, Some(false), gix_object::find::Never)75 .at_path(&relative_path, Some(false), &gix_object::find::Never)
76 .unwrap_err()76 .unwrap_err()
77 .kind(),77 .kind(),
78 std::io::ErrorKind::AlreadyExists78 std::io::ErrorKind::AlreadyExists
@@ -93,7 +93,7 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R · 14 unmodified lines
93 }93 }
94 let relative_path = format!("{dirname}/file");94 let relative_path = format!("{dirname}/file");
95 let path = cache95 let path = cache
96 .at_path(&relative_path, Some(false), gix_object::find::Never)?96 .at_path(&relative_path, Some(false), &gix_object::find::Never)?
97 .path();97 .path();
98 assert!(path.parent().unwrap().is_dir(), "directory was forcefully created");98 assert!(path.parent().unwrap().is_dir(), "directory was forcefully created");
99 assert!(!path.exists());99 assert!(!path.exists());
gix-worktree/tests/worktree/stack/ignore.rs+1−1
@@ -65,7 +65,7 @@ fn exclude_by_dir_is_handled_just_like_git() { · 64 unmodified lines
65 let relative_path = gix_path::from_byte_slice(relative_entry);65 let relative_path = gix_path::from_byte_slice(relative_entry);
66 let is_dir = dir.join(relative_path).metadata().ok().map(|m| m.is_dir());66 let is_dir = dir.join(relative_path).metadata().ok().map(|m| m.is_dir());
67 67
68 let platform = cache.at_entry(relative_entry, is_dir, FindError).unwrap();68 let platform = cache.at_entry(relative_entry, is_dir, &FindError).unwrap();
69 let match_ = platform.matching_exclude_pattern().expect("match all values");69 let match_ = platform.matching_exclude_pattern().expect("match all values");
70 let _is_excluded = platform.is_excluded();70 let _is_excluded = platform.is_excluded();
71 assert_eq!(71 assert_eq!(

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