diff: report an xdiff failure instead of an empty diff by cristianchiriac · Pull Request #7424 · libgit2/libgit2 · GitHub
Skip to content

diff: report an xdiff failure instead of an empty diff - #7424

Open
cristianchiriac wants to merge 2 commits into
libgit2:mainfrom
cristianchiriac:xdiff-report-failure
Open

cristianchiriac wants to merge 2 commits into
libgit2:mainfrom
cristianchiriac:xdiff-report-failure

Conversation

@cristianchiriac

Copy link
Copy Markdown

Fixes #7420.

git_xdiff discarded the return value of xdl_diff and returned only xo->output.error, which only the hunk and line callbacks set. When xdiff fails (out of memory while preparing the environment or building the edit script), it fails before any callback runs, so git_patch_from_buffers and the other text diff users (patch, diff, blame, merge) reported success with no hunks. A failure from xdl_diff now sets the output error when the callbacks didn't already. The allocation that failed has already set the out-of-memory error through git__malloc.

Test: diff::oom::patch_from_buffers_fails_or_has_the_hunk installs an allocator that fails the Nth allocation and runs git_patch_from_buffers on a one-line change for every N, until it needs no more allocations. Each run must either fail or produce its one hunk.

  • before: 1 != 0 (success reported with no hunks)
  • after: passes

-sdiff -sblame -smerge -sapply -spatch: 617 tests pass (MinGW gcc 16, Windows 11).

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
patch_generated_from_sources set the patch's free function only once
the file contents were loaded, so an earlier failure (such as running
out of memory while normalizing the options) left git_patch_free unable
to free the patch. Set it first.

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.

[BUG] git_xdiff ignores xdl_diff errors and returns an empty diff

1 participant