diff: report real progress in git_diff_file_cb - #7340
Open
atom2ueki wants to merge 4 commits into
Open
Conversation
The progress parameter of git_diff_file_cb was always hard-coded to 0 in git_patch__invoke_callbacks, despite the documentation stating it "Goes from 0 to 1 over the diff". Pass the current delta index / total deltas as progress when iterating via git_diff_foreach. Single-patch APIs (git_patch_print) still report 0 since they have no multi-file context. Fixes libgit2#5671
Remove the unused 'd' variable in test_diff_diffiter__iterate_files_progress; it iterated via git_diff_foreach instead of a manual loop, triggering -Werror=unused-variable.
Restore the leading tab in git_patch_print's invoke_callbacks call and the trailing newline at the end of diffiter.c to avoid -Wmisleading-indentation and style warnings.
ethomson
requested changes
Aug 12, 2026
Remove the changelog addition; maintainers generate the changelog at release time.
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.
Description
The
progressparameter ofgit_diff_file_cbwas always hard-coded to0ingit_patch__invoke_callbacks, despite the documentation stating it *"Goes from 0 to 1 over the diff"`.This fix computes a real progress value:
(float)idx / (float)git_diff_num_deltas(diff)when iterating viagit_diff_foreach. Single-patch APIs (git_patch_print,git_patch_to_buf) still pass0since they have no multi-file context.Changes
src/libgit2/patch.hfloat progressparam to internalgit_patch__invoke_callbacksdeclarationsrc/libgit2/patch.cprogresstofile_cbinstead of hard-coded0src/libgit2/diff.cprogress = idx / num_deltasingit_diff_foreachsrc/libgit2/diff_print.cgit_patch__invoke_callbacks(pass0)tests/libgit2/diff/diffiter.ctest_diff_diffiter__iterate_files_progresstestdocs/changelog.mdNotes
git_diff_file_cbtypedef) is unchanged — it already hasfloat progress.idx / num_deltasmatches the existing test helperdiff_foreach_via_iteratorindiff_helpers.c.Fixes #5671