Repository navigation
Build custom patches directly from a commit's diff - #6039
Merged
Merged
Conversation
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
from
September 20, 2026 17:52
32bc3d9 to
0495e2f
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
2 times, most recently
from
September 21, 2026 13:46
a4e232b to
de74ae0
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
3 times, most recently
from
September 27, 2026 10:41
609d642 to
e7924f0
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
from
September 27, 2026 10:56
e7924f0 to
3725e98
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
from
September 27, 2026 16:27
3725e98 to
da57ab3
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
2 times, most recently
from
October 4, 2026 13:48
c397f7c to
f419d45
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
from
October 4, 2026 15:01
f419d45 to
e8cff03
Compare
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
7 times, most recently
from
October 5, 2026 09:20
803950a to
352783c
Compare
The lines of a commit's diff that are in the custom patch being built have to be shown as such over whatever a diff renderer made of that diff, whose bytes we can't touch — and mustn't, since everything we know about a row is keyed by where it sits in the content. So the marks are a decoration drawn over the content instead: a column reserved at the left of every line, blank but for the lines that are in, with the content shifted along past it. Nothing about the content changes but the width it has to wrap in. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A patch is built in terms of where a line sits in the file's diff, which is what the patch explorer has to hand. The main view doesn't: a row of it resolves to a line of a file, and what index that line has depends on how much of the diff has been read and how a diff renderer chose to lay it out. So let the two meet at the patch builder's edge, in the identity of a change line — its number on the side it belongs to — leaving the main view to speak only of lines it can see. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Five panels show a commit's diff in the focused main view — one file of it from the commit files panel, the whole of it from the commits, sub-commits, stash and reflog panels — and each answered for that diff itself, in the same words. Have them share one object instead, told only which diff it is, so that what follows has a single place to say what can be done to a commit's diff and needs saying once rather than five times. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
It is built entirely on that helper, and the render chokepoint that is about to want it lives in the gui package, which cannot reach a controller. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Removing lines from a commit, moving a custom patch out of one, undoing either — none of it goes through the focused main view, so a selection over that commit's diff was left where it was, painted over a rendering of a diff that no longer exists. Every render now asks whether it is showing a different diff than the one on screen, which is what a rewritten commit looks like, and puts the selection back on the change that has taken its place — the same reveal an action in the view does for itself. It stands down for a render of the same diff, where a selection, perhaps a range still being made, is exactly right as it is, and for one that something more precise is already waiting to place. The key a render is remembered under moves ahead of anything that might change the command's arguments, so that it says which diff is being rendered and nothing else. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Which line of a file a diff row is, in the terms a patch is built in, is asked in two places already — staging a selection and editing a hunk — and is about to be asked in a third, of a commit's diff rather than the working tree's. The rule is the same one everywhere: an addition is where it sits in the new version of the file, a deletion where it sat in the old one. So the row is asked for its identity and the patch package for the lines with those identities, instead of walking the diff working the identities out again. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The five panels that show a commit's diff now offer on it what the patch explorer offers on the one file it can show at a time: space takes the selected lines into the custom patch being built, or back out of it again, and d takes them out of the commit itself. So a patch can be built straight from the diff already on screen, over several files at once and without entering the commit's files first — and from a stash entry or a reflog entry too, whose diffs the explorer could reach but which had no patch preview of their own to show for it. The two arrive together because they are one answer to what a commit's diff offers, and because d needs exactly what space builds: a patch of the selection, which the rebase then removes from the commit. Which of the two space is doing is decided by the first selected line, as toggling a file in the commit files panel is, and the selection then moves past the lines dealt with — they are still in the diff, a patch leaving the commit alone, so a second press would otherwise take them straight back out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A patch built from what is on screen has to show what is in it, over the diff those lines were taken from — which may be a diff renderer's rendering of it, whose bytes are none of ours to touch. So the marks are drawn in a gutter over the content, from the lines the patch holds rather than from where they were drawn last. They are worked out again whenever a pane's content settles and whenever the patch itself changes. Working them out as the content settles keeps them right across a renderer switch, a change of context size, or a walk through the commits. They are shown whenever the main view shows the diff the patch is built from, whether or not it has the focus. The pane beside the diff previews the patch all the while, and marks that came and went with the focus would look like a bug while browsing. A diff of any other commit gets none. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The pane beside a commit's diff showed the patch being built from it by assembling the text itself. That text could not be handed to a diff renderer the way a diff can: a stdin filter might have coped, but a tool that diffs two files could not. Its idea of how much context to show around a hunk was also its own rather than git's. Materialize the patch instead: write each of its files as it is before the patch into one tree and as it is after into another, and let git diff the two trees. The patch becomes a diff of real files, rendered by whatever renders the rest of them, with git's own context around it. Its lines can then be pointed at; taking them back out of the patch will need that. The trees are named a and b, so that with git's own prefixes suppressed the paths read like an ordinary diff's over the repo's own paths. They are written when the patch changes rather than when it is shown, the patch builder counting its own versions for that, and they go away with the patch. A renamed file is materialized under the name the patch expects to find it under. Where the patch carries the rename, that is the name the file had before, so the rename comes out as a rename. git names the trees themselves in the two rename lines, having only the two paths to go by. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Space in the pane previewing the patch had nothing to act on: everything there is in the patch already, so it can only mean taking those lines back out, in the way that space in the staged side of the working tree's diff only unstages. A line of the patch can't be found by its number: the patch renumbers whatever follows a change it leaves out, so a line of it names a line of the commit's diff that isn't the one shown. A line is identified instead by its position among its file's changes, counted in the diff the patch is shown as. That is the same position it has among the changes the patch holds for the file, since both are in the order the file has them. This holds however the rendering came out, so a renderer that groups a hunk's deletions before its additions, or leaves a change out altogether, no longer matters. The pane's rows are stated in terms of the trees the patch was materialized into, so the paths come back to the repo's own before anything is looked up in them. This also lets the lines there be copied and edited, as the lines of a commit's diff can be. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
stefanhaller
force-pushed
the
build-custom-patch-from-main-view
branch
from
October 5, 2026 09:33
352783c to
1e58904
Compare
stefanhaller
added a commit
that referenced
this pull request
Oct 5, 2026
9th PR in the stack of PRs towards staging hunks directly from the main view. This one is stacked on #6039. Everything the staging and patch-building panels did now happens in the main view, so this PR removes them. `enter` on a file, in the files panel or the commit files panel, focuses the main view at that file's diff. Double-clicking the file row does the same. Everything else about the flow is unchanged; there is simply no separate panel to be in. **Config changes, both migrated automatically:** - `gui.wrapLinesInStagingView` → `gui.wrapLinesInDiffView` - `gui.useHunkModeInStagingView` → `gui.useHunkModeInDiffView` Notable change: `wrapLinesInStagingView` used to affect only the staging panel, but not the normal diff view. The new `wrapLinesInDiffView` affects the main view always, whether focused or not; I assumed this is probably the desired behavior, but I don't use the option myself, so I can't tell for sure. **One thing to know if you use custom commands:** `staging`, `stagingSecondary` and `patchBuilding` are no longer context names. If a custom command still names one in its `context` field, that is now reported as a config error which you need to fix manually. The context size can now be changed while a patch is being built. The refusal existed because the old patch explorer kept track of which lines are included in the patch by their line indices in the diff, which would change when changing the context size. The new mechanism doesn't have this problem, because it keeps track of patch lines by their line identity, which doesn't change.
stefanhaller
added a commit
that referenced
this pull request
Oct 5, 2026
…atures (#6073) The demo videos were rendered as animated gifs, which is less than ideal, because they start playing automatically, they loop but users can't tell when they start over from the beginning, and they can't be paused or rewound. Convert them to videos instead so that users see a playhead and the usual player controls. Leave a bit of room at the bottom for those controls; different browsers render those differently, so it's a bit of a best effort solution. Also take this opportunity to update some of the demos for the changed functionality of #6035, #6039 and others.
1 task
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.
8th PR in the stack of PRs towards staging hunks directly from the main view. This one is stacked on #6035.
The same idea as the PR below it, for commits.
spaceover a commit's diff toggles the selected lines into the custom patch, anddremoves them from the commit.It works from all five panels that show a commit's diff: commits, commit files, sub-commits, stash and the reflog. The reflog and the stash never had a patch-building view at all; they have one now.
dis disabled, with a reason given, where the commit can't be rewritten — the stash, sub-commits of another branch, mid-rebase — and in the preview pane.The
spaceandddescriptions now depend on which kind of diff you are looking at: "Stage" and "Discard" over the working tree, "Toggle lines in patch" and "Remove lines from commit" over a commit.