Skip to content
Merged
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.

1 change: 1 addition & 0 deletions gix-commitgraph/Cargo.toml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What surprises me is that there is no way to check what hash format the graph is using. Could we have an implementation of object_hash (which exists on File) for the Graph, and assert on the value.
But then we'd need a way to get the currently set hash, which had to come from gix-testtools.
I think this would be very useful to have and some assertion should definitely be made.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are you thinking about something like the following:

/// The kind of hash used in this `Graph`.
///
/// Note that it is always conforming to the hash used in the owning repository.
///
/// # Panics
///
/// If the graph does not contain any `File`.
pub fn object_hash(&self) -> gix_hash::Kind {
    self.files
        .first()
        .map(super::File::object_hash)
        .expect("graph to have at least one file")
}

Copy link
Copy Markdown
Member

@Byron Sebastian Thiel (Byron) Feb 7, 2026

Choose a reason for hiding this comment

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

Are you interested in a follow-up? There is the nonempty crate which I think would do wonders here (and in other places).

But besides that, yes, this is what I imagined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! I’ll have a look at nonempty. I assume we want to wrap self.files? Or are you thinking about a more local use just in object_hash?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ve now added Graph::object_hash.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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
14 changes: 14 additions & 0 deletions gix-commitgraph/src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ impl Graph {
r.file.commit_at(r.pos)
}

/// The kind of hash used in this `Graph`.
///
/// Note that it is always conforming to the hash used in the owning repository.
///
/// # Panics
///
/// If the graph does not contain any `File`.
pub fn object_hash(&self) -> gix_hash::Kind {
self.files
.first()
.map(super::File::object_hash)
.expect("graph to have at least one file")
}

