Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gix-commitgraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ rust-version = "1.82"
doctest = false

[features]
## Support for SHA256 hashes and digests.
sha256 = ["gix-hash/sha256"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd want to use dev-dependencies to always add sha256 to the features when testing. That way, there is only one way to run tests: all of them.

## Data structures implement `serde::Serialize` and `serde::Deserialize`
serde = ["dep:serde", "gix-hash/serde", "bstr/serde"]

Expand All @@ -33,6 +35,7 @@ document-features = { version = "0.2.0", optional = true }
[dev-dependencies]
gix-testtools = { path = "../tests/tools" }
gix-date = { path = "../gix-date" }
gix-hash = { path = "../gix-hash", features = ["sha256"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions gix-diff/src/tree/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ mod tests {
#[test]
fn size_of_change() {
let actual = std::mem::size_of::<Change>();
let ceiling = 72;
assert!(
actual <= 48,
"{actual} <= 48: this type shouldn't grow without us knowing"
actual <= ceiling,
"{actual} <= {ceiling}: this type shouldn't grow without us knowing"
);
}
}
2 changes: 1 addition & 1 deletion gix-index/src/extension/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod tests {
#[test]
fn size_of_tree() {
let actual = std::mem::size_of::<crate::extension::Tree>();
let expected = 88;
let expected = 104;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-index/tests/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn loose_file_path(name: &str) -> PathBuf {
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<gix_index::Entry>();
let expected = 80;
let expected = 96;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-negotiate/tests/negotiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod baseline;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<gix_revwalk::graph::Commit<gix_negotiate::Metadata>>();
let expected = 56;
let expected = 72;
assert!(
size_ok(actual, expected),
"we may keep a lot of these, so let's not let them grow unnoticed: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-object/tests/object/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn fixture_name(kind: &str, path: &str) -> Vec<u8> {
fn size_in_memory() {
let actual = std::mem::size_of::<gix_object::Object>();
assert!(
actual <= 272,
actual <= 288,
"{actual} <= 272: Prevent unexpected growth of what should be lightweight objects"
);
}
Expand Down
2 changes: 1 addition & 1 deletion gix-pack/src/cache/delta/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ mod tests {
}

let actual = std::mem::size_of::<[Item<EntryWithDefault>; 7_500_000]>();
let expected = 840_000_000;
let expected = 960_000_000;
assert!(
size_ok(actual, expected),
"we don't want these to grow unnoticed: {actual} <~ {expected}"
Expand Down
4 changes: 2 additions & 2 deletions gix-pack/tests/pack/data/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use gix_testtools::size_ok;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<output::Entry>();
let expected = 80;
let expected = 112;
assert!(
size_ok(actual, expected),
"The size of the structure shouldn't change unexpectedly: {actual} <~ {expected}"
Expand All @@ -16,7 +16,7 @@ fn size_of_entry() {
#[test]
fn size_of_count() {
let actual = std::mem::size_of::<output::Count>();
let expected = 56;
let expected = 72;
assert!(
size_ok(actual, expected),
"The size of the structure shouldn't change unexpectedly: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-pack/tests/pack/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use gix_testtools::size_ok;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<pack::data::input::Entry>();
let expected = 104;
let expected = 136;
assert!(
size_ok(actual, expected),
"let's keep the size in check as we have many of them: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-ref/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod tests {
#[test]
fn size_of_reference() {
let actual = std::mem::size_of::<Reference>();
let expected = 80;
let expected = 104;
assert!(
size_ok(actual, expected),
"let's not let it change size undetected: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix-revwalk/tests/revwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod graph {
#[test]
fn size_of_commit() {
let actual = std::mem::size_of::<gix_revwalk::graph::Commit<()>>();
let expected = 48;
let expected = 64;
assert!(
size_ok(actual, expected),
"We might see quite a lot of these, so they shouldn't grow unexpectedly: {actual} <~ {expected}"
Expand Down
2 changes: 1 addition & 1 deletion gix/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod tests {
#[test]
fn size_of_oid() {
let actual = std::mem::size_of::<Id<'_>>();
let ceiling = 32;
let ceiling = 48;
assert!(
actual <= ceiling,
"size of oid shouldn't change without notice: {actual} <= {ceiling}"
Expand Down
4 changes: 2 additions & 2 deletions gix/tests/gix/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use gix_testtools::size_ok;
#[test]
fn object_ref_size_in_memory() {
let actual = std::mem::size_of::<gix::Object<'_>>();
let expected = 56;
let expected = 72;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand All @@ -17,7 +17,7 @@ fn object_ref_size_in_memory() {
#[test]
fn oid_size_in_memory() {
let actual = std::mem::size_of::<gix::Id<'_>>();
let expected = 32;
let expected = 48;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand Down
4 changes: 2 additions & 2 deletions gix/tests/gix/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod into_iter {
#[test]
fn item_size() {
let actual = std::mem::size_of::<Item>();
let expected = 264;
let expected = 320;
assert!(
size_ok(actual, expected),
"The size is the same as the one for the index-worktree-item: {actual} <~ {expected}"
Expand Down Expand Up @@ -303,7 +303,7 @@ mod index_worktree {
#[test]
fn item_size() {
let actual = std::mem::size_of::<Item>();
let expected = 264;
let expected = 320;
assert!(
size_ok(actual, expected),
"The size is pretty huge and goes down ideally: {actual} <~ {expected}"
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ check:
cargo check -p gix-features --features zlib
cargo check -p gix-features --features cache-efficiency-debug
cargo check -p gix-commitgraph --all-features
cargo check -p gix-commitgraph --features sha256
cargo check -p gix-config-value --all-features
cargo check -p gix-config --all-features
cargo check -p gix-diff --no-default-features
Expand Down Expand Up @@ -162,6 +163,8 @@ unit-tests:
cargo nextest run -p gix-hash --no-fail-fast
cargo nextest run -p gix-hash --features sha256 --no-fail-fast
cargo nextest run -p gix-hash --no-default-features --features sha256 --no-fail-fast # TODO: make this actually work by removing 'sha1' from default features.
env GIX_TEST_HASH=sha1 cargo nextest run -p gix-commitgraph --no-fail-fast
env GIX_TEST_HASH=sha256 cargo nextest run -p gix-commitgraph --no-fail-fast
cargo nextest run -p gix-object --no-fail-fast
cargo nextest run -p gix-object --features verbose-object-parsing-errors --no-fail-fast
cargo nextest run -p gix-tempfile --features signals --no-fail-fast
Expand Down
1 change: 1 addition & 0 deletions tests/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ default = []
xz = ["dep:xz2"]

[dependencies]
gix-hash = { version = "^0.22.0", path = "../../gix-hash" }
gix-lock = { version = "^21.0.0", path = "../../gix-lock" }
gix-discover = { version = "^0.46.0", path = "../../gix-discover" }
gix-worktree = { version = "^0.47.0", path = "../../gix-worktree" }
Expand Down
52 changes: 37 additions & 15 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ enum DirectoryRoot {
StandaloneTest,
}

/// Don't add a suffix to the archive name as `args` are platform dependent, none-deterministic,
/// Don't add a suffix to the archive name as `args` are platform dependent, non-deterministic,
/// or otherwise don't influence the content of the archive.
/// Note that this also means that `args` won't be used to control the hash of the archive itself.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -416,7 +416,7 @@ pub fn copy_recursively_into_existing_dir(src_dir: impl AsRef<Path>, dst_dir: im
Ok(())
}

/// Like `scripted_fixture_read_only()`], but passes `args` to `script_name`.
/// Like [`scripted_fixture_read_only()`], but passes `args` to `script_name`.
pub fn scripted_fixture_read_only_with_args(
script_name: impl AsRef<Path>,
args: impl IntoIterator<Item = impl Into<String>>,
Expand Down Expand Up @@ -470,14 +470,26 @@ fn scripted_fixture_read_only_with_args_inner(
gix_tempfile::signal::handler::Mode::DeleteTempfilesOnTerminationAndRestoreDefaultBehaviour,
);

let gix_test_hash = env::var_os("GIX_TEST_HASH")
.and_then(|os_string| os_string.into_string().ok())
.unwrap_or_default();
let hash_kind = gix_hash::Kind::from_str(&gix_test_hash).unwrap_or_default();

eprintln!("Using hash '{hash_kind}' when determining which fixture to use or recreate");

let script_location = script_name.as_ref();
let script_path = fixture_path_inner(script_location, root);

// keep this lock to assure we don't return unfinished directories for threaded callers
let args: Vec<String> = args.into_iter().map(Into::into).collect();
let script_identity = {
let mut map = SCRIPT_IDENTITY.lock();
map.entry(args.iter().fold(script_path.clone(), |p, a| p.join(a)))
let init = if hash_kind == gix_hash::Kind::Sha1 {
script_path.clone()
} else {
script_path.clone().join(hash_kind.to_string())
};
map.entry(args.iter().fold(init, |p, a| p.join(a)))
.or_insert_with(|| {
let crc_value = crc::Crc::<u32>::new(&crc::CRC_32_CKSUM);
let mut crc_digest = crc_value.digest();
Expand Down Expand Up @@ -509,8 +521,13 @@ fn scripted_fixture_read_only_with_args_inner(
}
ArgsInHash::No => "".into(),
};
let potential_hash_suffix = if hash_kind == gix_hash::Kind::Sha1 {
"".into()
} else {
format!("_{hash_kind}")
};
Path::new("generated-archives").join(format!(
"{}{suffix}.tar{}",
"{}{suffix}{potential_hash_suffix}.tar{}",
script_basename.to_str().expect("valid UTF-8"),
if cfg!(feature = "xz") { ".xz" } else { "" }
))
Expand All @@ -519,14 +536,12 @@ fn scripted_fixture_read_only_with_args_inner(
);
let (force_run, script_result_directory) = destination_dir.map_or_else(
|| {
let dir = fixture_path_inner(
Path::new("generated-do-not-edit").join(script_basename).join(format!(
"{}-{}",
script_identity,
family_name()
)),
root,
);
let mut path = Path::new("generated-do-not-edit").join(script_basename);
if hash_kind != gix_hash::Kind::Sha1 {
path = path.join(hash_kind.to_string());
}
path = path.join(format!("{}-{}", script_identity, family_name()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it would be more cluttered, I seem to prefer the idea of not nesting hash_kind, but add it to the format string here.

In future, there will be even more of these as another parameter, the one for the refs backend, is added.

Alternatively… what do you think about looking at both parameters and using them for nesting?

path.join(hash_kind).join(refs_kind)

The refs_kind is nothing that exists now, but it would be added at some point.

Yes, that seems like the way to go.

So let's make a mild breaking change and always add the hash_kind to the path via join.

let dir = fixture_path_inner(path, root);
(false, dir)
},
|d| (true, d.to_owned()),
Expand Down Expand Up @@ -588,13 +603,13 @@ fn scripted_fixture_read_only_with_args_inner(
}
let script_absolute_path = env::current_dir()?.join(script_path);
let mut cmd = std::process::Command::new(&script_absolute_path);
let output = match configure_command(&mut cmd, &args, &script_result_directory).output() {
let output = match configure_command(&mut cmd, hash_kind, &args, &script_result_directory).output() {
Ok(out) => out,
Err(err)
if err.kind() == std::io::ErrorKind::PermissionDenied || err.raw_os_error() == Some(193) /* windows */ =>
{
cmd = std::process::Command::new(bash_program());
configure_command(cmd.arg(script_absolute_path), &args, &script_result_directory).output()?
configure_command(cmd.arg(script_absolute_path), hash_kind, &args, &script_result_directory).output()?
}
Err(err) => return Err(err.into()),
};
Expand Down Expand Up @@ -625,6 +640,7 @@ const NULL_DEVICE: &str = "/dev/null";

fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
cmd: &'a mut std::process::Command,
hash_kind: gix_hash::Kind,
args: I,
script_result_directory: &Path,
) -> &'a mut std::process::Command {
Expand Down Expand Up @@ -664,6 +680,7 @@ fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
.env("GIT_CONFIG_VALUE_2", "main")
.env("GIT_CONFIG_KEY_3", "protocol.file.allow")
.env("GIT_CONFIG_VALUE_3", "always")
.env("GIT_DEFAULT_HASH", hash_kind.to_string())
}

/// Get the path attempted as a `bash` interpreter, for fixture scripts having no `#!` we can use.
Expand Down Expand Up @@ -1051,7 +1068,12 @@ mod tests {
let mut cmd = std::process::Command::new(GIT_PROGRAM);
cmd.env("GIT_CONFIG_SYSTEM", SCOPE_ENV_VALUE);
cmd.env("GIT_CONFIG_GLOBAL", SCOPE_ENV_VALUE);
configure_command(&mut cmd, ["config", "-l", "--show-origin"], temp.path());
configure_command(
&mut cmd,
gix_hash::Kind::Sha1,
["config", "-l", "--show-origin"],
temp.path(),
);

let output = cmd.output().expect("can run git");
let lines: Vec<_> = output
Expand Down
Loading