Skip to content

Commit c74c7fe

Browse files
committed
feat!: simplify Pipeline::new() by reomving the metadata collection.
It's required, but in practice has no effect as it's initialized at just the right time anyway, which is when it does matter. Also, re-export `gix_attributes as attributes` to allow using the types it mentions in the public API.
1 parent c752f67 commit c74c7fe

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

gix-filter/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
//! or not to apply such a filter.
1111
#![deny(rust_2018_idioms, missing_docs, unsafe_code)]
1212

13+
/// The `gix-attributes` crate whose types are mentioned in the public API of [Pipeline::convert_to_worktree()].
14+
pub use gix_attributes as attributes;
15+
1316
use bstr::BString;
1417
/// A forwarding of the `encoding_rs` crate for its types and convenience.
1518
pub use encoding_rs as encoding;

gix-filter/src/pipeline/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,13 @@ const ATTRS: [&str; 6] = ["crlf", "ident", "filter", "eol", "text", "working-tre
5252

5353
/// Lifecycle
5454
impl Pipeline {
55-
/// Create a new pipeline with configured `drivers` (which should be considered safe to invoke) with `context` as well as
56-
/// a way to initialize our attributes with `collection`.
55+
/// Create a new pipeline with configured `drivers` (which should be considered safe to invoke), which are passed `context`.
5756
/// `eol_config` serves as fallback to understand how to convert line endings if no line-ending attributes are present.
5857
/// `crlf_roundtrip_check` corresponds to the git-configuration of `core.safecrlf`.
5958
/// `object_hash` is relevant for the `ident` filter.
60-
pub fn new(
61-
collection: &gix_attributes::search::MetadataCollection,
62-
context: gix_command::Context,
63-
options: Options,
64-
) -> Self {
59+
pub fn new(context: gix_command::Context, options: Options) -> Self {
6560
let mut attrs = gix_attributes::search::Outcome::default();
66-
attrs.initialize_with_selection(collection, ATTRS);
61+
attrs.initialize_with_selection(&Default::default(), ATTRS);
6762
Pipeline {
6863
attrs,
6964
context: Context::default(),
@@ -83,8 +78,7 @@ impl Pipeline {
8378

8479
impl Default for Pipeline {
8580
fn default() -> Self {
86-
let collection = Default::default();
87-
Pipeline::new(&collection, Default::default(), Default::default())
81+
Pipeline::new(Default::default(), Default::default())
8882
}
8983
}
9084

gix-filter/tests/driver/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ pub(crate) mod apply {
138138
fn a_crashing_process_can_restart_it() -> crate::Result {
139139
let mut state = gix_filter::driver::State::default();
140140
let driver = driver_with_process();
141+
let err = match state.apply(
142+
&driver,
143+
&mut std::io::empty(),
144+
Operation::Smudge,
145+
context_from_path("fail"),
146+
) {
147+
Ok(_) => panic!("expecting an error as invalid context was passed"),
148+
Err(err) => err,
149+
};
141150
assert!(
142-
matches!(
143-
state.apply(
144-
&driver,
145-
&mut std::io::empty(),
146-
Operation::Smudge,
147-
context_from_path("fail")
148-
),
149-
Err(gix_filter::driver::apply::Error::ProcessInvoke { .. })
150-
),
151-
"cannot invoke if failure is requested"
151+
matches!(err, gix_filter::driver::apply::Error::ProcessInvoke { .. }),
152+
"{err:?}: cannot invoke if failure is requested"
152153
);
153154

154155
let mut filtered = state

gix-filter/tests/pipeline/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ fn pipeline(
5858
let cache = attribute_cache(name)?;
5959
let (drivers, encodings_with_roundtrip_check, crlf_roundtrip_check, eol_config) = init();
6060
let pipe = gix_filter::Pipeline::new(
61-
cache.attributes_collection(),
6261
Default::default(),
6362
gix_filter::pipeline::Options {
6463
drivers,

0 commit comments

Comments
 (0)