Skip to content

diff: report real progress in git_diff_file_cb - #7340

Open
atom2ueki wants to merge 4 commits into
libgit2:mainfrom
atom2ueki:fix/diff-file-cb-progress
Open

diff: report real progress in git_diff_file_cb#7340
atom2ueki wants to merge 4 commits into
libgit2:mainfrom
atom2ueki:fix/diff-file-cb-progress

Conversation

@atom2ueki

Copy link
Copy Markdown

Description

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"`.

This fix computes a real progress value: (float)idx / (float)git_diff_num_deltas(diff) when iterating via git_diff_foreach. Single-patch APIs (git_patch_print, git_patch_to_buf) still pass 0 since they have no multi-file context.

Changes

File Change
src/libgit2/patch.h Add float progress param to internal git_patch__invoke_callbacks declaration
src/libgit2/patch.c Accept and forward progress to file_cb instead of hard-coded 0
src/libgit2/diff.c Compute progress = idx / num_deltas in git_diff_foreach
src/libgit2/diff_print.c Update 2 call sites of git_patch__invoke_callbacks (pass 0)
tests/libgit2/diff/diffiter.c Add test_diff_diffiter__iterate_files_progress test
docs/changelog.md Add bug-fix entry

Notes

  • Public API (git_diff_file_cb typedef) is unchanged — it already has float progress.
  • ABI is unchanged — no public structs or function signatures were modified.
  • The formula idx / num_deltas matches the existing test helper diff_foreach_via_iterator in diff_helpers.c.

Fixes #5671

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.
Comment thread docs/changelog.md Outdated
Remove the changelog addition; maintainers generate the changelog at
release time.
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.

git_diff_file_cb progress always 0

2 participants