Repository navigation
blame: report a failure in git_blame_buffer - #7425
Open
cristianchiriac wants to merge 2 commits into
Open
cristianchiriac wants to merge 2 commits into
cristianchiriac wants to merge 2 commits into
Conversation
git_xdiff ignored the return value of xdl_diff and returned only the error recorded by the hunk and line callbacks. When xdiff fails, for example out of memory while preparing the diff, it does so before any callback runs, so git_patch_from_buffers and the other text diff users reported success with no hunks. Fixes libgit2#7420
git_blame_buffer ignored the result of git_diff_blob_to_buffer and returned success unconditionally, so a failed diff gave a blame whose hunks did not reflect the buffer. Return the error and free the partial blame. The hunk callbacks and split_hunk_in_vector also ignored a failed vector insert, which dropped a hunk silently; report those failures too, and free the blame when duplicating the reference hunks fails. Fixes libgit2#7418
This was referenced Oct 15, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7418. Builds on #7424, which is the first commit here. Without it, xdiff's own failures still look like success to the blame. I'll rebase once #7424 is merged, or I can fold both into one PR if you prefer.
git_blame_bufferignored the result ofgit_diff_blob_to_bufferand returned 0, so a failed diff gave the caller a blame whose hunks didn't reflect the buffer. Making all of an allocation-failure sweep pass turned up three more places that drop a failure the same way:git_blame_buffer: return the diff's error and free the partial blame. When duplicating a reference hunk or inserting it fails, also free the blame, which leaked before.buffer_hunk_cb/buffer_line_cb: the result ofgit_vector_insert/git_vector_insert_sortedwas ignored, so a hunk could be dropped silently. They now free the hunk and return -1, which aborts the diff with the error.split_hunk_in_vector: the original hunk was shortened before an insert whose result was ignored, losing its lines when the insert failed. It now inserts first and returns NULL on failure, which the only caller (buffer_hunk_cb) already reports.Test:
blame::oom::buffer_fails_or_has_every_hunkblames a buffer with one changed line againstblametest.git/b.txt. It does this with an allocator that fails the Nth allocation, for every N, until no allocation fails. Each run must either fail or return the same number of hunks as the blame made without failures.3 != 4-sblame -sdiff -smerge -sapply -spatch: 617 tests pass (MinGW gcc 16, Windows 11).