hashsig: retain replacement values in full heap by tasodoufu · Pull Request #7389 · libgit2/libgit2 · GitHub
Skip to content

hashsig: retain replacement values in full heap - #7389

Open
tasodoufu wants to merge 1 commit into
libgit2:mainfrom
tasodoufu:fix/hashsig-heap-replacement
Open

tasodoufu wants to merge 1 commit into
libgit2:mainfrom
tasodoufu:fix/hashsig-heap-replacement

Conversation

@tasodoufu

Copy link
Copy Markdown

Summary

Fix a replacement omission in the fixed-size hashsig heaps and add a regression test.

Reproduction

For an input with more than 127 runs, hashsig_heap_insert() takes the full-heap replacement path. Before this change, it decremented h->size, moved the last element to the root, and sifted down, but discarded the newly accepted val. This leaves the heap short and causes later values to be admitted unconditionally.

A regression test creates 600 distinct runs and compares the same runs in forward and reverse order. Since the signature is order-independent, the expected similarity is 100. Before this change, the test reported 49.

Cause

The full-heap path evicted the root without storing the replacement value.

Fix

Store val at the root and sift it down without changing the heap size.

Impact

Large signatures now retain the intended 127 extrema. Similarity and rename-detection results no longer depend on the order in which runs arrive because of the dropped replacement values.

Validation

  • Regression test before fix: failed, similarity 49 instead of 100.
  • Targeted core::hashsig suite after fix: 3/3 passed.
  • git diff --check: passed.
  • Full ctest --test-dir build --output-on-failure: 67% passed (8/12 CTest groups). The four failing groups were environment/configuration-related: the build had no TLS backend, and the existing offline fixture reported a missing object plus an unrelated git_diff_options initializer mismatch. The changed hashsig suite passed.

Unverified

I did not run the online tests with a TLS backend configured.

Fixes #7375

Assisted-by: OpenClaw (opencode-go/gpt-5.6-luna)

This branch has not been deployed

No deployments
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.

hashsig: the similarity heap evicts but never inserts, so the retained set is not the extremes

1 participant