Skip to content

Add hex_to_id_sha1_only, use in SHA-1 only tests#2595

Merged
Sebastian Thiel (Byron) merged 4 commits into
GitoxideLabs:mainfrom
cruessler:add-hex-to-id-sha1-only
May 12, 2026
Merged

Add hex_to_id_sha1_only, use in SHA-1 only tests#2595
Sebastian Thiel (Byron) merged 4 commits into
GitoxideLabs:mainfrom
cruessler:add-hex-to-id-sha1-only

Conversation

@cruessler
Copy link
Copy Markdown
Contributor

This is a follow-up to #2578. There’s some tests in gix/tests that are SHA-1 only in that they contain hard-coded SHA-1 hashes and don’t have a corresponding version for SHA-256 hashes. They still share the same hex_to_id function that returns a SHA-1 or SHA-256 hash, based on gix_testtools::object_hash. The behaviour of hex_to_id diverges from other instances of hex_to_id in other crates: in gix/tests, hex_to_id silently returns the SHA-1 has that was passed in when there’s no SHA-256 hash in the mapping while in other crates it is a hard error when the SHA-1 hash can’t be found in the mapping. This PR introduces a separate hex_to_id_sha1_only that keeps the fallback behaviour, so that hex_to_id can be changed to mirror hex_to_id in other crates.

@cruessler Christoph Rüßler (cruessler) marked this pull request as ready for review May 12, 2026 20:30
Copilot AI review requested due to automatic review settings May 12, 2026 20:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines SHA-1 vs SHA-256 handling in the gix integration tests by separating “hash mapping aware” ID conversion from “SHA-1 literal” ID conversion, preparing gix/tests for stricter SHA-256 fixture runs.

Changes:

  • Tighten hex_to_id() so SHA-256 fixture mode requires a SHA-1→SHA-256 mapping entry (no silent fallback).
  • Add hex_to_id_sha1_only() for tests that intentionally hard-code SHA-1 object IDs.
  • Update SHA-1-only revision-spec and repository tests to use hex_to_id_sha1_only().

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gix/tests/gix/util.rs Makes hex_to_id() strict in SHA-256 mode and adds hex_to_id_sha1_only() for SHA-1-only tests.
gix/tests/gix/revision/spec/from_bytes/traverse.rs Switches expected IDs to hex_to_id_sha1_only() in SHA-1-only traversal assertions.
gix/tests/gix/revision/spec/from_bytes/regex.rs Uses hex_to_id_sha1_only() for SHA-1-only regex revspec expectations.
gix/tests/gix/revision/spec/from_bytes/reflog.rs Uses hex_to_id_sha1_only() for reflog-based SHA-1-only expectations.
gix/tests/gix/revision/spec/from_bytes/peel.rs Uses hex_to_id_sha1_only() for peel tests with hard-coded SHA-1 IDs.
gix/tests/gix/revision/spec/from_bytes/mod.rs Updates module-level imports/usages to prefer hex_to_id_sha1_only() where appropriate.
gix/tests/gix/revision/spec/from_bytes/ambiguous.rs Moves hard-coded SHA-1 expectations to hex_to_id_sha1_only().
gix/tests/gix/repository/mod.rs Updates SHA-1-only revision parsing expectations to hex_to_id_sha1_only().

Comment thread gix/tests/gix/util.rs
Comment thread gix/tests/gix/util.rs Outdated
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d80c534f85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread gix/tests/gix/util.rs Outdated
Copy link
Copy Markdown
Member

@Byron Sebastian Thiel (Byron) left a comment

Choose a reason for hiding this comment

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

Thanks a lot, much appreciated!

Comment thread gix/tests/gix/util.rs
Comment thread gix/tests/gix/util.rs Outdated
Comment thread gix/tests/gix/util.rs Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 22:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

gix/tests/gix/util.rs:173

  • hex_to_id_sha1_only() is documented/named as “SHA-1 only”, but it currently just forwards to ObjectId::from_hex(), which will also accept 64-hex inputs and yield a SHA-256 id. If this helper is meant to enforce SHA-1, consider asserting hex.len() == 40 (and adjusting the expect message to “40 hex chars” rather than “40 bytes”).
/// Convert a hexadecimal hash into its corresponding `ObjectId` or _panic_.
///
/// This does *not* take `GIX_TEST_FIXTURE_HASH` into account, so it does not map SHA-1 hashes to
/// SHA-256 hashes. Use this for tests that don't need a mapping.
pub fn hex_to_id_sha1_only(hex: &str) -> gix_hash::ObjectId {
    gix_hash::ObjectId::from_hex(hex.as_bytes()).expect("40 bytes hex")
}

Comment thread gix/tests/gix/util.rs
Comment thread gix/tests/gix/util.rs
@Byron Sebastian Thiel (Byron) merged commit 87433ed into GitoxideLabs:main May 12, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants