Repository navigation
feat: show a picture's old and new version next to each other in its diff - #53
Merged
Merged
Conversation
Merged
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.
What this changes
A changed picture used to show only "Binary file". Now a PNG, JPEG, GIF, WebP, BMP or ICO shows its old version on the left and its new one on the right, each with its size in pixels and in bytes (for example
Old · 256 × 256 · 11.1 KB). A picture is shown as large as it is, or smaller when it does not fit. A new file hasnoneon the left, a deleted one on the right, and a version that cannot be decoded says why. This works in the uncommitted changes (unstaged, staged, untracked), in a commit and under a file's history, and the pictures follow changes made outside while the diff is open.The two versions are read with gitoxide (
Repo::versions: the index,HEAD, a commit and its first parent, or the working tree) and decoded on a background thread, so a large picture never holds up the window. Decoding uses theimagecrate, which eframe already depends on for PNG; this enables its JPEG, GIF, WebP, BMP and ICO decoders. A picture larger than the largest texture is scaled down for display; its real size is still shown.This is part 3 of "Better diffs" on the roadmap; syntax colouring becomes part 4.
How it is tested
A core test reads both versions for every kind of diff against a real repository: a staged file before the first commit, a commit that added a file, a rename (old version under the old name), a deletion, staged and unstaged changes, a file deleted from the working tree and an untracked file.
A new app test commits a small PNG, changes it and adds a broken one, then checks the captions and the painted sizes of both pictures, that a change made outside shows by itself (it fails without reading the pictures again after a reload), that a broken file explains itself and that the commit that added the picture has nothing before it. A small test covers how sizes in bytes read.
Tried in the app on Linux: a changed PNG icon, a new JPEG, the 1920 × 1080 screenshot in the commit history of this repository, and a change made outside while the diff was open.
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassIt adds as little code as the change needs, and removes what it makes unnecessary
Nothing in it comes from GitKraken or another closed-source client (see CONTRIBUTING.md)