feat(binary): add git binary patch support#33
Merged
weihanglo merged 10 commits intogit-format-patchfrom Feb 2, 2026
Merged
Conversation
4c61cc9 to
366461f
Compare
The API was stabilized in 1.73. The lint was added in 1.93.
* `Binary files a/path and b/path differ` (`git diff` without `--binary` flag) * `GIT binary patch` (from `git diff --binary`)
This makes diffy more transparent to users: diffy parses all, users decide later.
This is a preparation for binary diff application support. * Git binary patch is compressed by zlib hence flate2 * zlib-rs (which is the most performant zlib backend) requires MSRF 1.75.0+ hence the bump.
See <https://diffx.org/spec/binary-diffs.html#git-delta-binary-diffs> Specifically, this part of the example code: ```python orig_data: bytes = b'<file data>' modified_data: bytes = b'<file data>' result = io.Bytes() for (mode, modified_offset, modified_hunk, modified_size) in calc_hunks(orig_data, modified_data): if mode == ADD: assert 1 <= modified_size <= 127 result.write(bytes([modified_size, *modified_hunk])) elif mode == COPY: control = 0x80 args = bytearray() for shift, mask in zip((0, 8, 16, 24), (0x01, 0x02, 0x04, 0x08)): value = (modified_offset >> shift) & 0xFF if value: control |= mask args.append(value) for shift, mask in zip((0, 8, 16), (0x10, 0x20, 0x40)): value = (modified_size >> shift) & 0xFF if value: control |= mask args.append(value) result.write(bytes([control, *args])) ```
This wires up all the previous commits and expose `BinaryPatch::apply()` to users to apply Git binary patch. While binary patch application is behind the `binary` feature, parsing is done regardlessly, so the changed file count in diffy and in git should be mostly the same except submodule.
366461f to
5f59181
Compare
24 tasks
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.
Add parsing and application of git binary patches,
including both literal and delta formats.
This feature is behind the
binaryCargo feature.The implementation is based on
Some others highlights:
binaryfeature.