Skip to content

Commit ab69604

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 579adaf commit ab69604

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +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) as well as a way to initialize
56-
/// our attributes with `collection`.
55+
/// Create a new pipeline with configured `drivers` (which should be considered safe to invoke).
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(collection: &gix_attributes::search::MetadataCollection, options: Options) -> Self {
59+
pub fn new(options: Options) -> Self {
6160
let mut attrs = gix_attributes::search::Outcome::default();
62-
attrs.initialize_with_selection(collection, ATTRS);
61+
attrs.initialize_with_selection(&Default::default(), ATTRS);
6362
Pipeline {
6463
attrs,
6564
context: Context::default(),
@@ -79,8 +78,7 @@ impl Pipeline {
7978

8079
impl Default for Pipeline {
8180
fn default() -> Self {
82-
let collection = Default::default();
83-
Pipeline::new(&collection, Default::default())
81+
Pipeline::new(Default::default())
8482
}
8583
}
8684

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: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,12 @@ fn pipeline(
5757
) -> gix_testtools::Result<(gix_worktree::Stack, gix_filter::Pipeline)> {
5858
let cache = attribute_cache(name)?;
5959
let (drivers, encodings_with_roundtrip_check, crlf_roundtrip_check, eol_config) = init();
60-
let pipe = gix_filter::Pipeline::new(
61-
cache.attributes_collection(),
62-
gix_filter::pipeline::Options {
63-
drivers,
64-
eol_config,
65-
encodings_with_roundtrip_check,
66-
crlf_roundtrip_check,
67-
object_hash: gix_hash::Kind::Sha1,
68-
},
69-
);
60+
let pipe = gix_filter::Pipeline::new(gix_filter::pipeline::Options {
61+
drivers,
62+
eol_config,
63+
encodings_with_roundtrip_check,
64+
crlf_roundtrip_check,
65+
object_hash: gix_hash::Kind::Sha1,
66+
});
7067
Ok((cache, pipe))
7168
}

0 commit comments

Comments
 (0)