Skip to content

Commit 0424719

Browse files
committed
feat: add excludes feature to make exclude-checks possible.
1 parent c79cf74 commit 0424719

File tree

20 files changed

+262
-162
lines changed

20 files changed

+262
-162
lines changed

gix/Cargo.toml

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ default = ["max-performance-safe", "comfort", "basic", "extras"]
5151
basic = ["blob-diff", "revision"]
5252

5353
## Various additional features and capabilities that are not necessarily part of what most users would need.
54-
extras = ["worktree-stream", "worktree-archive", "revparse-regex", "mailmap"]
54+
extras = ["worktree-stream", "worktree-archive", "revparse-regex", "mailmap", "excludes", "attributes", "worktree-mutation"]
5555

5656
## Various progress-related features that improve the look of progress message units.
5757
comfort = ["gix-features/progress-unit-bytes", "gix-features/progress-unit-human-numbers"]
5858

5959
#! #### Components
6060
#!
6161
#! A component is a distinct feature which may be comprised of one or more methods around a particular topic.
62-
#! Providers of libraries should only activate
62+
#! Providers of libraries should only activate the components they need.
63+
64+
## Various ways to alter the worktree makeup by checkout and reset.
65+
worktree-mutation = ["attributes", "dep:gix-worktree-state"]
66+
67+
## Retrieve a worktree stack for querying exclude information
68+
excludes = ["dep:gix-ignore", "dep:gix-worktree"]
69+
70+
## Query attributes and excludes. Enables access to pathspecs, worktree checkouts, filter-pipelines and submodules.
71+
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes"]
6372

6473
## Add support for mailmaps, as way of determining the final name of commmiters and authors.
6574
mailmap = ["dep:gix-mailmap"]
@@ -76,13 +85,13 @@ revparse-regex = ["regex", "revision"]
7685
blob-diff = ["gix-diff/blob"]
7786

7887
## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats.
79-
worktree-stream = ["gix-worktree-stream"]
88+
worktree-stream = ["gix-worktree-stream", "attributes"]
8089

8190
## Create archives from a tree in the repository, similar to what `git archive` does.
8291
##
8392
## Note that we disable all default features which strips it off all container support, like `tar` and `zip`.
8493
## Your application should add it as dependency and re-activate the desired features.
85-
worktree-archive = ["gix-archive", "worktree-stream"]
94+
worktree-archive = ["gix-archive", "worktree-stream", "attributes"]
8695

8796
#! #### Mutually Exclusive Network Client
8897
#!
@@ -91,11 +100,11 @@ worktree-archive = ["gix-archive", "worktree-stream"]
91100
#! Making a choice here also affects which crypto-library ends up being used.
92101

93102
## Make `gix-protocol` available along with an async client.
94-
async-network-client = ["gix-protocol/async-client", "gix-pack/streaming-input"]
103+
async-network-client = ["gix-protocol/async-client", "gix-pack/streaming-input", "attributes"]
95104
## Use this if your crate uses `async-std` as runtime, and enable basic runtime integration when connecting to remote servers via the `git://` protocol.
96105
async-network-client-async-std = ["async-std", "async-network-client", "gix-transport/async-std"]
97106
## Make `gix-protocol` available along with a blocking client, providing access to the `file://`, git://` and `ssh://` transports.
98-
blocking-network-client = ["gix-protocol/blocking-client", "gix-pack/streaming-input"]
107+
blocking-network-client = ["gix-protocol/blocking-client", "gix-pack/streaming-input", "attributes"]
99108
## Stacks with `blocking-network-client` to provide support for HTTP/S using **curl**, and implies blocking networking as a whole, making the `https://` transport avaialble.
100109
blocking-http-transport-curl = ["blocking-network-client", "gix-transport/http-client-curl"]
101110
## Stacks with `blocking-network-client` to provide support for HTTP/S using **reqwest**, and implies blocking networking as a whole, making the `https://` transport avaialble.
@@ -155,10 +164,10 @@ serde = [ "dep:serde",
155164
"gix-index/serde",
156165
"gix-mailmap?/serde",
157166
"gix-url/serde",
158-
"gix-attributes/serde",
159-
"gix-ignore/serde",
167+
"gix-attributes?/serde",
168+
"gix-ignore?/serde",
160169
"gix-revision/serde",
161-
"gix-worktree/serde",
170+
"gix-worktree?/serde",
162171
"gix-commitgraph/serde",
163172
"gix-credentials/serde"]
164173