/// Returns the commit matching the given `id`.
pub fn commit_by_id(&self, id: impl AsRef<gix_hash::oid>) -> Option<Commit<'_>> {
let r = self.lookup_by_id(id.as_ref())?;
Expand Down
8 changes: 8 additions & 0 deletions gix-commitgraph/tests/commitgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pub fn graph_and_expected_named(
let expected = inspect_refs(&repo_dir, refs);
let cg =
Graph::from_info_dir(&repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid");
let object_hash = cg.object_hash();
let any_ref = expected.values().next().expect("at least one ref");
assert_eq!(
object_hash,
any_ref.id().kind(),
"graph hash kind should match fixture object IDs"
);

(cg, expected)
}

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.
7 changes: 5 additions & 2 deletions gix-diff/src/tree/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ mod tests {
#[test]
fn size_of_change() {
let actual = std::mem::size_of::<Change>();
let sha1 = 48;
let sha256_extra = 24;
let ceiling = sha1 + sha256_extra;
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"
);
}
}
4 changes: 3 additions & 1 deletion gix-index/src/extension/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ mod tests {
#[test]
fn size_of_tree() {
let actual = std::mem::size_of::<crate::extension::Tree>();
let expected = 88;
let sha1 = 88;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ gix-features = { path = "../../gix-features", features = ["progress"] }
gix-testtools = { path = "../../tests/tools" }
gix-odb = { path = "../../gix-odb" }
gix-object = { path = "../../gix-object" }
gix-hash = { path = "../../gix-hash" }
gix-hash = { path = "../../gix-hash", features = ["sha256"] }
filetime = "0.2.27"
bstr = { version = "1.12.0", default-features = false }
4 changes: 3 additions & 1 deletion gix-index/tests/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ 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 sha1 = 80;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand Down
4 changes: 3 additions & 1 deletion gix-negotiate/tests/negotiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ mod baseline;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<gix_revwalk::graph::Commit<gix_negotiate::Metadata>>();
let expected = 56;
let sha1 = 56;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"we may keep a lot of these, so let's not let them grow unnoticed: {actual} <~ {expected}"
Expand Down
7 changes: 5 additions & 2 deletions gix-object/tests/object/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ fn fixture_name(kind: &str, path: &str) -> Vec<u8> {
#[test]
fn size_in_memory() {
let actual = std::mem::size_of::<gix_object::Object>();
let sha1 = 272;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
assert!(
actual <= 272,
"{actual} <= 272: Prevent unexpected growth of what should be lightweight objects"
actual <= expected,
"{actual} <= {expected}: Prevent unexpected growth of what should be lightweight objects"
);
}

Expand Down
1 change: 1 addition & 0 deletions gix-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ gix-tempfile = { version = "^21.0.0", default-features = false, path = "../gix-t

[dev-dependencies]
gix-testtools = { path = "../tests/tools" }
gix-hash = { version = "^0.22.0", path = "../gix-hash", features = ["sha256"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 3 additions & 1 deletion gix-pack/src/cache/delta/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ mod tests {
}

let actual = std::mem::size_of::<[Item<EntryWithDefault>; 7_500_000]>();
let expected = 840_000_000;
let sha1 = 840_000_000;
let sha256_extra = 120_000_000;
let expected = sha1 + sha256_extra;
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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "0.0.0"
repository = "https://github.com/GitoxideLabs/gitoxide"
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
license = "MIT OR Apache-2.0"
description = "Please use `gix-<thiscrate>` instead ('git' -> 'gix')"
description = "Tests for the gix-pack crate"
edition = "2021"
rust-version = "1.82"

Expand All @@ -27,5 +27,5 @@ bstr = { version = "1.12.0", default-features = false, features = ["std"] }
maplit = "1.0.2"
gix-object = { path = "../../gix-object" }
gix-traverse = { path = "../../gix-traverse" }
gix-hash = { path = "../../gix-hash" }
gix-hash = { path = "../../gix-hash", features = ["sha256"] }
memmap2 = "0.9.7"
8 changes: 6 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,9 @@ use gix_testtools::size_ok;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<output::Entry>();
let expected = 80;
let sha1 = 80;
let sha256_extra = 32;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"The size of the structure shouldn't change unexpectedly: {actual} <~ {expected}"
Expand All @@ -16,7 +18,9 @@ fn size_of_entry() {
#[test]
fn size_of_count() {
let actual = std::mem::size_of::<output::Count>();
let expected = 56;
let sha1 = 56;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"The size of the structure shouldn't change unexpectedly: {actual} <~ {expected}"
Expand Down
4 changes: 3 additions & 1 deletion gix-pack/tests/pack/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use gix_testtools::size_ok;
#[test]
fn size_of_entry() {
let actual = std::mem::size_of::<pack::data::input::Entry>();
let expected = 104;
let sha1 = 104;
let sha256_extra = 32;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"let's keep the size in check as we have many of them: {actual} <~ {expected}"
Expand Down
4 changes: 3 additions & 1 deletion gix-ref/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ mod tests {
#[test]
fn size_of_reference() {
let actual = std::mem::size_of::<Reference>();
let expected = 80;
let sha1 = 80;
let sha256_extra = 24;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"let's not let it change size undetected: {actual} <~ {expected}"
Expand Down
4 changes: 3 additions & 1 deletion gix-revwalk/tests/revwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ mod graph {
#[test]
fn size_of_commit() {
let actual = std::mem::size_of::<gix_revwalk::graph::Commit<()>>();
let expected = 48;
let sha1 = 48;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
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-worktree-state/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gix-object = { path = "../../gix-object" }
gix-discover = { path = "../../gix-discover" }
gix-filter = { path = "../../gix-filter" }
gix-index = { path = "../../gix-index" }
gix-hash = { path = "../../gix-hash" }
gix-hash = { path = "../../gix-hash", features = ["sha256"] }
gix-fs = { path = "../../gix-fs" }
gix-features = { path = "../../gix-features" }
gix-testtools = { path = "../../tests/tools" }
Expand Down
2 changes: 1 addition & 1 deletion gix-worktree/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gix-features-parallel = ["gix-features/parallel"]
gix-worktree = { path = "..", features = ["attributes"] }
gix-index = { path = "../../gix-index" }
gix-fs = { path = "../../gix-fs" }
gix-hash = { path = "../../gix-hash" }
gix-hash = { path = "../../gix-hash", features = ["sha256"] }
gix-object = { path = "../../gix-object" }
gix-glob = { path = "../../gix-glob" }
gix-path = { path = "../../gix-path" }
Expand Down
1 change: 1 addition & 0 deletions gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ document-features = { version = "0.2.0", optional = true }
gix = { path = ".", default-features = false, features = [
"need-more-recent-msrv", "tree-error"
] }
gix-hash = { version = "^0.22.0", path = "../gix-hash", features = ["sha256"] }
pretty_assertions = "1.4.0"
gix-testtools = { path = "../tests/tools" }
is_ci = "1.1.1"
Expand Down
4 changes: 3 additions & 1 deletion gix/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ mod tests {
#[test]
fn size_of_oid() {
let actual = std::mem::size_of::<Id<'_>>();
let ceiling = 32;
let sha1 = 32;
let sha256_extra = 16;
let ceiling = sha1 + sha256_extra;
assert!(
actual <= ceiling,
"size of oid shouldn't change without notice: {actual} <= {ceiling}"
Expand Down
8 changes: 6 additions & 2 deletions gix/tests/gix/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use gix_testtools::size_ok;
#[test]
fn object_ref_size_in_memory() {
let actual = std::mem::size_of::<gix::Object<'_>>();
let expected = 56;
let sha1 = 56;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"the size of this structure should not change unexpectedly: {actual} <~ {expected}"
Expand All @@ -17,7 +19,9 @@ fn object_ref_size_in_memory() {
#[test]
fn oid_size_in_memory() {
let actual = std::mem::size_of::<gix::Id<'_>>();
let expected = 32;
let sha1 = 32;
let sha256_extra = 16;
let expected = sha1 + sha256_extra;
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/tests/gix/revision/spec/from_bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn bad_objects_are_valid_until_they_are_actually_read_from_the_odb() {
|
└─ An error occurred while obtaining an object from the loose object store
|
└─ decompression of loose object at 'tests/fixtures/generated-do-not-edit/make_rev_spec_parse_repos/2990428670-unix/blob.corrupt/objects/ca/fea31147e840161a1860c50af999917ae1536b' failed
└─ decompression of loose object at 'tests/fixtures/generated-do-not-edit/make_rev_spec_parse_repos/sha1/2990428670-unix/blob.corrupt/objects/ca/fea31147e840161a1860c50af999917ae1536b' failed
|
└─ Could not decode zip stream, status was 'Invalid input data'
|
Expand Down
8 changes: 6 additions & 2 deletions gix/tests/gix/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ mod into_iter {
#[test]
fn item_size() {
let actual = std::mem::size_of::<Item>();
let expected = 264;
let sha1 = 264;
let sha256_extra = 56;
let expected = sha1 + sha256_extra;
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 +305,9 @@ mod index_worktree {
#[test]
fn item_size() {
let actual = std::mem::size_of::<Item>();
let expected = 264;
let sha1 = 264;
let sha256_extra = 56;
let expected = sha1 + sha256_extra;
assert!(
size_ok(actual, expected),
"The size is pretty huge and goes down ideally: {actual} <~ {expected}"
Expand Down
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,17 @@ 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_FIXTURE_HASH=sha1 cargo nextest run -p gix-commitgraph --no-fail-fast
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-commitgraph --no-fail-fast
Comment on lines +165 to +166
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Christoph Rüßler (@cruessler) I have removed the other usages of gix-commitgraph as they just seemed to set the hash to SHA1 which doesn't seem necessary or effective anymore.

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
cargo nextest run -p gix-features --all-features --no-fail-fast
cargo nextest run -p gix-ref-tests --all-features --no-fail-fast
cargo nextest run -p gix-odb --all-features --no-fail-fast
cargo nextest run -p gix-odb-tests --features gix-features-parallel --no-fail-fast
cargo nextest run -p gix-pack --all-features --no-fail-fast
env GIX_TEST_FIXTURE_HASH=sha1 cargo nextest run -p gix-pack --all-features --no-fail-fast
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-pack --all-features --no-fail-fast
cargo nextest run -p gix-pack-tests --features all-features --no-fail-fast
cargo nextest run -p gix-pack-tests --features gix-features-parallel --no-fail-fast
cargo nextest run -p gix-index-tests --features gix-features-parallel --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
Loading
Loading