Thanks to visit codestin.com
Credit goes to github.com

Skip to content

diff: make git_diff_from_buffer diffs show binary data when printed. #7051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timonvo
Copy link

@timonvo timonvo commented Mar 16, 2025

This change sets the GIT_DIFF_SHOW_BINARY flag on all git_diff
structs created using git_diff_from_buffer. This ensures that when the
diff is printed (e.g. with git_diff_print or git_diff_to_buf) all
binary data patches in the diff are actually printed out.

Before this change printing a diff created from a patch file using
git_diff_from_buffer would result in binary data patches not being
included in the output. Instead, a "Binary files A and B differ" message
would be included in the printed patch, even if the original patch did
include a "GIT binary patch". This meant that you couldn't actually
round-trip such diffs, going from patch file to git_diff to patch
file.

Note that this change is consistent with how that same flag is already
set on all git_patch structs created using git_patch_parse (which
git_diff_from_buffer calls to populate the git_diff, and which
git_patch_from_buffer also calls).

This change sets the `GIT_DIFF_SHOW_BINARY` flag on all `git_diff`
structs created using `git_diff_from_buffer`. This ensures that when the
diff is printed (e.g. with `git_diff_print` or `git_diff_to_buf`) all
binary data patches in the diff are actually printed out.

Before this change printing a diff created from a patch file using
`git_diff_from_buffer` would result in binary data patches not being
included in the output. Instead, a "Binary files A and B differ" message
would be included in the printed patch, even if the original patch did
include a "GIT binary patch". This meant that you couldn't actually
round-trip such diffs, going from patch file to `git_diff` to patch
file.

Note that this change is consistent with how that same flag is already
set on all `git_patch` structs created using `git_patch_parse` (which
`git_diff_from_buffer` calls to populate the `git_diff`, and which
`git_patch_from_buffer` also calls).
timonvo added a commit to timonvo/git2-rs that referenced this pull request Mar 16, 2025
…8d20.

This fixes patch file -> diff -> patch file round tripping when binary
data is included. See libgit2/libgit2#7051.
timonvo added a commit to timonvo/git2-rs that referenced this pull request Mar 16, 2025
…8d20.

This fixes patch file -> diff -> patch file round tripping when binary
data is included. See libgit2/libgit2#7051.
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.

1 participant