@@ -182,7 +191,7 @@ gix-validate = { version = "^0.8.0", path = "../gix-validate" }
182191
gix-sec = { version = "^0.9.0", path = "../gix-sec" }
183192
gix-date = { version = "^0.7.4", path = "../gix-date" }
184193
gix-refspec = { version = "^0.16.0", path = "../gix-refspec" }
185-
gix-filter = { version = "^0.3.0", path = "../gix-filter" }
194+
gix-filter = { version = "^0.3.0", path = "../gix-filter", optional = true }
186195

187196
gix-config = { version = "^0.28.0", path = "../gix-config" }
188197
gix-odb = { version = "^0.51.0", path = "../gix-odb" }
@@ -202,18 +211,18 @@ gix-mailmap = { version = "^0.17.0", path = "../gix-mailmap", optional = true }
202211
gix-features = { version = "^0.33.0", path = "../gix-features", features = ["progress", "once_cell"] }
203212
gix-trace = { version = "^0.1.3", path = "../gix-trace" }
204213

205-
gix-attributes = { version = "^0.17.0", path = "../gix-attributes" }
206-
gix-ignore = { version = "^0.6.0", path = "../gix-ignore" }
207214
gix-glob = { version = "^0.11.0", path = "../gix-glob" }
208215
gix-credentials = { version = "^0.18.0", path = "../gix-credentials" }
209216
gix-prompt = { version = "^0.6.0", path = "../gix-prompt" }
210217
gix-index = { version = "^0.23.1", path = "../gix-index" }
211-
gix-worktree = { version = "^0.25.0", path = "../gix-worktree" }
212-
gix-worktree-state = { version = "^0.2.0", path = "../gix-worktree-state" }
218+
gix-attributes = { version = "^0.17.0", path = "../gix-attributes", optional = true }
219+
gix-ignore = { version = "^0.6.0", path = "../gix-ignore", optional = true }
220+
gix-worktree = { version = "^0.25.0", path = "../gix-worktree", optional = true, default-features = false }
221+
gix-worktree-state = { version = "^0.2.0", path = "../gix-worktree-state", optional = true }
213222
gix-hashtable = { version = "^0.3.0", path = "../gix-hashtable" }
214223
gix-commitgraph = { version = "^0.19.0", path = "../gix-commitgraph" }
215-
gix-pathspec = { version = "^0.1.0", path = "../gix-pathspec" }
216-
gix-submodule = { version = "^0.2.0", path = "../gix-submodule" }
224+
gix-pathspec = { version = "^0.1.0", path = "../gix-pathspec", optional = true }
225+
gix-submodule = { version = "^0.2.0", path = "../gix-submodule", optional = true }
217226

218227
gix-worktree-stream = { version = "^0.3.0", path = "../gix-worktree-stream", optional = true }
219228
gix-archive = { version = "^0.3.0", path = "../gix-archive", default-features = false, optional = true }

gix/src/clone/fetch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl PrepareFetch {
149149
}
150150

