Skip to content

Commit

Permalink
feat: add Repository::big_file_threshold() to easily learn what Git…
Browse files Browse the repository at this point in the history
… considers a big file.
  • Loading branch information
Byron committed Jan 20, 2025
1 parent 1ccbeef commit f3257f3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 0 additions & 1 deletion gix/src/config/cache/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl Cache {
.copied()
}

#[cfg(feature = "blob-diff")]
pub(crate) fn big_file_threshold(&self) -> Result<u64, config::unsigned_integer::Error> {
Ok(self
.resolved
Expand Down
6 changes: 6 additions & 0 deletions gix/src/repository/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl crate::Repository {
&self.options
}

/// Return the big-file threshold above which Git will not perform a diff anymore or try to delta-diff packs,
/// as configured by `core.bigFileThreshold`, or the default value.
pub fn big_file_threshold(&self) -> Result<u64, config::unsigned_integer::Error> {
self.config.big_file_threshold()
}

/// Obtain options for use when connecting via `ssh`.
#[cfg(feature = "blocking-network-client")]
pub fn ssh_connect_options(
Expand Down
Binary file modified gix/tests/fixtures/generated-archives/make_config_repos.tar
Binary file not shown.
5 changes: 5 additions & 0 deletions gix/tests/fixtures/make_config_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ EOF
echo $'[remote "any"]\n\turl=anyurl' >>config

)

git init big-file-threshold
(cd big-file-threshold
git config core.bigFileThreshold 42
)
16 changes: 14 additions & 2 deletions gix/tests/gix/repository/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ mod config_snapshot;
mod identity;
mod remote;

#[test]
fn big_file_threshold() -> crate::Result {
let repo = repo("with-hasconfig");
assert_eq!(
repo.big_file_threshold()?,
512 * 1024 * 1024,
"Git really handles huge files, and this is the default"
);

let repo = crate::repository::config::repo("big-file-threshold");
assert_eq!(repo.big_file_threshold()?, 42, "It picks up configured values as well");
Ok(())
}

#[cfg(feature = "blocking-network-client")]
mod ssh_options {
use std::ffi::OsStr;
Expand Down Expand Up @@ -38,12 +52,10 @@ mod ssh_options {
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
mod transport_options;

#[cfg(feature = "blocking-network-client")]
pub fn repo(name: &str) -> gix::Repository {
repo_opts(name, |opts| opts.strict_config(true))
}

#[cfg(feature = "blocking-network-client")]
pub fn repo_opts(name: &str, modify: impl FnOnce(gix::open::Options) -> gix::open::Options) -> gix::Repository {
let dir = gix_testtools::scripted_fixture_read_only("make_config_repos.sh").unwrap();
gix::open_opts(dir.join(name), modify(gix::open::Options::isolated())).unwrap()
Expand Down

0 comments on commit f3257f3

Please sign in to comment.