From 072ee32f693a31161cd6a843da6582d13efbb20b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Sep 2023 13:46:41 +0200 Subject: [PATCH] fix!: use `dyn` trait where possible. This reduces compile time due to avoiding duplication. --- Cargo.lock | 10 +- gitoxide-core/src/commitgraph/verify.rs | 2 +- gitoxide-core/src/corpus/run.rs | 3 +- gitoxide-core/src/index/checkout.rs | 8 +- gitoxide-core/src/organize.rs | 4 +- gitoxide-core/src/pack/create.rs | 21 ++-- gitoxide-core/src/pack/explode.rs | 31 +++--- gitoxide-core/src/pack/index.rs | 16 +-- gitoxide-core/src/pack/multi_index.rs | 8 +- gitoxide-core/src/pack/receive.rs | 22 ++-- gitoxide-core/src/pack/verify.rs | 8 +- gitoxide-core/src/repository/archive.rs | 2 +- .../src/repository/attributes/query.rs | 6 +- gitoxide-core/src/repository/clone.rs | 3 +- gitoxide-core/src/repository/exclude.rs | 8 +- gitoxide-core/src/repository/index/entries.rs | 42 +++---- gitoxide-core/src/repository/verify.rs | 8 +- gix-actor/src/identity.rs | 4 +- gix-actor/src/signature/mod.rs | 4 +- gix-actor/tests/signature/mod.rs | 6 +- gix-attributes/src/search/attributes.rs | 15 ++- gix-attributes/src/search/outcome.rs | 11 +- gix-attributes/tests/search/mod.rs | 10 +- gix-commitgraph/src/file/access.rs | 5 +- gix-commitgraph/src/file/verify.rs | 3 +- gix-commitgraph/src/init.rs | 17 ++- gix-commitgraph/src/lib.rs | 2 +- gix-commitgraph/tests/commitgraph.rs | 3 +- gix-config/fuzz/fuzz_targets/parse.rs | 2 +- gix-config/src/file/access/comfort.rs | 31 +++--- gix-config/src/file/access/mutate.rs | 56 ++++++++-- gix-config/src/file/access/raw.rs | 52 +++++++-- gix-config/src/file/access/read_only.rs | 13 +-- gix-config/src/file/init/comfort.rs | 6 +- gix-config/src/file/init/from_paths.rs | 17 +-- gix-config/src/file/mutable/section.rs | 10 +- gix-config/src/file/section/body.rs | 14 +-- gix-config/src/file/section/mod.rs | 2 +- gix-config/src/file/write.rs | 8 +- gix-config/src/parse/event.rs | 2 +- gix-config/src/parse/events.rs | 8 +- gix-config/src/parse/key.rs | 3 +- gix-config/src/parse/nom/mod.rs | 12 +- gix-config/tests/config.rs | 2 +- gix-config/tests/file/init/from_env.rs | 2 +- gix-config/tests/file/mod.rs | 2 +- gix-config/tests/file/mutable/section.rs | 6 +- gix-config/tests/file/write.rs | 2 +- gix-config/tests/parse/key.rs | 8 +- gix-credentials/src/helper/invoke.rs | 7 +- gix-credentials/src/program/mod.rs | 42 +++---- gix-date/src/time/format.rs | 6 +- gix-date/src/time/write.rs | 2 +- gix-date/tests/time/baseline.rs | 2 +- gix-diff/tests/diff.rs | 2 +- gix-diff/tests/tree/mod.rs | 10 +- gix-discover/src/is.rs | 22 ++-- gix-discover/src/path.rs | 8 +- gix-discover/src/repository.rs | 13 +-- gix-discover/src/upwards/mod.rs | 17 ++- gix-discover/src/upwards/util.rs | 4 +- gix-discover/tests/is_git/mod.rs | 12 +- gix-discover/tests/isolated.rs | 16 +-- gix-discover/tests/upwards/ceiling_dirs.rs | 20 ++-- gix-discover/tests/upwards/mod.rs | 28 ++--- gix-features/src/cache.rs | 6 +- gix-features/src/fs.rs | 8 +- gix-features/src/hash.rs | 10 +- gix-features/src/io.rs | 6 +- gix-features/src/progress.rs | 2 +- gix-features/tests/pipe.rs | 4 +- gix-filter/examples/arrow.rs | 2 +- gix-filter/src/driver/apply.rs | 2 +- gix-filter/src/driver/delayed.rs | 8 +- gix-filter/src/driver/process/client.rs | 16 +-- gix-filter/src/driver/process/server.rs | 2 +- gix-filter/src/eol/convert_to_git.rs | 19 ++-- gix-filter/src/pipeline/convert.rs | 20 ++-- gix-filter/src/pipeline/util.rs | 2 +- gix-filter/tests/driver/mod.rs | 12 +- gix-filter/tests/eol/convert_to_git.rs | 32 +++--- gix-filter/tests/filter.rs | 2 +- gix-filter/tests/pipeline/convert_to_git.rs | 23 ++-- .../tests/pipeline/convert_to_worktree.rs | 6 +- gix-filter/tests/pipeline/mod.rs | 7 +- gix-fs/src/capabilities.rs | 11 +- gix-fs/src/dir/create.rs | 14 +-- gix-fs/src/dir/remove.rs | 3 +- gix-fs/src/stack.rs | 10 +- gix-fs/tests/dir/remove.rs | 2 +- gix-fs/tests/stack/mod.rs | 20 ++-- gix-glob/src/pattern.rs | 8 +- gix-glob/src/search/mod.rs | 9 +- gix-glob/src/search/pattern.rs | 10 +- gix-glob/tests/pattern/matching.rs | 4 +- gix-glob/tests/search/pattern.rs | 6 +- gix-glob/tests/wildmatch/mod.rs | 2 +- gix-hash/src/oid.rs | 2 +- gix-hash/src/prefix.rs | 3 +- gix-hash/tests/prefix/mod.rs | 10 +- gix-ignore/src/search.rs | 19 ++-- gix-ignore/tests/search/mod.rs | 12 +- gix-index/src/file/init.rs | 4 +- gix-lock/src/acquire.rs | 6 +- gix-negotiate/src/lib.rs | 4 +- gix-negotiate/tests/baseline/mod.rs | 10 +- gix-negotiate/tests/negotiate.rs | 6 +- gix-object/src/blob.rs | 20 ++-- gix-object/src/commit/write.rs | 4 +- gix-object/src/data.rs | 3 +- gix-object/src/encode.rs | 18 +-- gix-object/src/object/mod.rs | 20 ++-- gix-object/src/tag/write.rs | 12 +- gix-object/src/traits.rs | 12 +- gix-object/src/tree/write.rs | 4 +- gix-object/tests/object.rs | 2 +- gix-odb/src/alternate/mod.rs | 15 +-- gix-odb/src/cache.rs | 30 ++--- gix-odb/src/find.rs | 14 ++- gix-odb/src/lib.rs | 13 ++- gix-odb/src/sink.rs | 14 +-- gix-odb/src/store_impls/dynamic/find.rs | 34 ++---- gix-odb/src/store_impls/dynamic/handle.rs | 4 +- gix-odb/src/store_impls/dynamic/header.rs | 10 +- gix-odb/src/store_impls/dynamic/init.rs | 9 +- gix-odb/src/store_impls/dynamic/load_index.rs | 2 +- gix-odb/src/store_impls/dynamic/prefix.rs | 4 +- gix-odb/src/store_impls/dynamic/verify.rs | 42 +++---- gix-odb/src/store_impls/dynamic/write.rs | 7 +- gix-odb/src/store_impls/loose/find.rs | 18 +-- gix-odb/src/store_impls/loose/verify.rs | 8 +- gix-odb/src/store_impls/loose/write.rs | 36 +++--- gix-odb/src/traits.rs | 104 ++++++------------ gix-odb/tests/odb/alternate/mod.rs | 6 +- gix-odb/tests/odb/find/mod.rs | 2 +- gix-odb/tests/odb/header/mod.rs | 2 +- gix-odb/tests/odb/mod.rs | 2 +- gix-odb/tests/odb/regression/mod.rs | 2 +- gix-odb/tests/odb/sink/mod.rs | 2 +- gix-odb/tests/odb/store/compound.rs | 2 +- gix-odb/tests/odb/store/dynamic.rs | 95 ++++++++-------- gix-odb/tests/odb/store/linked.rs | 12 +- gix-odb/tests/odb/store/loose.rs | 40 +++---- gix-pack/src/bundle/find.rs | 8 +- gix-pack/src/bundle/mod.rs | 14 +-- gix-pack/src/bundle/write/mod.rs | 51 ++++----- gix-pack/src/cache/delta/from_offsets.rs | 8 +- gix-pack/src/cache/delta/mod.rs | 8 +- gix-pack/src/cache/delta/traverse/mod.rs | 22 ++-- gix-pack/src/cache/delta/traverse/resolve.rs | 22 ++-- gix-pack/src/data/entry/decode.rs | 8 +- gix-pack/src/data/entry/header.rs | 4 +- gix-pack/src/data/file/decode/entry.rs | 8 +- gix-pack/src/data/file/decode/header.rs | 2 +- gix-pack/src/data/file/verify.rs | 2 +- gix-pack/src/data/input/bytes_to_entries.rs | 2 +- gix-pack/src/data/input/entry.rs | 2 +- .../data/input/lookup_ref_delta_objects.rs | 12 +- gix-pack/src/data/output/count/mod.rs | 2 +- gix-pack/src/data/output/count/objects/mod.rs | 71 +++++------- .../src/data/output/count/objects/types.rs | 10 +- .../src/data/output/entry/iter_from_counts.rs | 27 ++--- gix-pack/src/data/output/entry/mod.rs | 9 +- gix-pack/src/find.rs | 21 ++-- gix-pack/src/find_traits.rs | 82 ++++++-------- gix-pack/src/index/access.rs | 11 +- gix-pack/src/index/traverse/mod.rs | 19 ++-- gix-pack/src/index/traverse/with_index.rs | 37 ++++--- gix-pack/src/index/traverse/with_lookup.rs | 24 ++-- gix-pack/src/index/util.rs | 2 +- gix-pack/src/index/verify.rs | 20 ++-- gix-pack/src/index/write/encode.rs | 20 ++-- gix-pack/src/index/write/mod.rs | 28 +++-- gix-pack/src/multi_index/access.rs | 4 +- gix-pack/src/multi_index/chunk.rs | 12 +- gix-pack/src/multi_index/verify.rs | 46 ++++---- gix-pack/src/multi_index/write.rs | 33 +++--- gix-pack/src/verify.rs | 4 +- gix-pack/tests/pack/bundle.rs | 10 +- gix-pack/tests/pack/data/file.rs | 6 +- .../pack/data/output/count_and_entries.rs | 40 +++---- gix-pack/tests/pack/data/output/mod.rs | 2 +- gix-pack/tests/pack/index.rs | 12 +- gix-pack/tests/pack/mod.rs | 2 +- gix-pack/tests/pack/multi_index/access.rs | 6 +- gix-pack/tests/pack/multi_index/verify.rs | 4 +- gix-pack/tests/pack/multi_index/write.rs | 8 +- gix-path/src/convert.rs | 4 +- gix-path/src/realpath.rs | 7 +- gix-path/tests/convert/normalize.rs | 49 ++++++--- gix-path/tests/realpath/mod.rs | 23 ++-- gix-pathspec/src/defaults.rs | 2 +- gix-pathspec/src/pattern.rs | 4 +- gix-pathspec/src/search/init.rs | 64 ++++++----- gix-pathspec/src/search/matching.rs | 7 +- gix-pathspec/tests/defaults.rs | 12 +- gix-pathspec/tests/search/mod.rs | 16 ++- gix-protocol/src/fetch/delegate.rs | 12 +- gix-protocol/src/fetch_fn.rs | 2 +- gix-ref/src/fullname.rs | 2 +- gix-ref/src/name.rs | 8 +- gix-ref/src/namespace.rs | 5 +- gix-ref/src/peel.rs | 3 +- gix-ref/src/store/file/find.rs | 2 +- gix-ref/src/store/file/log/line.rs | 4 +- gix-ref/src/store/file/loose/iter.rs | 7 +- gix-ref/src/store/file/loose/mod.rs | 12 +- gix-ref/src/store/file/loose/reflog.rs | 2 +- .../loose/reflog/create_or_update/tests.rs | 2 +- gix-ref/src/store/file/overlay_iter.rs | 13 +-- gix-ref/src/store/file/raw_ext.rs | 32 +++--- gix-ref/src/store/file/transaction/prepare.rs | 24 +++- gix-ref/src/store/general/init.rs | 7 +- gix-ref/src/store/packed/buffer.rs | 3 +- gix-ref/src/store/packed/iter.rs | 3 +- gix-ref/src/store/packed/transaction.rs | 6 +- gix-ref/src/transaction/ext.rs | 12 +- gix-ref/tests/file/reference.rs | 14 +-- gix-ref/tests/file/store/find.rs | 8 +- gix-ref/tests/file/store/iter.rs | 14 +-- gix-ref/tests/file/transaction/mod.rs | 6 +- .../create_or_update/mod.rs | 6 +- gix-ref/tests/file/worktree.rs | 21 ++-- gix-ref/tests/namespace/mod.rs | 2 +- gix-ref/tests/packed/iter.rs | 10 +- gix-ref/tests/refs.rs | 2 +- gix-ref/tests/transaction/mod.rs | 24 ++-- gix-refspec/src/write.rs | 4 +- gix-revision/src/describe.rs | 4 +- gix-revision/tests/describe/mod.rs | 2 +- gix-revwalk/src/graph/mod.rs | 20 ++-- gix-sec/src/identity.rs | 9 +- gix-sec/src/trust.rs | 4 +- gix-sec/tests/identity/mod.rs | 4 +- gix-status/tests/status/index_as_worktree.rs | 2 +- gix-submodule/src/access.rs | 18 +-- gix-submodule/src/is_active_platform.rs | 2 +- gix-submodule/src/lib.rs | 2 +- gix-tempfile/src/forksafe.rs | 6 +- gix-tempfile/src/handle.rs | 18 +-- gix-tempfile/src/lib.rs | 2 +- .../client/blocking_io/http/curl/remote.rs | 2 +- gix-traverse/tests/traverse.rs | 2 +- gix-traverse/tests/tree/mod.rs | 12 +- gix-url/src/lib.rs | 7 +- gix-url/tests/access/mod.rs | 9 +- gix-worktree-state/src/checkout/entry.rs | 2 +- gix-worktree-state/tests/state/checkout.rs | 6 +- gix-worktree-stream/src/from_tree/traverse.rs | 2 +- gix-worktree/src/stack/delegate.rs | 18 +-- gix-worktree/src/stack/mod.rs | 7 +- gix-worktree/src/stack/state/attributes.rs | 13 +-- gix-worktree/src/stack/state/ignore.rs | 11 +- gix-worktree/tests/worktree/mod.rs | 2 +- gix-worktree/tests/worktree/stack/ignore.rs | 2 +- gix-worktree/tests/worktree/stack/mod.rs | 2 +- gix/src/clone/checkout.rs | 9 +- gix/src/clone/fetch/util.rs | 9 +- gix/src/commit.rs | 2 +- gix/src/config/cache/access.rs | 2 +- gix/src/config/cache/init.rs | 4 +- gix/src/config/overrides.rs | 8 +- gix/src/config/snapshot/access.rs | 5 +- gix/src/create.rs | 2 +- gix/src/discover.rs | 2 +- gix/src/filter.rs | 8 +- gix/src/object/errors.rs | 10 +- gix/src/object/tree/mod.rs | 4 +- gix/src/open/repository.rs | 12 +- gix/src/pathspec.rs | 9 +- gix/src/reference/iter.rs | 12 +- gix/src/reference/mod.rs | 4 +- gix/src/remote/connect.rs | 6 +- .../remote/connection/fetch/receive_pack.rs | 36 +++--- .../connection/fetch/update_refs/mod.rs | 3 +- .../connection/fetch/update_refs/tests.rs | 2 +- gix/src/repository/object.rs | 18 +-- gix/src/revision/walk.rs | 2 +- gix/src/submodule/mod.rs | 2 +- gix/tests/clone/mod.rs | 5 +- gix/tests/remote/fetch.rs | 1 + gix/tests/remote/save.rs | 7 +- gix/tests/repository/object.rs | 2 +- gix/tests/repository/shallow.rs | 3 +- gix/tests/repository/worktree.rs | 5 +- gix/tests/revision/spec/from_bytes/util.rs | 1 + gix/tests/util/mod.rs | 2 +- src/shared.rs | 2 +- tests/tools/src/lib.rs | 2 +- 289 files changed, 1694 insertions(+), 1641 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcf595ff7d9..6458d8165e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1137,7 +1137,7 @@ dependencies = [ "is-terminal", "once_cell", "owo-colors", - "prodash 26.2.0", + "prodash 26.2.1", "serde_derive", "tabled", "time", @@ -1237,7 +1237,7 @@ dependencies = [ "log", "once_cell", "parking_lot", - "prodash 26.2.0", + "prodash 26.2.1", "regex", "reqwest", "serde", @@ -1570,7 +1570,7 @@ dependencies = [ "libc", "once_cell", "parking_lot", - "prodash 26.2.0", + "prodash 26.2.1", "sha1", "sha1_smol", "thiserror", @@ -3503,9 +3503,9 @@ checksum = "9516b775656bc3e8985e19cd4b8c0c0de045095074e453d2c0a513b5f978392d" [[package]] name = "prodash" -version = "26.2.0" +version = "26.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdc60e4df7c418baa9fbfc62b5054b06745dfc3a2aee40294ad390b701f6351" +checksum = "50bcc40e3e88402f12b15f94d43a2c7673365e9601cc52795e119b95a266100c" dependencies = [ "async-io", "bytesize", diff --git a/gitoxide-core/src/commitgraph/verify.rs b/gitoxide-core/src/commitgraph/verify.rs index 3a4623a1c21..8d601a762d3 100644 --- a/gitoxide-core/src/commitgraph/verify.rs +++ b/gitoxide-core/src/commitgraph/verify.rs @@ -39,7 +39,7 @@ pub(crate) mod function { W1: io::Write, W2: io::Write, { - let g = Graph::at(path).with_context(|| "Could not open commit graph")?; + let g = Graph::at(path.as_ref()).with_context(|| "Could not open commit graph")?; #[allow(clippy::unnecessary_wraps, unknown_lints)] fn noop_processor(_commit: &gix::commitgraph::file::Commit<'_>) -> std::result::Result<(), std::fmt::Error> { diff --git a/gitoxide-core/src/corpus/run.rs b/gitoxide-core/src/corpus/run.rs index fb924fc1d05..1cabea65115 100644 --- a/gitoxide-core/src/corpus/run.rs +++ b/gitoxide-core/src/corpus/run.rs @@ -1,3 +1,4 @@ +use gix::progress::DynNestedProgress; use std::{path::Path, sync::atomic::AtomicBool}; use crate::{ @@ -141,7 +142,7 @@ impl Execute for VerifyOdb { crate::repository::verify::integrity( repo, std::io::sink(), - progress, + progress.add_child("integrity".into()), should_interrupt, crate::repository::verify::Context { output_statistics: None, diff --git a/gitoxide-core/src/index/checkout.rs b/gitoxide-core/src/index/checkout.rs index 5ecb3688860..f7f31432c7d 100644 --- a/gitoxide-core/src/index/checkout.rs +++ b/gitoxide-core/src/index/checkout.rs @@ -104,8 +104,8 @@ pub fn checkout_exclusive( } } }, - &mut files, - &mut bytes, + &files, + &bytes, should_interrupt, opts, ), @@ -116,8 +116,8 @@ pub fn checkout_exclusive( buf.clear(); Ok(gix::objs::BlobRef { data: buf }) }, - &mut files, - &mut bytes, + &files, + &bytes, should_interrupt, opts, ), diff --git a/gitoxide-core/src/organize.rs b/gitoxide-core/src/organize.rs index 1feed705a18..04764c2df5d 100644 --- a/gitoxide-core/src/organize.rs +++ b/gitoxide-core/src/organize.rs @@ -92,8 +92,8 @@ pub fn find_git_repository_workdirs( fn find_origin_remote(repo: &Path) -> anyhow::Result> { let non_bare = repo.join(".git").join("config"); let local = gix::config::Source::Local; - let config = gix::config::File::from_path_no_includes(non_bare.as_path(), local) - .or_else(|_| gix::config::File::from_path_no_includes(repo.join("config").as_path(), local))?; + let config = gix::config::File::from_path_no_includes(non_bare.as_path().into(), local) + .or_else(|_| gix::config::File::from_path_no_includes(repo.join("config"), local))?; Ok(config .string_by_key("remote.origin.url") .map(|url| gix_url::Url::from_bytes(url.as_ref())) diff --git a/gitoxide-core/src/pack/create.rs b/gitoxide-core/src/pack/create.rs index 7501e22a27f..6b3d3d65d8c 100644 --- a/gitoxide-core/src/pack/create.rs +++ b/gitoxide-core/src/pack/create.rs @@ -112,14 +112,13 @@ where P: NestedProgress, P::SubProgress: 'static, { + type ObjectIdIter = dyn Iterator>> + Send; + let repo = gix::discover(repository_path)?.into_sync(); progress.init(Some(2), progress::steps()); let tips = tips.into_iter(); let make_cancellation_err = || anyhow!("Cancelled by user"); - let (mut handle, input): ( - _, - Box> + Send>, - ) = match input { + let (mut handle, mut input): (_, Box) = match input { None => { let mut progress = progress.add_child("traversing"); progress.init(None, progress::count("commits")); @@ -141,7 +140,7 @@ where let handle = handle.clone(); move |oid, buf| handle.find_commit_iter(oid, buf).map(|t| t.0) }) - .map(|res| res.map_err(Into::into).map(|c| c.id)) + .map(|res| res.map_err(|err| Box::new(err) as Box<_>).map(|c| c.id)) .inspect(move |_| progress.inc()), ); (handle, iter) @@ -157,7 +156,7 @@ where .lines() .map(|hex_id| { hex_id - .map_err(Into::into) + .map_err(|err| Box::new(err) as Box<_>) .and_then(|hex_id| ObjectId::from_hex(hex_id.as_bytes()).map_err(Into::into)) }) .inspect(move |_| progress.inc()), @@ -207,7 +206,7 @@ where pack::data::output::count::objects( handle.clone(), input, - progress, + &progress, &interrupt::IS_INTERRUPTED, pack::data::output::count::objects::Options { thread_limit, @@ -217,9 +216,9 @@ where )? } else { pack::data::output::count::objects_unthreaded( - handle.clone(), - input, - progress, + &handle, + &mut input, + &progress, &interrupt::IS_INTERRUPTED, input_object_expansion, )? @@ -236,7 +235,7 @@ where InOrderIter::from(pack::data::output::entry::iter_from_counts( counts, handle, - progress, + Box::new(progress), pack::data::output::entry::iter_from_counts::Options { thread_limit, mode: pack::data::output::entry::iter_from_counts::Mode::PackCopyAndBaseObjects, diff --git a/gitoxide-core/src/pack/explode.rs b/gitoxide-core/src/pack/explode.rs index 5b00f29da0c..f73a54533ad 100644 --- a/gitoxide-core/src/pack/explode.rs +++ b/gitoxide-core/src/pack/explode.rs @@ -97,19 +97,22 @@ enum OutputWriter { } impl gix::odb::Write for OutputWriter { - type Error = Error; - - fn write_buf(&self, kind: object::Kind, from: &[u8]) -> Result { + fn write_buf(&self, kind: object::Kind, from: &[u8]) -> Result { match self { - OutputWriter::Loose(db) => db.write_buf(kind, from).map_err(Into::into), - OutputWriter::Sink(db) => db.write_buf(kind, from).map_err(Into::into), + OutputWriter::Loose(db) => db.write_buf(kind, from), + OutputWriter::Sink(db) => db.write_buf(kind, from), } } - fn write_stream(&self, kind: object::Kind, size: u64, from: impl Read) -> Result { + fn write_stream( + &self, + kind: object::Kind, + size: u64, + from: &mut dyn Read, + ) -> Result { match self { - OutputWriter::Loose(db) => db.write_stream(kind, size, from).map_err(Into::into), - OutputWriter::Sink(db) => db.write_stream(kind, size, from).map_err(Into::into), + OutputWriter::Loose(db) => db.write_stream(kind, size, from), + OutputWriter::Sink(db) => db.write_stream(kind, size, from), } } } @@ -137,7 +140,7 @@ pub fn pack_or_pack_index( pack_path: impl AsRef, object_path: Option>, check: SafetyCheck, - progress: impl NestedProgress, + mut progress: impl NestedProgress + 'static, Context { thread_limit, delete_pack, @@ -178,11 +181,11 @@ pub fn pack_or_pack_index( |_| pack::index::traverse::Algorithm::Lookup, ); - let pack::index::traverse::Outcome { progress, .. } = bundle + let pack::index::traverse::Outcome { .. } = bundle .index .traverse( &bundle.pack, - progress, + &mut progress, &should_interrupt, { let object_path = object_path.map(|p| p.as_ref().to_owned()); @@ -193,7 +196,7 @@ pub fn pack_or_pack_index( let mut read_buf = Vec::new(); move |object_kind, buf, index_entry, progress| { let written_id = out.write_buf(object_kind, buf).map_err(|err| Error::Write { - source: Box::new(err) as Box, + source: err, kind: object_kind, id: index_entry.oid, })?; @@ -213,13 +216,13 @@ pub fn pack_or_pack_index( } if let Some(verifier) = loose_odb.as_ref() { let obj = verifier - .try_find(written_id, &mut read_buf) + .try_find(&written_id, &mut read_buf) .map_err(|err| Error::WrittenFileCorrupt { source: err, id: written_id, })? .ok_or(Error::WrittenFileMissing { id: written_id })?; - obj.verify_checksum(written_id)?; + obj.verify_checksum(&written_id)?; } Ok(()) } diff --git a/gitoxide-core/src/pack/index.rs b/gitoxide-core/src/pack/index.rs index 36a69258497..814f43d0697 100644 --- a/gitoxide-core/src/pack/index.rs +++ b/gitoxide-core/src/pack/index.rs @@ -70,16 +70,12 @@ pub enum PathOrRead { Read(Box), } -pub fn from_pack

( +pub fn from_pack( pack: PathOrRead, directory: Option, - progress: P, + mut progress: impl NestedProgress + 'static, ctx: Context<'static, impl io::Write>, -) -> anyhow::Result<()> -where - P: NestedProgress, - P::SubProgress: 'static, -{ +) -> anyhow::Result<()> { use anyhow::Context; let options = pack::bundle::write::Options { thread_limit: ctx.thread_limit, @@ -94,10 +90,10 @@ where let pack_len = pack.metadata()?.len(); let pack_file = fs::File::open(pack)?; pack::Bundle::write_to_directory_eagerly( - pack_file, + Box::new(pack_file), Some(pack_len), directory, - progress, + &mut progress, ctx.should_interrupt, None, options, @@ -107,7 +103,7 @@ where input, None, directory, - progress, + &mut progress, ctx.should_interrupt, None, options, diff --git a/gitoxide-core/src/pack/multi_index.rs b/gitoxide-core/src/pack/multi_index.rs index b8e0603f480..c49b2723b1f 100644 --- a/gitoxide-core/src/pack/multi_index.rs +++ b/gitoxide-core/src/pack/multi_index.rs @@ -9,17 +9,17 @@ pub const PROGRESS_RANGE: std::ops::RangeInclusive = 1..=3; pub fn verify( multi_index_path: PathBuf, - progress: impl NestedProgress, + mut progress: impl NestedProgress + 'static, should_interrupt: &AtomicBool, ) -> anyhow::Result<()> { - gix::odb::pack::multi_index::File::at(multi_index_path)?.verify_integrity_fast(progress, should_interrupt)?; + gix::odb::pack::multi_index::File::at(multi_index_path)?.verify_integrity_fast(&mut progress, should_interrupt)?; Ok(()) } pub fn create( index_paths: Vec, output_path: PathBuf, - progress: impl NestedProgress, + mut progress: impl NestedProgress + 'static, should_interrupt: &AtomicBool, object_hash: gix::hash::Kind, ) -> anyhow::Result<()> { @@ -31,7 +31,7 @@ pub fn create( gix::odb::pack::multi_index::File::write_from_index_paths( index_paths, &mut out, - progress, + &mut progress, should_interrupt, gix::odb::pack::multi_index::write::Options { object_hash }, )?; diff --git a/gitoxide-core/src/pack/receive.rs b/gitoxide-core/src/pack/receive.rs index 9e4c009bb54..fe6de13e697 100644 --- a/gitoxide-core/src/pack/receive.rs +++ b/gitoxide-core/src/pack/receive.rs @@ -130,7 +130,7 @@ mod blocking_io { fn receive_pack( &mut self, input: impl BufRead, - progress: impl NestedProgress, + progress: impl NestedProgress + 'static, refs: &[Ref], _previous_response: &Response, ) -> io::Result<()> { @@ -156,7 +156,7 @@ mod blocking_io { ) -> anyhow::Result<()> where W: std::io::Write, - P: NestedProgress, + P: NestedProgress + 'static, P::SubProgress: 'static, { let transport = net::connect( @@ -212,7 +212,7 @@ mod async_io { async fn receive_pack( &mut self, input: impl AsyncBufRead + Unpin + 'async_trait, - progress: impl gix::NestedProgress, + progress: impl gix::NestedProgress + 'static, refs: &[Ref], _previous_response: &Response, ) -> io::Result<()> { @@ -367,8 +367,8 @@ fn receive_pack_blocking( mut directory: Option, mut refs_directory: Option, ctx: &mut Context, - input: impl io::BufRead, - progress: impl NestedProgress, + mut input: impl io::BufRead, + mut progress: impl NestedProgress + 'static, refs: &[Ref], ) -> io::Result<()> { let options = pack::bundle::write::Options { @@ -377,9 +377,15 @@ fn receive_pack_blocking( iteration_mode: pack::data::input::Mode::Verify, object_hash: ctx.object_hash, }; - let outcome = - pack::Bundle::write_to_directory(input, directory.take(), progress, &ctx.should_interrupt, None, options) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; + let outcome = pack::Bundle::write_to_directory( + &mut input, + directory.take().as_deref(), + &mut progress, + &ctx.should_interrupt, + None, + options, + ) + .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; if let Some(directory) = refs_directory.take() { write_raw_refs(refs, directory)?; diff --git a/gitoxide-core/src/pack/verify.rs b/gitoxide-core/src/pack/verify.rs index 3b40a13858a..6c9eed25328 100644 --- a/gitoxide-core/src/pack/verify.rs +++ b/gitoxide-core/src/pack/verify.rs @@ -87,7 +87,7 @@ impl pack::cache::DecodeEntry for EitherCache { pub fn pack_or_pack_index( path: impl AsRef, - mut progress: impl NestedProgress, + mut progress: impl NestedProgress + 'static, Context { mut out, mut err, @@ -121,7 +121,7 @@ where let res = match ext { "pack" => { let pack = odb::pack::data::File::at(path, object_hash).with_context(|| "Could not open pack file")?; - pack.verify_checksum(progress.add_child("Sha1 of pack"), should_interrupt) + pack.verify_checksum(&mut progress.add_child("Sha1 of pack"), should_interrupt) .map(|id| (id, None))? } "idx" => { @@ -151,7 +151,7 @@ where thread_limit } }), - progress, + &mut progress, should_interrupt, ) .map(|o| (o.actual_index_checksum, o.pack_traverse_statistics)) @@ -161,7 +161,7 @@ where match path.file_name() { Some(file_name) if file_name == "multi-pack-index" => { let multi_index = gix::odb::pack::multi_index::File::at(path)?; - let res = multi_index.verify_integrity(progress, should_interrupt, gix::odb::pack::index::verify::integrity::Options{ + let res = multi_index.verify_integrity(&mut progress, should_interrupt, gix::odb::pack::index::verify::integrity::Options{ verify_mode: mode, traversal: algorithm.into(), thread_limit, diff --git a/gitoxide-core/src/repository/archive.rs b/gitoxide-core/src/repository/archive.rs index 7ef715638fa..9fdf6fbeace 100644 --- a/gitoxide-core/src/repository/archive.rs +++ b/gitoxide-core/src/repository/archive.rs @@ -34,7 +34,7 @@ pub fn stream( .ok_or_else(|| anyhow!("Adding files requires a worktree directory that contains them"))?, )?; for path in add_paths { - stream.add_entry_from_path(&root, &gix::path::realpath(path)?)?; + stream.add_entry_from_path(&root, &gix::path::realpath(&path)?)?; } } for (path, content) in files { diff --git a/gitoxide-core/src/repository/attributes/query.rs b/gitoxide-core/src/repository/attributes/query.rs index 223edb64462..b2d57563f5f 100644 --- a/gitoxide-core/src/repository/attributes/query.rs +++ b/gitoxide-core/src/repository/attributes/query.rs @@ -8,6 +8,7 @@ pub struct Options { } pub(crate) mod function { + use std::borrow::Cow; use std::{io, path::Path}; use anyhow::{anyhow, bail}; @@ -38,7 +39,10 @@ pub(crate) mod function { match input { PathsOrPatterns::Paths(paths) => { for path in paths { - let is_dir = gix::path::from_bstr(path.as_ref()).metadata().ok().map(|m| m.is_dir()); + let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref())) + .metadata() + .ok() + .map(|m| m.is_dir()); let entry = cache.at_entry(path.as_slice(), is_dir)?; if !entry.matching_attributes(&mut matches) { diff --git a/gitoxide-core/src/repository/clone.rs b/gitoxide-core/src/repository/clone.rs index 96640c69537..fdb2878776b 100644 --- a/gitoxide-core/src/repository/clone.rs +++ b/gitoxide-core/src/repository/clone.rs @@ -11,6 +11,7 @@ pub struct Options { pub const PROGRESS_RANGE: std::ops::RangeInclusive = 1..=3; pub(crate) mod function { + use std::borrow::Cow; use std::ffi::OsStr; use anyhow::{bail, Context}; @@ -45,7 +46,7 @@ pub(crate) mod function { let url: gix::Url = url.as_ref().try_into()?; let directory = directory.map_or_else( || { - gix::path::from_bstr(url.path.as_ref()) + gix::path::from_bstr(Cow::Borrowed(url.path.as_ref())) .as_ref() .file_stem() .map(Into::into) diff --git a/gitoxide-core/src/repository/exclude.rs b/gitoxide-core/src/repository/exclude.rs index d42e9fcade4..f3ed2e3595a 100644 --- a/gitoxide-core/src/repository/exclude.rs +++ b/gitoxide-core/src/repository/exclude.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::io; use anyhow::{anyhow, bail}; @@ -37,14 +38,17 @@ pub fn query( let index = repo.index()?; let mut cache = repo.excludes( &index, - Some(gix::ignore::Search::from_overrides(overrides)), + Some(gix::ignore::Search::from_overrides(&mut overrides.into_iter())), Default::default(), )?; match input { PathsOrPatterns::Paths(paths) => { for path in paths { - let is_dir = gix::path::from_bstr(path.as_ref()).metadata().ok().map(|m| m.is_dir()); + let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref())) + .metadata() + .ok() + .map(|m| m.is_dir()); let entry = cache.at_entry(path.as_slice(), is_dir, |oid, buf| repo.objects.find_blob(oid, buf))?; let match_ = entry .matching_exclude_pattern() diff --git a/gitoxide-core/src/repository/index/entries.rs b/gitoxide-core/src/repository/index/entries.rs index f5f988660f1..893f89dda3c 100644 --- a/gitoxide-core/src/repository/index/entries.rs +++ b/gitoxide-core/src/repository/index/entries.rs @@ -158,26 +158,30 @@ pub(crate) mod function { // Note that we intentionally ignore `_case` so that we act like git does, attribute matching case is determined // by the repository, not the pathspec. let entry_is_excluded = pathspec - .pattern_matching_relative_path(entry.path(&index), Some(false), |rela_path, _case, is_dir, out| { - cache - .as_mut() - .map(|(attrs, cache)| { - match last_match { - // The user wants the attributes for display, so the match happened already. - Some(matched) => { - attrs.copy_into(cache.attributes_collection(), out); - matched + .pattern_matching_relative_path( + entry.path(&index), + Some(false), + &mut |rela_path, _case, is_dir, out| { + cache + .as_mut() + .map(|(attrs, cache)| { + match last_match { + // The user wants the attributes for display, so the match happened already. + Some(matched) => { + attrs.copy_into(cache.attributes_collection(), out); + matched + } + // The user doesn't want attributes, so we set the cache position on demand only + None => cache + .at_entry(rela_path, Some(is_dir)) + .ok() + .map(|platform| platform.matching_attributes(out)) + .unwrap_or_default(), } - // The user doesn't want attributes, so we set the cache position on demand only - None => cache - .at_entry(rela_path, Some(is_dir)) - .ok() - .map(|platform| platform.matching_attributes(out)) - .unwrap_or_default(), - } - }) - .unwrap_or_default() - }) + }) + .unwrap_or_default() + }, + ) .map_or(true, |m| m.is_excluded()); let entry_is_submodule = entry.mode.is_submodule(); diff --git a/gitoxide-core/src/repository/verify.rs b/gitoxide-core/src/repository/verify.rs index df5a74c5192..3f033fae5e4 100644 --- a/gitoxide-core/src/repository/verify.rs +++ b/gitoxide-core/src/repository/verify.rs @@ -19,7 +19,7 @@ pub const PROGRESS_RANGE: std::ops::RangeInclusive = 1..=3; pub fn integrity( repo: gix::Repository, mut out: impl std::io::Write, - progress: impl gix::NestedProgress, + mut progress: impl gix::NestedProgress + 'static, should_interrupt: &AtomicBool, Context { output_statistics, @@ -30,7 +30,7 @@ pub fn integrity( ) -> anyhow::Result<()> { #[cfg_attr(not(feature = "serde"), allow(unused))] let outcome = repo.objects.store_ref().verify_integrity( - progress, + &mut progress, should_interrupt, gix::odb::pack::index::verify::integrity::Options { verify_mode, @@ -48,9 +48,7 @@ pub fn integrity( let objects = repo.objects; move |oid, buf: &mut Vec| objects.find_tree_iter(oid, buf).ok() })?; - outcome - .progress - .info(format!("Index at '{}' OK", index.path().display())); + progress.info(format!("Index at '{}' OK", index.path().display())); } match output_statistics { Some(OutputFormat::Human) => writeln!(out, "Human output is currently unsupported, use JSON instead")?, diff --git a/gix-actor/src/identity.rs b/gix-actor/src/identity.rs index 9507afdc297..e6d8fcb520f 100644 --- a/gix-actor/src/identity.rs +++ b/gix-actor/src/identity.rs @@ -35,14 +35,14 @@ mod write { /// Output impl Identity { /// Serialize this instance to `out` in the git serialization format for signatures (but without timestamp). - pub fn write_to(&self, out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { self.to_ref().write_to(out) } } impl<'a> IdentityRef<'a> { /// Serialize this instance to `out` in the git serialization format for signatures (but without timestamp). - pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { out.write_all(validated_token(self.name)?)?; out.write_all(b" ")?; out.write_all(b"<")?; diff --git a/gix-actor/src/signature/mod.rs b/gix-actor/src/signature/mod.rs index cb91bd8eb9f..057d4293e7d 100644 --- a/gix-actor/src/signature/mod.rs +++ b/gix-actor/src/signature/mod.rs @@ -95,7 +95,7 @@ pub(crate) mod write { /// Output impl Signature { /// Serialize this instance to `out` in the git serialization format for actors. - pub fn write_to(&self, out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { self.to_ref().write_to(out) } /// Computes the number of bytes necessary to serialize this signature @@ -106,7 +106,7 @@ pub(crate) mod write { impl<'a> SignatureRef<'a> { /// Serialize this instance to `out` in the git serialization format for actors. - pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { out.write_all(validated_token(self.name)?)?; out.write_all(b" ")?; out.write_all(b"<")?; diff --git a/gix-actor/tests/signature/mod.rs b/gix-actor/tests/signature/mod.rs index e0c7e663d2e..496fb54ae54 100644 --- a/gix-actor/tests/signature/mod.rs +++ b/gix-actor/tests/signature/mod.rs @@ -11,7 +11,7 @@ mod write_to { time: default_time(), }; assert_eq!( - format!("{:?}", signature.write_to(Vec::new())), + format!("{:?}", signature.write_to(&mut Vec::new())), "Err(Custom { kind: Other, error: IllegalCharacter })" ); } @@ -24,7 +24,7 @@ mod write_to { time: default_time(), }; assert_eq!( - format!("{:?}", signature.write_to(Vec::new())), + format!("{:?}", signature.write_to(&mut Vec::new())), "Err(Custom { kind: Other, error: IllegalCharacter })" ); } @@ -37,7 +37,7 @@ mod write_to { time: default_time(), }; assert_eq!( - format!("{:?}", signature.write_to(Vec::new())), + format!("{:?}", signature.write_to(&mut Vec::new())), "Err(Custom { kind: Other, error: IllegalCharacter })" ); } diff --git a/gix-attributes/src/search/attributes.rs b/gix-attributes/src/search/attributes.rs index 8eb66621366..2b48d1ed3be 100644 --- a/gix-attributes/src/search/attributes.rs +++ b/gix-attributes/src/search/attributes.rs @@ -27,14 +27,14 @@ impl Search { let mut group = Self::default(); group.add_patterns_buffer( b"[attr]binary -diff -merge -text", - "[builtin]", + "[builtin]".into(), None, collection, true, /* allow macros */ ); for path in files.into_iter() { - group.add_patterns_file(path, true, None, buf, collection, true /* allow macros */)?; + group.add_patterns_file(path.into(), true, None, buf, collection, true /* allow macros */)?; } Ok(group) } @@ -49,7 +49,7 @@ impl Search { /// Returns `true` if the file was added, or `false` if it didn't exist. pub fn add_patterns_file( &mut self, - source: impl Into, + source: PathBuf, follow_symlinks: bool, root: Option<&Path>, buf: &mut Vec, @@ -75,7 +75,7 @@ impl Search { pub fn add_patterns_buffer( &mut self, bytes: &[u8], - source: impl Into, + source: PathBuf, root: Option<&Path>, collection: &mut MetadataCollection, allow_macros: bool, @@ -99,14 +99,13 @@ impl Search { impl Search { /// Match `relative_path`, a path relative to the repository, while respective `case`-sensitivity and write them to `out` /// Return `true` if at least one pattern matched. - pub fn pattern_matching_relative_path<'a, 'b>( - &'a self, - relative_path: impl Into<&'b BStr>, + pub fn pattern_matching_relative_path( + &self, + relative_path: &BStr, case: gix_glob::pattern::Case, is_dir: Option, out: &mut Outcome, ) -> bool { - let relative_path = relative_path.into(); let basename_pos = relative_path.rfind(b"/").map(|p| p + 1); let mut has_match = false; self.patterns.iter().rev().any(|pl| { diff --git a/gix-attributes/src/search/outcome.rs b/gix-attributes/src/search/outcome.rs index 409be393833..6f724a407ff 100644 --- a/gix-attributes/src/search/outcome.rs +++ b/gix-attributes/src/search/outcome.rs @@ -45,12 +45,19 @@ impl Outcome { &mut self, collection: &MetadataCollection, attribute_names: impl IntoIterator>>, + ) { + self.initialize_with_selection_inner(collection, &mut attribute_names.into_iter().map(Into::into)) + } + + fn initialize_with_selection_inner( + &mut self, + collection: &MetadataCollection, + attribute_names: &mut dyn Iterator>, ) { self.initialize(collection); self.selected.clear(); - self.selected.extend(attribute_names.into_iter().map(|name| { - let name = name.into(); + self.selected.extend(attribute_names.map(|name| { ( name.to_owned(), collection.name_to_meta.get(name.as_str()).map(|meta| meta.id), diff --git a/gix-attributes/tests/search/mod.rs b/gix-attributes/tests/search/mod.rs index b8fbaf83072..36e6286c8ed 100644 --- a/gix-attributes/tests/search/mod.rs +++ b/gix-attributes/tests/search/mod.rs @@ -50,7 +50,7 @@ mod specials { ); let mut out = Outcome::default(); out.initialize(&collection); - search.pattern_matching_relative_path(path, case, None, &mut out) + search.pattern_matching_relative_path(path.into(), case, None, &mut out) } fn searchi(pattern: &str, path: &str, rela_containing_dir: Option<&str>) -> bool { @@ -66,7 +66,7 @@ fn baseline() -> crate::Result { let mut buf = Vec::new(); // Due to the way our setup differs from gits dynamic stack (which involves trying to read files from disk // by path) we can only test one case baseline, so we require multiple platforms (or filesystems) to run this. - let case = if gix_fs::Capabilities::probe("../.git").ignore_case { + let case = if gix_fs::Capabilities::probe("../.git".as_ref()).ignore_case { Case::Fold } else { Case::Sensitive @@ -307,7 +307,11 @@ mod baseline { let mut buf = Vec::new(); let mut collection = MetadataCollection::default(); - let group = gix_attributes::Search::new_globals([base.join("user.attributes")], &mut buf, &mut collection)?; + let group = gix_attributes::Search::new_globals( + &mut [base.join("user.attributes")].into_iter(), + &mut buf, + &mut collection, + )?; Ok((group, collection, base, input)) } diff --git a/gix-commitgraph/src/file/access.rs b/gix-commitgraph/src/file/access.rs index d3c32d8bb0e..79a40d75dbf 100644 --- a/gix-commitgraph/src/file/access.rs +++ b/gix-commitgraph/src/file/access.rs @@ -74,7 +74,10 @@ impl File { /// Translate the given object hash to its position within this file, if present. // copied from gix-odb/src/pack/index/ext pub fn lookup(&self, id: impl AsRef) -> Option { - let id = id.as_ref(); + self.lookup_inner(id.as_ref()) + } + + fn lookup_inner(&self, id: &gix_hash::oid) -> Option { let first_byte = usize::from(id.first_byte()); let mut upper_bound = self.fan[first_byte]; let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 }; diff --git a/gix-commitgraph/src/file/verify.rs b/gix-commitgraph/src/file/verify.rs index 91da92c635e..c91f6b4d281 100644 --- a/gix-commitgraph/src/file/verify.rs +++ b/gix-commitgraph/src/file/verify.rs @@ -160,8 +160,7 @@ impl File { /// If the given path's filename matches "graph-{hash}.graph", check that `hash` matches the /// expected hash. -fn verify_split_chain_filename_hash(path: impl AsRef, expected: &gix_hash::oid) -> Result<(), String> { - let path = path.as_ref(); +fn verify_split_chain_filename_hash(path: &Path, expected: &gix_hash::oid) -> Result<(), String> { path.file_name() .and_then(std::ffi::OsStr::to_str) .and_then(|filename| filename.strip_suffix(".graph")) diff --git a/gix-commitgraph/src/init.rs b/gix-commitgraph/src/init.rs index f964aade029..0b03ba9462d 100644 --- a/gix-commitgraph/src/init.rs +++ b/gix-commitgraph/src/init.rs @@ -41,13 +41,13 @@ pub enum Error { /// Instantiate a `Graph` from various sources. impl Graph { /// Instantiate a commit graph from `path` which may be a directory containing graph files or the graph file itself. - pub fn at(path: impl AsRef) -> Result { - Self::try_from(path.as_ref()) + pub fn at(path: &Path) -> Result { + Self::try_from(path) } /// Instantiate a commit graph from the directory containing all of its files. - pub fn from_commit_graphs_dir(path: impl AsRef) -> Result { - let commit_graphs_dir = path.as_ref(); + pub fn from_commit_graphs_dir(path: &Path) -> Result { + let commit_graphs_dir = path; let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io { err: e, @@ -70,8 +70,7 @@ impl Graph { /// Instantiate a commit graph from a `.git/objects/info/commit-graph` or /// `.git/objects/info/commit-graphs/graph-*.graph` file. - pub fn from_file(path: impl AsRef) -> Result { - let path = path.as_ref(); + pub fn from_file(path: &Path) -> Result { let file = File::at(path).map_err(|e| Error::File { err: e, path: path.to_owned(), @@ -80,9 +79,9 @@ impl Graph { } /// Instantiate a commit graph from an `.git/objects/info` directory. - pub fn from_info_dir(info_dir: impl AsRef) -> Result { - Self::from_file(info_dir.as_ref().join("commit-graph")) - .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs"))) + pub fn from_info_dir(info_dir: &Path) -> Result { + Self::from_file(&info_dir.join("commit-graph")) + .or_else(|_| Self::from_commit_graphs_dir(&info_dir.join("commit-graphs"))) } /// Create a new commit graph from a list of `files`. diff --git a/gix-commitgraph/src/lib.rs b/gix-commitgraph/src/lib.rs index 231c11c6fb0..a247ccd87de 100644 --- a/gix-commitgraph/src/lib.rs +++ b/gix-commitgraph/src/lib.rs @@ -45,7 +45,7 @@ pub struct Graph { /// Instantiate a commit graph from an `.git/objects/info` directory, or one of the various commit-graph files. pub fn at(path: impl AsRef) -> Result { - Graph::at(path) + Graph::at(path.as_ref()) } mod access; diff --git a/gix-commitgraph/tests/commitgraph.rs b/gix-commitgraph/tests/commitgraph.rs index 20d20dee1ee..94568fe5cfa 100644 --- a/gix-commitgraph/tests/commitgraph.rs +++ b/gix-commitgraph/tests/commitgraph.rs @@ -80,7 +80,8 @@ pub fn graph_and_expected_named( .expect("script succeeds all the time") .join(name); let expected = inspect_refs(&repo_dir, refs); - let cg = Graph::from_info_dir(repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid"); + let cg = + Graph::from_info_dir(&repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid"); (cg, expected) } diff --git a/gix-config/fuzz/fuzz_targets/parse.rs b/gix-config/fuzz/fuzz_targets/parse.rs index a065ad75950..34a12ceeb02 100644 --- a/gix-config/fuzz/fuzz_targets/parse.rs +++ b/gix-config/fuzz/fuzz_targets/parse.rs @@ -4,5 +4,5 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|data: &[u8]| { // Don't name this _; Rust may optimize it out. - let _a = gix_config::parse::from_bytes(data, |_e| ()); + let _a = gix_config::parse::from_bytes(data, &mut |_e| ()); }); diff --git a/gix-config/src/file/access/comfort.rs b/gix-config/src/file/access/comfort.rs index 5ad0e6186b7..ed62e779269 100644 --- a/gix-config/src/file/access/comfort.rs +++ b/gix-config/src/file/access/comfort.rs @@ -31,7 +31,8 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Option> { - self.raw_value_filter(section_name, subsection_name, key, filter).ok() + self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok() } /// Like [`string_filter()`][File::string_filter()], but suitable for statically known `key`s like `remote.origin.url`. @@ -40,7 +41,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.raw_value_filter(key.section_name, key.subsection_name, key.value_name, filter) .ok() } @@ -78,7 +79,7 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Option> { - self.raw_value_filter(section_name, subsection_name, key, filter) + self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) .ok() .map(crate::Path::from) } @@ -89,7 +90,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.path_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -141,7 +142,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.boolean_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -168,7 +169,9 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Option> { - let int = self.raw_value_filter(section_name, subsection_name, key, filter).ok()?; + let int = self + .raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok()?; Some(crate::Integer::try_from(int.as_ref()).and_then(|b| { b.to_decimal() .ok_or_else(|| value::Error::new("Integer overflow", int.into_owned())) @@ -181,7 +184,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.integer_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -192,12 +195,13 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, key: impl AsRef, ) -> Option>> { - self.raw_values(section_name, subsection_name, key).ok() + self.raw_values(section_name.as_ref(), subsection_name, key.as_ref()) + .ok() } /// Like [`strings()`][File::strings()], but suitable for statically known `key`s like `remote.origin.url`. pub fn strings_by_key<'a>(&self, key: impl Into<&'a BStr>) -> Option>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.strings(key.section_name, key.subsection_name, key.value_name) } @@ -209,7 +213,8 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Option>> { - self.raw_values_filter(section_name, subsection_name, key, filter).ok() + self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok() } /// Like [`strings_filter()`][File::strings_filter()], but suitable for statically known `key`s like `remote.origin.url`. @@ -218,7 +223,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.strings_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -247,7 +252,7 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Option, value::Error>> { - self.raw_values_filter(section_name, subsection_name, key, filter) + self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) .ok() .map(|values| { values @@ -268,7 +273,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option, value::Error>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.integers_filter(key.section_name, key.subsection_name, key.value_name, filter) } } diff --git a/gix-config/src/file/access/mutate.rs b/gix-config/src/file/access/mutate.rs index 5237b3794bb..4844a34f4d1 100644 --- a/gix-config/src/file/access/mutate.rs +++ b/gix-config/src/file/access/mutate.rs @@ -17,9 +17,17 @@ impl<'event> File<'event> { &'a mut self, name: impl AsRef, subsection_name: Option<&BStr>, + ) -> Result, lookup::existing::Error> { + self.section_mut_inner(name.as_ref(), subsection_name) + } + + fn section_mut_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, ) -> Result, lookup::existing::Error> { let id = self - .section_ids_by_name_and_subname(name.as_ref(), subsection_name)? + .section_ids_by_name_and_subname(name, subsection_name)? .next_back() .expect("BUG: Section lookup vec was empty"); let nl = self.detect_newline_style_smallvec(); @@ -64,7 +72,15 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, filter: &mut MetadataFilter, ) -> Result, section::header::Error> { - let name = name.as_ref(); + self.section_mut_or_create_new_filter_inner(name.as_ref(), subsection_name, filter) + } + + fn section_mut_or_create_new_filter_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, + ) -> Result, section::header::Error> { match self .section_ids_by_name_and_subname(name.as_ref(), subsection_name) .ok() @@ -95,9 +111,18 @@ impl<'event> File<'event> { name: impl AsRef, subsection_name: Option<&BStr>, filter: &mut MetadataFilter, + ) -> Result>, lookup::existing::Error> { + self.section_mut_filter_inner(name.as_ref(), subsection_name, filter) + } + + fn section_mut_filter_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, ) -> Result>, lookup::existing::Error> { let id = self - .section_ids_by_name_and_subname(name.as_ref(), subsection_name)? + .section_ids_by_name_and_subname(name, subsection_name)? .rev() .find(|id| { let s = &self.sections[id]; @@ -158,6 +183,14 @@ impl<'event> File<'event> { &mut self, name: impl Into>, subsection: impl Into>>, + ) -> Result, section::header::Error> { + self.new_section_inner(name.into(), subsection.into()) + } + + fn new_section_inner( + &mut self, + name: Cow<'event, str>, + subsection: Option>, ) -> Result, section::header::Error> { let id = self.push_section_internal(file::Section::new(name, subsection, OwnShared::clone(&self.meta))?); let nl = self.detect_newline_style_smallvec(); @@ -205,11 +238,11 @@ impl<'event> File<'event> { /// ``` pub fn remove_section<'a>( &mut self, - name: &str, + name: impl AsRef, subsection_name: impl Into>, ) -> Option> { let id = self - .section_ids_by_name_and_subname(name, subsection_name.into()) + .section_ids_by_name_and_subname(name.as_ref(), subsection_name.into()) .ok()? .next_back()?; self.remove_section_by_id(id) @@ -254,12 +287,21 @@ impl<'event> File<'event> { /// later sections with the same name have precedent over earlier ones. pub fn remove_section_filter<'a>( &mut self, - name: &str, + name: impl AsRef, subsection_name: impl Into>, filter: &mut MetadataFilter, + ) -> Option> { + self.remove_section_filter_inner(name.as_ref(), subsection_name.into(), filter) + } + + fn remove_section_filter_inner( + &mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, ) -> Option> { let id = self - .section_ids_by_name_and_subname(name, subsection_name.into()) + .section_ids_by_name_and_subname(name, subsection_name) .ok()? .rev() .find(|id| filter(self.sections.get(id).expect("each id has a section").meta()))?; diff --git a/gix-config/src/file/access/raw.rs b/gix-config/src/file/access/raw.rs index 6fef6c9ed40..3736bf3a286 100644 --- a/gix-config/src/file/access/raw.rs +++ b/gix-config/src/file/access/raw.rs @@ -40,8 +40,17 @@ impl<'event> File<'event> { key: impl AsRef, filter: &mut MetadataFilter, ) -> Result, lookup::existing::Error> { - let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?; - let key = key.as_ref(); + self.raw_value_filter_inner(section_name.as_ref(), subsection_name, key.as_ref(), filter) + } + + fn raw_value_filter_inner( + &self, + section_name: &str, + subsection_name: Option<&BStr>, + key: &str, + filter: &mut MetadataFilter, + ) -> Result, lookup::existing::Error> { + let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?; for section_id in section_ids.rev() { let section = self.sections.get(§ion_id).expect("known section id"); if !filter(section.meta()) { @@ -80,9 +89,19 @@ impl<'event> File<'event> { subsection_name: Option<&'lookup BStr>, key: &'lookup str, filter: &mut MetadataFilter, + ) -> Result, lookup::existing::Error> { + self.raw_value_mut_filter_inner(section_name.as_ref(), subsection_name, key, filter) + } + + fn raw_value_mut_filter_inner<'lookup>( + &mut self, + section_name: &str, + subsection_name: Option<&'lookup BStr>, + key: &'lookup str, + filter: &mut MetadataFilter, ) -> Result, lookup::existing::Error> { let mut section_ids = self - .section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)? + .section_ids_by_name_and_subname(section_name, subsection_name)? .rev(); let key = section::Key(Cow::::Borrowed(key.into())); @@ -190,10 +209,19 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, key: impl AsRef, filter: &mut MetadataFilter, + ) -> Result>, lookup::existing::Error> { + self.raw_values_filter_inner(section_name.as_ref(), subsection_name, key.as_ref(), filter) + } + + fn raw_values_filter_inner( + &self, + section_name: &str, + subsection_name: Option<&BStr>, + key: &str, + filter: &mut MetadataFilter, ) -> Result>, lookup::existing::Error> { let mut values = Vec::new(); - let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?; - let key = key.as_ref(); + let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?; for section_id in section_ids { let section = self.sections.get(§ion_id).expect("known section id"); if !filter(section.meta()) { @@ -277,7 +305,17 @@ impl<'event> File<'event> { key: &'lookup str, filter: &mut MetadataFilter, ) -> Result, lookup::existing::Error> { - let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?; + self.raw_values_mut_filter_inner(section_name.as_ref(), subsection_name, key, filter) + } + + fn raw_values_mut_filter_inner<'lookup>( + &mut self, + section_name: &str, + subsection_name: Option<&'lookup BStr>, + key: &'lookup str, + filter: &mut MetadataFilter, + ) -> Result, lookup::existing::Error> { + let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?; let key = section::Key(Cow::::Borrowed(key.into())); let mut offsets = HashMap::new(); @@ -432,7 +470,7 @@ impl<'event> File<'event> { section::key::Error: From, { let mut section = self.section_mut_or_create_new_filter(section_name, subsection_name, filter)?; - Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value)) + Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value.into())) } /// Sets a multivar in a given section, optional subsection, and key value. diff --git a/gix-config/src/file/access/read_only.rs b/gix-config/src/file/access/read_only.rs index d5fd192bb7b..eb1071fe2e1 100644 --- a/gix-config/src/file/access/read_only.rs +++ b/gix-config/src/file/access/read_only.rs @@ -131,7 +131,7 @@ impl<'event> File<'event> { /// Returns the last found immutable section with a given `name` and optional `subsection_name`. pub fn section( &self, - name: impl AsRef, + name: &str, subsection_name: Option<&BStr>, ) -> Result<&file::Section<'event>, lookup::existing::Error> { self.section_filter(name, subsection_name, &mut |_| true)? @@ -140,10 +140,7 @@ impl<'event> File<'event> { /// Returns the last found immutable section with a given `key`, identifying the name and subsection name like `core` /// or `remote.origin`. - pub fn section_by_key<'a>( - &self, - key: impl Into<&'a BStr>, - ) -> Result<&file::Section<'event>, lookup::existing::Error> { + pub fn section_by_key(&self, key: &BStr) -> Result<&file::Section<'event>, lookup::existing::Error> { let key = crate::parse::section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?; self.section(key.section_name, key.subsection_name) } @@ -154,7 +151,7 @@ impl<'event> File<'event> { /// is returned. pub fn section_filter<'a>( &'a self, - name: impl AsRef, + name: &str, subsection_name: Option<&BStr>, filter: &mut MetadataFilter, ) -> Result>, lookup::existing::Error> { @@ -171,9 +168,9 @@ impl<'event> File<'event> { } /// Like [`section_filter()`][File::section_filter()], but identifies the section with `key` like `core` or `remote.origin`. - pub fn section_filter_by_key<'a, 'b>( + pub fn section_filter_by_key<'a>( &'a self, - key: impl Into<&'b BStr>, + key: &BStr, filter: &mut MetadataFilter, ) -> Result>, lookup::existing::Error> { let key = crate::parse::section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?; diff --git a/gix-config/src/file/init/comfort.rs b/gix-config/src/file/init/comfort.rs index f8e624c731b..4a5a1c68b25 100644 --- a/gix-config/src/file/init/comfort.rs +++ b/gix-config/src/file/init/comfort.rs @@ -82,16 +82,16 @@ impl File<'static> { /// /// Includes will be resolved within limits as some information like the git installation directory is missing to interpolate /// paths with as well as git repository information like the branch name. - pub fn from_git_dir(dir: impl Into) -> Result, from_git_dir::Error> { + pub fn from_git_dir(dir: std::path::PathBuf) -> Result, from_git_dir::Error> { let (mut local, git_dir) = { let source = Source::Local; - let mut path = dir.into(); + let mut path = dir; path.push( source .storage_location(&mut gix_path::env::var) .expect("location available for local"), ); - let local = Self::from_path_no_includes(&path, source)?; + let local = Self::from_path_no_includes(path.clone(), source)?; path.pop(); (local, path) }; diff --git a/gix-config/src/file/init/from_paths.rs b/gix-config/src/file/init/from_paths.rs index ea209cefc4c..5d092f88a7c 100644 --- a/gix-config/src/file/init/from_paths.rs +++ b/gix-config/src/file/init/from_paths.rs @@ -23,8 +23,7 @@ impl File<'static> { /// Load the single file at `path` with `source` without following include directives. /// /// Note that the path will be checked for ownership to derive trust. - pub fn from_path_no_includes(path: impl Into, source: crate::Source) -> Result { - let path = path.into(); + pub fn from_path_no_includes(path: std::path::PathBuf, source: crate::Source) -> Result { let trust = match gix_sec::Trust::from_path_ownership(&path) { Ok(t) => t, Err(err) => return Err(Error::Io { source: err, path }), @@ -60,7 +59,12 @@ impl File<'static> { ) -> Result, Error> { let mut buf = Vec::with_capacity(512); let err_on_nonexisting_paths = true; - Self::from_paths_metadata_buf(path_meta, &mut buf, err_on_nonexisting_paths, options) + Self::from_paths_metadata_buf( + &mut path_meta.into_iter().map(Into::into), + &mut buf, + err_on_nonexisting_paths, + options, + ) } /// Like [`from_paths_metadata()`][Self::from_paths_metadata()], but will use `buf` to temporarily store the config file @@ -68,17 +72,14 @@ impl File<'static> { /// /// If `err_on_nonexisting_paths` is false, instead of aborting with error, we will continue to the next path instead. pub fn from_paths_metadata_buf( - path_meta: impl IntoIterator>, + path_meta: &mut dyn Iterator, buf: &mut Vec, err_on_non_existing_paths: bool, options: Options<'_>, ) -> Result, Error> { let mut target = None; let mut seen = BTreeSet::default(); - for (path, mut meta) in path_meta.into_iter().filter_map(|meta| { - let mut meta = meta.into(); - meta.path.take().map(|p| (p, meta)) - }) { + for (path, mut meta) in path_meta.filter_map(|mut meta| meta.path.take().map(|p| (p, meta))) { if !seen.insert(path.clone()) { continue; } diff --git a/gix-config/src/file/mutable/section.rs b/gix-config/src/file/mutable/section.rs index f13b87e483a..336ccad2d7e 100644 --- a/gix-config/src/file/mutable/section.rs +++ b/gix-config/src/file/mutable/section.rs @@ -123,10 +123,10 @@ impl<'a, 'event> SectionMut<'a, 'event> { /// Sets the last key value pair if it exists, or adds the new value. /// Returns the previous value if it replaced a value, or None if it adds /// the value. - pub fn set<'b>(&mut self, key: Key<'event>, value: impl Into<&'b BStr>) -> Option> { + pub fn set(&mut self, key: Key<'event>, value: &BStr) -> Option> { match self.key_and_value_range_by(&key) { None => { - self.push(key, Some(value.into())); + self.push(key, Some(value)); None } Some((key_range, value_range)) => { @@ -136,15 +136,15 @@ impl<'a, 'event> SectionMut<'a, 'event> { self.section .body .0 - .insert(range_start, Event::Value(escape_value(value.into()).into())); + .insert(range_start, Event::Value(escape_value(value).into())); Some(ret) } } } /// Removes the latest value by key and returns it, if it exists. - pub fn remove(&mut self, key: impl AsRef) -> Option> { - let key = Key::from_str_unchecked(key.as_ref()); + pub fn remove(&mut self, key: &str) -> Option> { + let key = Key::from_str_unchecked(key); let (key_range, _value_range) = self.key_and_value_range_by(&key)?; Some(self.remove_internal(key_range, true)) } diff --git a/gix-config/src/file/section/body.rs b/gix-config/src/file/section/body.rs index 694de18bd91..1bc12725c6b 100644 --- a/gix-config/src/file/section/body.rs +++ b/gix-config/src/file/section/body.rs @@ -18,14 +18,14 @@ impl<'event> Body<'event> { /// Note that we consider values without key separator `=` non-existing. #[must_use] pub fn value(&self, key: impl AsRef) -> Option> { - self.value_implicit(key).flatten() + self.value_implicit(key.as_ref()).flatten() } /// Retrieves the last matching value in a section with the given key, if present, and indicates an implicit value with `Some(None)`, /// and a non-existing one as `None` #[must_use] - pub fn value_implicit(&self, key: impl AsRef) -> Option>> { - let key = Key::from_str_unchecked(key.as_ref()); + pub fn value_implicit(&self, key: &str) -> Option>> { + let key = Key::from_str_unchecked(key); let (_key_range, range) = self.key_and_value_range_by(&key)?; let range = match range { None => return Some(None), @@ -54,8 +54,8 @@ impl<'event> Body<'event> { /// Retrieves all values that have the provided key name. This may return /// an empty vec, which implies there were no values with the provided key. #[must_use] - pub fn values(&self, key: impl AsRef) -> Vec> { - let key = &Key::from_str_unchecked(key.as_ref()); + pub fn values(&self, key: &str) -> Vec> { + let key = &Key::from_str_unchecked(key); let mut values = Vec::new(); let mut expect_value = false; let mut concatenated_value = BString::default(); @@ -92,8 +92,8 @@ impl<'event> Body<'event> { /// Returns true if the section contains the provided key. #[must_use] - pub fn contains_key(&self, key: impl AsRef) -> bool { - let key = &Key::from_str_unchecked(key.as_ref()); + pub fn contains_key(&self, key: &str) -> bool { + let key = &Key::from_str_unchecked(key); self.0.iter().any(|e| { matches!(e, Event::SectionKey(k) if k == key diff --git a/gix-config/src/file/section/mod.rs b/gix-config/src/file/section/mod.rs index f73405960d0..f07a145e3d4 100644 --- a/gix-config/src/file/section/mod.rs +++ b/gix-config/src/file/section/mod.rs @@ -74,7 +74,7 @@ impl<'a> Section<'a> { /// Stream ourselves to the given `out`, in order to reproduce this section mostly losslessly /// as it was parsed. - pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, mut out: &mut dyn std::io::Write) -> std::io::Result<()> { self.header.write_to(&mut out)?; if self.body.0.is_empty() { diff --git a/gix-config/src/file/write.rs b/gix-config/src/file/write.rs index b4cd9c48fc6..772054f9529 100644 --- a/gix-config/src/file/write.rs +++ b/gix-config/src/file/write.rs @@ -17,8 +17,8 @@ impl File<'_> { /// as it was parsed, while writing only sections for which `filter` returns true. pub fn write_to_filter( &self, - mut out: impl std::io::Write, - mut filter: impl FnMut(&Section<'_>) -> bool, + mut out: &mut dyn std::io::Write, + mut filter: &mut dyn FnMut(&Section<'_>) -> bool, ) -> std::io::Result<()> { let nl = self.detect_newline_style(); @@ -65,8 +65,8 @@ impl File<'_> { /// Stream ourselves to the given `out`, in order to reproduce this file mostly losslessly /// as it was parsed. - pub fn write_to(&self, out: impl std::io::Write) -> std::io::Result<()> { - self.write_to_filter(out, |_| true) + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { + self.write_to_filter(out, &mut |_| true) } } diff --git a/gix-config/src/parse/event.rs b/gix-config/src/parse/event.rs index b7b96934d04..f528e2077d6 100644 --- a/gix-config/src/parse/event.rs +++ b/gix-config/src/parse/event.rs @@ -33,7 +33,7 @@ impl Event<'_> { /// Stream ourselves to the given `out`, in order to reproduce this event mostly losslessly /// as it was parsed. - pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, mut out: &mut dyn std::io::Write) -> std::io::Result<()> { match self { Self::ValueNotDone(e) => { out.write_all(e.as_ref())?; diff --git a/gix-config/src/parse/events.rs b/gix-config/src/parse/events.rs index 1a1287d642b..f3f5275005a 100644 --- a/gix-config/src/parse/events.rs +++ b/gix-config/src/parse/events.rs @@ -229,7 +229,7 @@ impl Events<'static> { input: &'a [u8], filter: Option) -> bool>, ) -> Result, parse::Error> { - from_bytes(input, |e| e.to_owned(), filter) + from_bytes(input, &|e| e.to_owned(), filter) } } @@ -241,7 +241,7 @@ impl<'a> Events<'a> { /// /// Use `filter` to only include those events for which it returns true. pub fn from_bytes(input: &'a [u8], filter: Option) -> bool>) -> Result, parse::Error> { - from_bytes(input, std::convert::identity, filter) + from_bytes(input, &std::convert::identity, filter) } /// Attempt to zero-copy parse the provided `input` string. @@ -288,14 +288,14 @@ impl<'a> TryFrom<&'a [u8]> for Events<'a> { fn from_bytes<'a, 'b>( input: &'a [u8], - convert: impl Fn(Event<'a>) -> Event<'b>, + convert: &dyn Fn(Event<'a>) -> Event<'b>, filter: Option) -> bool>, ) -> Result, parse::Error> { let mut header = None; let mut events = section::Events::default(); let mut frontmatter = FrontMatterEvents::default(); let mut sections = Vec::new(); - parse::from_bytes(input, |e: Event<'_>| match e { + parse::from_bytes(input, &mut |e: Event<'_>| match e { Event::SectionHeader(next_header) => { match header.take() { None => { diff --git a/gix-config/src/parse/key.rs b/gix-config/src/parse/key.rs index b0e0376be2a..0ebb09e5f51 100644 --- a/gix-config/src/parse/key.rs +++ b/gix-config/src/parse/key.rs @@ -14,8 +14,7 @@ pub struct Key<'a> { /// Parse `input` like `core.bare` or `remote.origin.url` as a `Key` to make its fields available, /// or `None` if there were not at least 2 tokens separated by `.`. /// Note that `input` isn't validated, and is `str` as ascii is a subset of UTF-8 which is required for any valid keys. -pub fn parse_unvalidated<'a>(input: impl Into<&'a BStr>) -> Option> { - let input = input.into(); +pub fn parse_unvalidated(input: &BStr) -> Option> { let mut tokens = input.splitn(2, |b| *b == b'.'); let section_name = tokens.next()?; let subsection_or_key = tokens.next()?; diff --git a/gix-config/src/parse/nom/mod.rs b/gix-config/src/parse/nom/mod.rs index 1ae2f8593d1..3ae45618dc2 100644 --- a/gix-config/src/parse/nom/mod.rs +++ b/gix-config/src/parse/nom/mod.rs @@ -12,7 +12,7 @@ use winnow::{ use crate::parse::{error::ParseNode, section, Comment, Error, Event}; /// Attempt to zero-copy parse the provided bytes, passing results to `dispatch`. -pub fn from_bytes<'i>(mut input: &'i [u8], mut dispatch: impl FnMut(Event<'i>)) -> Result<(), Error> { +pub fn from_bytes<'i>(mut input: &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> Result<(), Error> { let start = input.checkpoint(); let bom = unicode_bom::Bom::from(input); @@ -46,7 +46,7 @@ pub fn from_bytes<'i>(mut input: &'i [u8], mut dispatch: impl FnMut(Event<'i>)) let mut node = ParseNode::SectionHeader; - let res = repeat(1.., |i: &mut &'i [u8]| section(i, &mut node, &mut dispatch)) + let res = repeat(1.., |i: &mut &'i [u8]| section(i, &mut node, dispatch)) .map(|()| ()) .parse_next(&mut input); res.map_err(|_| { @@ -94,7 +94,7 @@ mod tests; fn section<'i>( i: &mut &'i [u8], node: &mut ParseNode, - dispatch: &mut impl FnMut(Event<'i>), + dispatch: &mut dyn FnMut(Event<'i>), ) -> PResult<(), NomError<&'i [u8]>> { let start = i.checkpoint(); let header = section_header(i).map_err(|e| { @@ -205,7 +205,7 @@ fn is_subsection_unescaped_char(c: u8) -> bool { fn key_value_pair<'i>( i: &mut &'i [u8], node: &mut ParseNode, - dispatch: &mut impl FnMut(Event<'i>), + dispatch: &mut dyn FnMut(Event<'i>), ) -> PResult<(), NomError<&'i [u8]>> { *node = ParseNode::Name; if let Some(name) = opt(config_name).parse_next(i)? { @@ -234,7 +234,7 @@ fn config_name<'i>(i: &mut &'i [u8]) -> PResult<&'i BStr, NomError<&'i [u8]>> { .parse_next(i) } -fn config_value<'i>(i: &mut &'i [u8], dispatch: &mut impl FnMut(Event<'i>)) -> PResult<(), NomError<&'i [u8]>> { +fn config_value<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PResult<(), NomError<&'i [u8]>> { if opt('=').parse_next(i)?.is_some() { dispatch(Event::KeyValueSeparator); if let Some(whitespace) = opt(take_spaces1).parse_next(i)? { @@ -252,7 +252,7 @@ fn config_value<'i>(i: &mut &'i [u8], dispatch: &mut impl FnMut(Event<'i>)) -> P /// Handles parsing of known-to-be values. This function handles both single /// line values as well as values that are continuations. -fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut impl FnMut(Event<'i>)) -> PResult<(), NomError<&'i [u8]>> { +fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PResult<(), NomError<&'i [u8]>> { let start_checkpoint = i.checkpoint(); let mut value_start_checkpoint = i.checkpoint(); let mut value_end = None; diff --git a/gix-config/tests/config.rs b/gix-config/tests/config.rs index 874365a2d06..7107bca8bad 100644 --- a/gix-config/tests/config.rs +++ b/gix-config/tests/config.rs @@ -1,4 +1,4 @@ -type Result = std::result::Result>; +pub use gix_testtools::Result; mod file; mod parse; diff --git a/gix-config/tests/file/init/from_env.rs b/gix-config/tests/file/init/from_env.rs index 4987c60603d..198a25575c9 100644 --- a/gix-config/tests/file/init/from_env.rs +++ b/gix-config/tests/file/init/from_env.rs @@ -44,7 +44,7 @@ fn single_key_value_pair() -> crate::Result { let config = File::from_env(Default::default())?.unwrap(); assert_eq!(config.raw_value("core", None, "key")?, Cow::<[u8]>::Borrowed(b"value")); assert_eq!( - config.section_by_key("core")?.meta(), + config.section_by_key("core".into())?.meta(), &gix_config::file::Metadata::from(gix_config::Source::Env), "source if configured correctly" ); diff --git a/gix-config/tests/file/mod.rs b/gix-config/tests/file/mod.rs index 3a2bc92ab03..2cf50210db7 100644 --- a/gix-config/tests/file/mod.rs +++ b/gix-config/tests/file/mod.rs @@ -21,7 +21,7 @@ mod open { #[test] fn parse_config_with_windows_line_endings_successfully() { - File::from_path_no_includes(&fixture_path_standalone("repo-config.crlf"), gix_config::Source::Local).unwrap(); + File::from_path_no_includes(fixture_path_standalone("repo-config.crlf"), gix_config::Source::Local).unwrap(); } } diff --git a/gix-config/tests/file/mutable/section.rs b/gix-config/tests/file/mutable/section.rs index ea17ce7a401..17ef1df586b 100644 --- a/gix-config/tests/file/mutable/section.rs +++ b/gix-config/tests/file/mutable/section.rs @@ -51,7 +51,7 @@ mod remove { let prev_values = vec!["v", "", "", "", "a b c"]; let mut num_values = section.num_values(); for (key, expected_prev_value) in ('a'..='e').zip(prev_values) { - let prev_value = section.remove(key.to_string()); + let prev_value = section.remove(&key.to_string()); num_values -= 1; assert_eq!(prev_value.expect("present").as_ref(), expected_prev_value); assert_eq!(section.num_values(), num_values); @@ -104,7 +104,7 @@ mod set { for (key, (new_value, expected_prev_value)) in (b'a'..=b'e').zip(values.into_iter().zip(prev_values)) { let key = std::str::from_utf8(std::slice::from_ref(&key))?.to_owned(); - let prev_value = section.set(key.try_into()?, new_value); + let prev_value = section.set(key.try_into()?, new_value.as_ref()); assert_eq!(prev_value.as_deref().expect("prev value set"), expected_prev_value); } @@ -112,7 +112,7 @@ mod set { assert_eq!( config .section_mut("a", None)? - .set("new-one".to_owned().try_into()?, "value"), + .set("new-one".to_owned().try_into()?, "value".into()), None, "new values don't replace an existing one" ); diff --git a/gix-config/tests/file/write.rs b/gix-config/tests/file/write.rs index 3ae71d313ff..26c72c7f72b 100644 --- a/gix-config/tests/file/write.rs +++ b/gix-config/tests/file/write.rs @@ -137,7 +137,7 @@ mod to_filter { .push("c".try_into()?, Some("d".into())); let mut buf = Vec::::new(); - config.write_to_filter(&mut buf, |s| s.meta().source == gix_config::Source::Local)?; + config.write_to_filter(&mut buf, &mut |s| s.meta().source == gix_config::Source::Local)?; let nl = config.detect_newline_style(); assert_eq!(buf.to_str_lossy(), format!("[a \"local\"]{nl}\tb = c{nl}\tc = d{nl}")); diff --git a/gix-config/tests/parse/key.rs b/gix-config/tests/parse/key.rs index 6342429f6e4..40de5ae4269 100644 --- a/gix-config/tests/parse/key.rs +++ b/gix-config/tests/parse/key.rs @@ -2,13 +2,13 @@ use gix_config::parse; #[test] fn missing_dot_is_invalid() { - assert_eq!(parse::key("hello"), None); + assert_eq!(parse::key("hello".into()), None); } #[test] fn section_name_and_key() { assert_eq!( - parse::key("core.bare"), + parse::key("core.bare".into()), Some(parse::Key { section_name: "core", subsection_name: None, @@ -20,7 +20,7 @@ fn section_name_and_key() { #[test] fn section_name_subsection_and_key() { assert_eq!( - parse::key("remote.origin.url"), + parse::key("remote.origin.url".into()), Some(parse::Key { section_name: "remote", subsection_name: Some("origin".into()), @@ -29,7 +29,7 @@ fn section_name_subsection_and_key() { ); assert_eq!( - parse::key("includeIf.gitdir/i:C:\\bare.git.path"), + parse::key("includeIf.gitdir/i:C:\\bare.git.path".into()), Some(parse::Key { section_name: "includeIf", subsection_name: Some("gitdir/i:C:\\bare.git".into()), diff --git a/gix-credentials/src/helper/invoke.rs b/gix-credentials/src/helper/invoke.rs index 563f3b2ffc8..e5662f4ca4e 100644 --- a/gix-credentials/src/helper/invoke.rs +++ b/gix-credentials/src/helper/invoke.rs @@ -4,7 +4,7 @@ use crate::helper::{Action, Context, Error, NextAction, Outcome, Result}; impl Action { /// Send ourselves to the given `write` which is expected to be credentials-helper compatible - pub fn send(&self, mut write: impl std::io::Write) -> std::io::Result<()> { + pub fn send(&self, write: &mut dyn std::io::Write) -> std::io::Result<()> { match self { Action::Get(ctx) => ctx.write_to(write), Action::Store(last) | Action::Erase(last) => { @@ -40,11 +40,12 @@ pub fn invoke(helper: &mut crate::Program, action: &Action) -> Result { } pub(crate) fn raw(helper: &mut crate::Program, action: &Action) -> std::result::Result>, Error> { - let (stdin, stdout) = helper.start(action)?; + let (mut stdin, stdout) = helper.start(action)?; if let (Action::Get(_), None) = (&action, &stdout) { panic!("BUG: `Helper` impls must return an output handle to read output from if Action::Get is provided") } - action.send(stdin)?; + action.send(&mut stdin)?; + drop(stdin); let stdout = stdout .map(|mut stdout| { let mut buf = Vec::new(); diff --git a/gix-credentials/src/program/mod.rs b/gix-credentials/src/program/mod.rs index e13e0a5ecfa..80146601856 100644 --- a/gix-credentials/src/program/mod.rs +++ b/gix-credentials/src/program/mod.rs @@ -39,29 +39,31 @@ impl Program { /// Parse the given input as per the custom helper definition, supporting `!