151151
/// Similar to [`fetch_only()`][Self::fetch_only()`], but passes ownership to a utility type to configure a checkout operation.
152-
#[cfg(feature = "blocking-network-client")]
152+
#[cfg(all(feature = "worktree-mutation", feature = "blocking-network-client"))]
153153
pub fn fetch_then_checkout<P>(
154154
&mut self,
155155
progress: P,

gix/src/clone/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl PrepareFetch {
122122
/// A utility to collect configuration on how to perform a checkout into a working tree, and when dropped without checking out successfully
123123
/// the fetched repository will be dropped.
124124
#[must_use]
125+
#[cfg(feature = "worktree-mutation")]
125126
pub struct PrepareCheckout {
126127
/// A freshly initialized repository which is owned by us, or `None` if it was handed to the user
127128
pub(self) repo: Option<crate::Repository>,
@@ -165,4 +166,5 @@ mod access_feat {
165166
pub mod fetch;
166167

167168
///
169+
#[cfg(feature = "worktree-mutation")]
168170
pub mod checkout;

gix/src/config/cache/access.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(clippy::result_large_err)]
22
use std::{borrow::Cow, path::PathBuf, time::Duration};
33

4-
use gix_attributes::Source;
54
use gix_lock::acquire::Fail;
65

76
use crate::{
@@ -10,13 +9,11 @@ use crate::{
109
config::{
1110
boolean,
1211
cache::util::{ApplyLeniency, ApplyLeniencyDefaultValue},
13-
checkout_options,
14-
tree::{gitoxide, Checkout, Core, Key},
12+
tree::{Core, Key},
1513
Cache,
1614
},
17-
filter, remote,
15+
remote,
1816
repository::identity,
19-
Repository,
2017
};
2118

2219
/// Access
@@ -116,6 +113,7 @@ impl Cache {
116113
}
117114

118115
/// The path to the user-level excludes file to ignore certain files in the worktree.
116+
#[cfg(feature = "excludes")]
119117
pub(crate) fn excludes_file(&self) -> Option<Result<PathBuf, gix_config::path::interpolate::Error>> {
120118
self.trusted_file_path("core", None, Core::EXCLUDES_FILE.name)?
121119
.map(std::borrow::Cow::into_owned)
@@ -159,21 +157,23 @@ impl Cache {
159157
/// Collect everything needed to checkout files into a worktree.
160158
/// Note that some of the options being returned will be defaulted so safe settings, the caller might have to override them
161159
/// depending on the use-case.
160+
#[cfg(feature = "worktree-mutation")]
162161
pub(crate) fn checkout_options(
163162
&self,
164-
repo: &Repository,
163+
repo: &crate::Repository,
165164
attributes_source: gix_worktree::stack::state::attributes::Source,
166-
) -> Result<gix_worktree_state::checkout::Options, checkout_options::Error> {
165+
) -> Result<gix_worktree_state::checkout::Options, crate::config::checkout_options::Error> {
166+
use crate::config::tree::gitoxide;
167167
let git_dir = repo.git_dir();
168168
let thread_limit = self.apply_leniency(
169169
self.resolved
170170
.integer_filter_by_key("checkout.workers", &mut self.filter_config_section.clone())
171-
.map(|value| Checkout::WORKERS.try_from_workers(value)),
171+
.map(|value| crate::config::tree::Checkout::WORKERS.try_from_workers(value)),
172172
)?;
173173
let capabilities = self.fs_capabilities()?;
174174
let filters = {
175175
let collection = Default::default();
176-
let mut filters = gix_filter::Pipeline::new(&collection, filter::Pipeline::options(repo)?);
176+
let mut filters = gix_filter::Pipeline::new(&collection, crate::filter::Pipeline::options(repo)?);
177177
if let Ok(mut head) = repo.head() {
178178
let ctx = filters.driver_context_mut();
179179
ctx.ref_name = head.referent_name().map(|name| name.as_bstr().to_owned());
@@ -217,6 +217,7 @@ impl Cache {
217217
})
218218
}
219219

220+
#[cfg(feature = "excludes")]
220221
pub(crate) fn assemble_exclude_globals(
221222
&self,
222223
git_dir: &std::path::Path,
@@ -236,12 +237,14 @@ impl Cache {
236237
))
237238
}
238239
// TODO: at least one test, maybe related to core.attributesFile configuration.
240+
#[cfg(feature = "attributes")]
239241
pub(crate) fn assemble_attribute_globals(
240242
&self,
241243
git_dir: &std::path::Path,
242244
source: gix_worktree::stack::state::attributes::Source,
243245
attributes: crate::open::permissions::Attributes,
244246
) -> Result<(gix_worktree::stack::state::Attributes, Vec<u8>), config::attribute_stack::Error> {
247+
use gix_attributes::Source;
245248
let configured_or_user_attributes = match self
246249
.trusted_file_path("core", None, Core::ATTRIBUTES_FILE.name)
247250
.transpose()?
@@ -276,9 +279,11 @@ impl Cache {
276279
Ok((state, buf))
277280
}
278281

282+
#[cfg(feature = "attributes")]
279283
pub(crate) fn pathspec_defaults(
280284
&self,
281285
) -> Result<gix_pathspec::Defaults, gix_pathspec::defaults::from_environment::Error> {
286+
use crate::config::tree::gitoxide;
282287
let res = gix_pathspec::Defaults::from_environment(&mut |name| {
283288
let key = [
284289
&gitoxide::Pathspec::ICASE,
@@ -303,6 +308,7 @@ impl Cache {
303308
}
304309
}
305310

311+
#[cfg(any(feature = "attributes", feature = "excludes"))]
306312
pub(crate) fn xdg_config_path(
307313
&self,
308314
resource_file_name: &str,

gix/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub mod diff {
119119
}
120120

121121
///
122+
#[cfg(feature = "attributes")]
122123
pub mod checkout_options {
123124
/// The error produced when collecting all information needed for checking out files into a worktree.
124125
#[derive(Debug, thiserror::Error)]
@@ -520,6 +521,7 @@ pub(crate) struct Cache {
520521
/// If true, we should default what's possible if something is misconfigured, on case by case basis, to be more resilient.
521522
/// Also available in options! Keep in sync!
522523
pub lenient_config: bool,
524+
#[cfg_attr(not(feature = "worktree-mutation"), allow(dead_code))]
523525
attributes: crate::open::permissions::Attributes,
524526
environment: crate::open::permissions::Environment,
525527
// TODO: make core.precomposeUnicode available as well.

0 commit comments

Comments
 (0)