Skip to content

Don’t change semantic behaviour based on debug_assertions #1882

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

Merged
merged 6 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions gitoxide-core/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ pub fn list(
if format != OutputFormat::Human {
bail!("Only human output format is supported at the moment");
}
let repo = gix::open_opts(
repo.git_dir(),
repo.open_options().clone().lossy_config(false).cli_overrides(overrides),
)?;
let repo = gix::open_opts(repo.git_dir(), repo.open_options().clone().cli_overrides(overrides))?;
let config = repo.config_snapshot();
if let Some(frontmatter) = config.frontmatter() {
for event in frontmatter {
Expand Down
6 changes: 4 additions & 2 deletions gix-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ http-client-reqwest-rust-tls-trust-dns = [
]
## Stacks with `blocking-http-transport-reqwest` and enables `https://` via the `native-tls` crate.
http-client-reqwest-native-tls = ["http-client-reqwest", "reqwest/default-tls"]
## Allows sending credentials over cleartext HTTP. For testing purposes only.
http-client-insecure-credentials = []
## If set, an async implementations of the git transports becomes available in `crate::client`.
## Suitable for implementing your own transports while using git's way of communication, typically in conjunction with a custom server.
## **Note** that the _blocking_ client has a wide range of available transports, with the _async_ version of it supporting only the TCP based `git` transport leaving you
Expand All @@ -66,12 +68,12 @@ serde = ["dep:serde"]
[[test]]
name = "blocking-transport"
path = "tests/blocking-transport.rs"
required-features = ["blocking-client", "maybe-async/is_sync"]
required-features = ["blocking-client", "http-client-insecure-credentials", "maybe-async/is_sync"]

[[test]]
name = "blocking-transport-http-only"
path = "tests/blocking-transport-http.rs"
required-features = ["http-client-curl", "maybe-async/is_sync"]
required-features = ["http-client-curl", "http-client-insecure-credentials", "maybe-async/is_sync"]

[[test]]
name = "async-transport"
Expand Down
2 changes: 1 addition & 1 deletion gix-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<H: Http> Transport<H> {
#[allow(clippy::unnecessary_wraps, unknown_lints)]
fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {
if let Some(gix_sec::identity::Account { username, password }) = &self.identity {
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "http-client-insecure-credentials"))]
if self.url.starts_with("http://") {
return Err(client::Error::AuthenticationRefused(
"Will not send credentials in clear text over http",
Expand Down
6 changes: 3 additions & 3 deletions gix/src/config/cache/incubate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct StageOne {
pub buf: Vec<u8>,

pub is_bare: bool,
pub lossy: Option<bool>,
pub lossy: bool,
pub object_hash: gix_hash::Kind,
pub reflog: Option<gix_ref::store::WriteReflog>,
pub precompose_unicode: bool,
Expand All @@ -24,7 +24,7 @@ impl StageOne {
common_dir: &std::path::Path,
git_dir: &std::path::Path,
git_dir_trust: gix_sec::Trust,
lossy: Option<bool>,
lossy: bool,
lenient: bool,
) -> Result<Self, Error> {
let mut buf = Vec::with_capacity(512);
Expand Down Expand Up @@ -109,7 +109,7 @@ fn load_config(
buf: &mut Vec<u8>,
source: gix_config::Source,
git_dir_trust: gix_sec::Trust,
lossy: Option<bool>,
lossy: bool,
lenient: bool,
) -> Result<gix_config::File<'static>, Error> {
let metadata = gix_config::file::Metadata::from(source)
Expand Down
4 changes: 2 additions & 2 deletions gix/src/config/cache/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub(crate) fn interpolate_context<'a>(
}
}

pub(crate) fn base_options(lossy: Option<bool>, lenient: bool) -> gix_config::file::init::Options<'static> {
pub(crate) fn base_options(lossy: bool, lenient: bool) -> gix_config::file::init::Options<'static> {
gix_config::file::init::Options {
lossy: lossy.unwrap_or(!cfg!(debug_assertions)),
lossy,
ignore_io_errors: lenient,
..Default::default()
}
Expand Down
2 changes: 1 addition & 1 deletion gix/src/open/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct Options {
pub(crate) git_dir_trust: Option<gix_sec::Trust>,
/// Warning: this one is copied to config::Cache - don't change it after repo open or keep in sync.
pub(crate) filter_config_section: Option<fn(&gix_config::file::Metadata) -> bool>,
pub(crate) lossy_config: Option<bool>,
pub(crate) lossy_config: bool,
pub(crate) lenient_config: bool,
pub(crate) bail_if_untrusted: bool,
pub(crate) api_config_overrides: Vec<BString>,
Expand Down
15 changes: 7 additions & 8 deletions gix/src/open/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl Default for Options {
permissions: Default::default(),
git_dir_trust: None,
filter_config_section: None,
lossy_config: None,
lossy_config: false,
lenient_config: true,
bail_if_untrusted: false,
open_path_as_is: false,
Expand Down Expand Up @@ -120,13 +120,12 @@ impl Options {
self
}

/// By default, in release mode configuration will be read without retaining non-essential information like
/// comments or whitespace to optimize lookup performance.
/// If set, default is false, configuration will be read without retaining non-essential information like comments
/// or whitespace to optimize lookup performance.
///
/// Some application might want to toggle this to false in they want to display or edit configuration losslessly
/// with all whitespace and comments included.
/// This will prevent displaying or editing configuration losslessly.
pub fn lossy_config(mut self, toggle: bool) -> Self {
self.lossy_config = toggle.into();
self.lossy_config = toggle;
self
}

Expand Down Expand Up @@ -163,7 +162,7 @@ impl gix_sec::trust::DefaultForLevel for Options {
permissions: Permissions::default_for_level(level),
git_dir_trust: gix_sec::Trust::Full.into(),
filter_config_section: Some(config::section::is_trusted),
lossy_config: None,
lossy_config: false,
bail_if_untrusted: false,
lenient_config: true,
open_path_as_is: false,
Expand All @@ -179,7 +178,7 @@ impl gix_sec::trust::DefaultForLevel for Options {
bail_if_untrusted: false,
lenient_config: true,
open_path_as_is: false,
lossy_config: None,
lossy_config: false,
api_config_overrides: Vec::new(),
cli_config_overrides: Vec::new(),
current_dir: None,
Expand Down
Loading