Skip to content

Commit bb3a735

Browse files
committed
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.
1 parent ccb1a08 commit bb3a735

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

gix-worktree/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#![cfg_attr(docsrs, 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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,19 @@ impl Stack {
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 {
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn baseline() -> crate::Result {
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 {
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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory() -> crate
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() {
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 {
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
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
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn exclude_by_dir_is_handled_just_like_git() {
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!(

0 commit comments

Comments
 (0)