Skip to content

Commit 228caf7

Browse files
authored
Merge pull request #2377 from cruessler/add-sha-256-to-gix-commitgraph
Add GIX_TEST_FIXTURE_HASH to gix-testtools
2 parents 90065cd + 8ccd760 commit 228caf7

34 files changed

Lines changed: 160 additions & 45 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-commitgraph/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ document-features = { version = "0.2.0", optional = true }
3333
[dev-dependencies]
3434
gix-testtools = { path = "../tests/tools" }
3535
gix-date = { path = "../gix-date" }
36+
gix-hash = { path = "../gix-hash", features = ["sha256"] }
3637

3738
[package.metadata.docs.rs]
3839
all-features = true

gix-commitgraph/src/access.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ impl Graph {
1111
r.file.commit_at(r.pos)
1212
}
1313

14+
/// The kind of hash used in this `Graph`.
15+
///
16+
/// Note that it is always conforming to the hash used in the owning repository.
17+
///
18+
/// # Panics
19+
///
20+
/// If the graph does not contain any `File`.
21+
pub fn object_hash(&self) -> gix_hash::Kind {
22+
self.files
23+
.first()
24+
.map(super::File::object_hash)
25+
.expect("graph to have at least one file")
26+
}
27+
1428
/// Returns the commit matching the given `id`.
1529
pub fn commit_by_id(&self, id: impl AsRef<gix_hash::oid>) -> Option<Commit<'_>> {
1630
let r = self.lookup_by_id(id.as_ref())?;

gix-commitgraph/tests/commitgraph.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ pub fn graph_and_expected_named(
8181
let expected = inspect_refs(&repo_dir, refs);
8282
let cg =
8383
Graph::from_info_dir(&repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid");
84+
let object_hash = cg.object_hash();
85+
let any_ref = expected.values().next().expect("at least one ref");
86+
assert_eq!(
87+
object_hash,
88+
any_ref.id().kind(),
89+
"graph hash kind should match fixture object IDs"
90+
);
91+
8492
(cg, expected)
8593
}
8694

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)