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
1010 #![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
1111 #![deny(missing_docs, rust_2018_idioms, unsafe_code)]
1212 use bstr::BString;
13−pub use gix_glob;
13+/// A way to access the [`Case`](glob::pattern::Case) enum which used throughout this API.
14+pub use gix_glob as glob;
1415
1516 /// A cache for efficiently executing operations on directories and files which are encountered in sorted order.
1617 /// 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
108108 /// `objects` maybe used to lookup objects from an [id mapping][crate::stack::State::id_mappings_from_index()], with mappnigs
109109 ///
110110 /// Provide access to cached information for that `relative` path via the returned platform.
111− pub fn at_path<Find>(
111+ pub fn at_path(
112112 &mut self,
113113 relative: impl AsRef<Path>,
114114 is_dir: Option<bool>,
115− objects: Find,
116− ) -> std::io::Result<Platform<'_>>
117− where
118− Find: gix_object::Find,
119− {
115+ objects: &dyn gix_object::Find,
116+ ) -> std::io::Result<Platform<'_>> {
120117 self.statistics.platforms += 1;
121118 let mut delegate = StackDelegate {
122119 state: &mut self.state,
123120 buf: &mut self.buf,
124121 is_dir: is_dir.unwrap_or(false),
125122 id_mappings: &self.id_mappings,
126− objects: &objects,
123+ objects,
127124 case: self.case,
128125 statistics: &mut self.statistics,
129126 };
@@ -142,15 +139,12 @@ impl Stack { · 12 unmodified lines
142139 /// ### Panics
143140 ///
144141 /// on illformed UTF8 in `relative`
145− pub fn at_entry<'r, Find>(
142+ pub fn at_entry<'r>(
146143 &mut self,
147144 relative: impl Into<&'r BStr>,
148145 is_dir: Option<bool>,
149− objects: Find,
150− ) -> std::io::Result<Platform<'_>>
151− where
152− Find: gix_object::Find,
153− {
146+ objects: &dyn gix_object::Find,
147+ ) -> std::io::Result<Platform<'_>> {
154148 let relative = relative.into();
155149 let relative_path = gix_path::from_bstr(relative);
156150
gix-worktree/tests/worktree/stack/attributes.rs+2−2
@@ -29,7 +29,7 @@ fn baseline() -> crate::Result { · 28 unmodified lines
2929 let mut actual = cache.attribute_matches();
3030 let input = std::fs::read(base.join("baseline"))?;
3131 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)?;
3333 let has_match = entry.matching_attributes(&mut actual);
3434
3535 assert_eq!(
@@ -50,7 +50,7 @@ fn baseline() -> crate::Result { · 14 unmodified lines
5050 let mut actual = cache.selected_attribute_matches(["info", "test"]);
5151 let input = std::fs::read(base.join("baseline.selected"))?;
5252 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)?;
5454 let has_match = entry.matching_attributes(&mut actual);
5555
5656 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
1515 );
1616 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);
1717
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();
1919 assert!(!path.parent().unwrap().exists(), "prefix itself is never created");
2020 assert_eq!(cache.statistics().delegate.num_mkdir_calls, 0);
2121 Ok(())
@@ -33,7 +33,7 @@ fn directory_paths_are_created_in_full() { · 11 unmodified lines
3333 ("link", None),
3434 ] {
3535 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)
3737 .unwrap()
3838 .path();
3939 assert!(path.parent().unwrap().is_dir(), "dir exists");
@@ -47,7 +47,7 @@ fn existing_directories_are_fine() -> crate::Result { · 7 unmodified lines
4747 let (mut cache, tmp) = new_cache();
4848 std::fs::create_dir(tmp.path().join("dir"))?;
4949
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();
5151 assert!(path.parent().unwrap().is_dir(), "directory is still present");
5252 assert!(!path.exists(), "it won't create the file");
5353 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
7272 let relative_path = format!("{dirname}/file");
7373 assert_eq!(
7474 cache
75− .at_path(&relative_path, Some(false), gix_object::find::Never)
75+ .at_path(&relative_path, Some(false), &gix_object::find::Never)
7676 .unwrap_err()
7777 .kind(),
7878 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
9393 }
9494 let relative_path = format!("{dirname}/file");
9595 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)?
9797 .path();
9898 assert!(path.parent().unwrap().is_dir(), "directory was forcefully created");
9999 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
6565 let relative_path = gix_path::from_byte_slice(relative_entry);
6666 let is_dir = dir.join(relative_path).metadata().ok().map(|m| m.is_dir());
6767
68− let platform = cache.at_entry(relative_entry, is_dir, FindError).unwrap();
68+ let platform = cache.at_entry(relative_entry, is_dir, &FindError).unwrap();
6969 let match_ = platform.matching_exclude_pattern().expect("match all values");
7070 let _is_excluded = platform.is_excluded();
7171 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