New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows the default git/gitoxide configuration to be obtained from the ENV and config #13687
base: master
Are you sure you want to change the base?
Conversation
I assume this is meant to resolve the immediate part of #13688 (leaving aside the more general problem). Is that right? |
src/cargo/core/features.rs
Outdated
@@ -908,15 +914,19 @@ fn parse_git(it: impl Iterator<Item = impl AsRef<str>>) -> CargoResult<Option<Gi | |||
#[derive(Debug, Copy, Clone, Default, Deserialize)] | |||
pub struct GitoxideFeatures { | |||
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index. | |||
#[serde(default = "default_true")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these were chosen to align with GitoxideFeatures::safe()
and to mirror if you do -Zgitoxide
However, this breaks down if you do CARGO_UNSTABLE_GITOXIDE_FETCH=true
, then almost everything else becomes enabled (we should have a test to show this case).
Some other challenges with these defaults
- Unclear what the motivation is (could have comment pointing to
GitoxideFeature::safe
) - Challenge in keeping in sync with
GitoxideFeature::safe
Should we instead just default everything to false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would love to just work is CARGO_UNSTABLE_GITOXIDE=fetch,list_files
and CARGO_UNSTABLE_GITOXIDE=true
mirroring the CLI flag (which would also imply you could have unstable.gitoxide = "fetch,list_files"
in the config file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah maybe we can make it a comma separated list to reduce the complexity.
Wonder do people really use individual gitoxide features? I always assume that people would just enable them as a whole, though gitoxide author recommends keeping them separately: #13252 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would love to just work is CARGO_UNSTABLE_GITOXIDE=fetch,list_files and CARGO_UNSTABLE_GITOXIDE=true mirroring the CLI flag (which would also imply you could have unstable.gitoxide = "fetch,list_files" in the config file).
So what we defined as table is going to be replaced with a string? It makes sense, I have no objection to this, but it is not clear that it will break the configuration of the previous version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to support both, via #[serde(deserialize_with = ...)]
and a custom deserializer that handles a string/list or a struct, like
cargo/src/cargo/util/context/mod.rs
Line 2673 in 88d55a8
fn progress_or_string<'de, D>(deserializer: D) -> Result<Option<ProgressConfig>, D::Error> |
☔ The latest upstream changes (presumably #13696) made this pull request unmergeable. Please resolve the merge conflicts. |
r? weihanglo |
e852649
to
b5fd826
Compare
In my new commit, a string can be parsed as git/gitoxide features in ENV and Config.
In Config, the git/gitoxide can be defined as
the unspecified field can be skipped, because it defined as Rust default value. Back to the original use of environment variables, now you just need to specify the field you want to modify, the rest field will use Rust default value.
But you should keep in mind, the rest field will use Rust default value, not pre-defined value. That said, See |
Yes,this tend to mirror the -Zgit/-Zgitoxide as possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review 🙇🏾♂️
src/cargo/util/context/de.rs
Outdated
// then run `CARGO_UNSTABLE_GIT_SHALLOW_INDEX cargo fetch`, here will return `missing config key unstable.git`. | ||
// It seems that anything that starts with CARGO_UNSTABLE_GIT, even like CARGO_UNSTABLE_GITOXIDE can trigger this. | ||
// This is a workaround for now, but should be fixed in the future. | ||
visitor.visit_none() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this seems fine for now, I am a bit worried about the change.
What about having an enum deriving serde?
#[derive(Debug, Copy, Clone, Default, Deserialize)]
#[serde(untagged)]
pub enum Gitoxide {
#[default]
All,
Some(GitoxideFeatures),
}
so that I assumed it would work well with
[unstable]
gitoxide = true
# or
[unstable.gitoxide]
checkout = true
As well as enviroment variables?
CARGO_UNSTABLE_GITOXIDE=true
CARGO_UNSTABLE_GITOXIDE_CHECKOUT=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to be working. see gitoxide_features_as_table
in the lastest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had replaced vistor.visit_none()
with below,
// The effect here is the same as in [`deserialize_option`].
if self.gctx.has_key(&self.key, self.env_prefix_ok)? {
return visitor.visit_some(self);
}
So we can still specify a inner field of a struct in the ENV, like CARGO_UNSTABLE_GITOXIDE_FETCH
, even that CARGO_UNSTABLE_GIOXIDE
doesn't exist.
But that's not enough, It will still warning unstable.git
missing key, Why is this happening? After some groping, Problems gradually surfaced, see https://github.com/rust-lang/cargo/blob/master/src/cargo/util/context/de.rs#L268-L269
if env_key.starts_with(field_key.as_env_key()) {
fields.insert(KeyKind::Normal(field.to_string()));
here will treat CARGO_UNSTABLE_GIT
as prefix of CARGO_UNSTABLE_GIOXIDE_FETCH
, and the unstable.git
and unsable.gitoxide
will be pushed into fields. This is a problem, when the unstable fields is a struct and the fields implement their deserialize_any
method. So any environment variable that starts with the XX character will have missing XX keys.
See test struct_with_overlapping_inner_struct_and_defaults
for more details.
7592481
to
76421f7
Compare
- pass 'all' or true to enable all pre-definded git/gitoxide features - support parse git/gitoxide as table in Config, if the field is tagged with #[serde(default)], then it can be skipped
76421f7
to
b4f699e
Compare
@@ -265,8 +271,14 @@ impl<'gctx> ConfigMapAccess<'gctx> { | |||
let mut field_key = de.key.clone(); | |||
field_key.push(field); | |||
for env_key in de.gctx.env_keys() { | |||
if env_key.starts_with(field_key.as_env_key()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #13687 (comment)
I wonder if this is worth fixing on separately PR. Because it's only a problem in my situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. I'll find a time reviewing this.
(it's always a headache for me to read config deserialization code 🤯)
☔ The latest upstream changes (presumably #13956) made this pull request unmergeable. Please resolve the merge conflicts. |
What does this PR try to resolve?
The default git/gitoxide feautures config can be obtained througt
-Zgit
and-Zgitoxide
.However, it cannot be obtained from environment variables or configurations.
It's not very ergonomic.
How should we test and review this PR?
The previous commit explained the staus quo, the next commit addressed the problem.
Additional information
Inspired by #11813 (comment)
See also #13285 (comment)
Change of usage
Specify the feature you like
Besides, you can pass "all" to use the pre-defined features.
The rest fields will use Rust default value. That said, checkout and internal_use_git2 will be false.
Besides, you can pass true to the whole feature to specify the pre-defined features.