Skip to content

feat: compare fundamental types with textual representations - #2932

Draft
Sebastian Thiel (Byron) wants to merge 6 commits into
mainfrom
fundamental-types-comp
Draft

feat: compare fundamental types with textual representations#2932
Sebastian Thiel (Byron) wants to merge 6 commits into
mainfrom
fundamental-types-comp

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Aug 20, 2026

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew

Everything below this line was generated by Codex GPT-5.

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Reported issue

Initial report

$issue-full-auto Let fundamental types like `gix-ref::FullName*`, and `gix-object::ObjectId` compare directly to their natural counterparts, particularly for testing. All they do is to compare their internal representation, or their typical representation (like they hex/reverse hex value). This shuold also be implemenated for their connected types.

Follow-up

> - gix: make repository-attached Id delegate textual equality to its ObjectId.

The `Reference` type is missing, even though it (and related types maybe) shouldn't.

Also have a separate commit for actually making use of these new comparisons in the test suite everywhere.

Summary

  • Add direct comparisons between hash IDs and canonical lowercase hexadecimal text.
  • Add comparisons between reference names/references and their byte or string representations.
  • Add repository-attached gix::Id and gix::Reference comparisons.
  • Preserve PartialEq symmetry and transitivity by limiting prefix, truncated, and reference comparisons to law-preserving directions.
  • Adopt the new comparisons throughout the test suite in a separate commit.

Commits

  • 77f28a89d9 feat(gix-hash): compare hash types with text
  • 24b200e878 feat(gix-ref): compare names and references with natural counterparts
  • a3c1c8d355 Preserve PartialEq transitivity for reference comparisons
  • 60aa0c806b Preserve PartialEq laws for hash text comparisons
  • 5e83f39167 feat(gix): compare attached IDs and references with text
  • d1c3e249d7 Use fundamental-type comparisons throughout tests

Validation

  • Focused gix-ref, gix, hash-crate, and gix-object tag-target tests.
  • Formatting, diff checks, cargo-machete, and all local clippy configurations.
  • cargo deny --workspace --all-features check bans licenses sources.
  • env GIX_TEST_IGNORE_ARCHIVES=1 just ci-test.
  • just doc-tests.
  • env GIX_TEST_CREATE_ARCHIVES_EVEN_ON_CI=1 cargo nextest run --workspace --no-fail-fast --exclude gix-error (3,710 passed, one existing leaky annotation, five configured skips).
  • just ci-journey-tests.

Allow ObjectId, oid, ChangeId, Prefix, and their display helpers to compare directly and symmetrically with str and String values. Comparisons reuse the existing stack encoders and accept parser-supported uppercase without allocating.

Regression coverage first demonstrated the missing PartialEq implementations as compile errors, then covered SHA-1, SHA-256, normal hex, reverse hex, prefixes, invalid text, and both operand orders.

Validation:
- cargo test -p gix-hash --all-features --test hash
- cargo clippy -p gix-hash --all-features --tests -- -D warnings
- cargo check -p gix-hash --no-default-features --features sha1
- cargo check -p gix-hash --no-default-features --features sha256
- cargo fmt --all -- --check
Allow owned and borrowed reference-name types, namespaces, and raw, loose, and packed references to compare directly with text and byte strings. Reference comparisons project their stored full name, while same-type equality remains structural.\n\nAdd regression coverage for symmetric owned, borrowed, UTF-8, and non-UTF-8 comparisons.\n\nValidation: cargo test -p gix-ref --test refs equality --all-features; cargo fmt --all -- --check
Keep name-only comparisons directional with references on the left. This preserves direct test-friendly comparisons without allowing two structurally distinct references to compare transitively through the same textual or FullName value.\n\nValidation: cargo test -p gix-ref --test refs equality --all-features; cargo fmt --all -- --check
Compare full object and change IDs only with their canonical lowercase text. Keep Prefix, HexDisplay, and ReverseHexDisplay comparisons directional because their displayed text does not uniquely identify their structural value.\n\nThis prevents non-transitive equality chains through differently-cased strings, truncated displays, and cross-kind prefixes.\n\nValidation: cargo test -p gix-hash --test hash comparisons --all-features; cargo clippy -p gix-hash --all-targets --all-features -- -D warnings; SHA-1 and SHA-256 library checks; cargo fmt --all -- --check
Delegate attached Id textual equality to ObjectId, preserving symmetric canonical comparisons. Let attached references compare directly with text, byte strings, and full names by delegating to their stored plumbing reference.\n\nReference comparisons remain directional because same-name references may have different targets.\n\nValidation: GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix compares_with_; cargo clippy -p gix --test gix -- -D warnings; cargo fmt --all -- --check
Replace test-only parsing, formatting, and name projections with direct comparisons against natural textual representations. This exercises hash IDs, ref names, plumbing references, and repository-attached IDs and references through the new equality implementations.

Validated with the gix-ref and gix integration suites, focused hash migration tests, cargo fmt, and diff checks.
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.

2 participants