jj: label single-change diffs with the description#250
Conversation
Diffview currently uses the raw rev argument as the file-panel "Showing changes for" label whenever :DiffviewOpen is called with an explicit revision argument. This is not limited to ranges: a single explicit commit also bypasses adapter formatting and is shown as the raw rev text. That is fine for many workflows, but it is noisy for jj callers that open one change as <parent-commit>..<commit>. The file panel is narrow, and a pair of commit IDs tends to overflow while not communicating the selected change. Separate the human-facing panel label from the rev argument by adding a rev_to_panel_name(rev_arg, left, right) adapter hook. The hook is display-only. The default implementation preserves existing behavior for other adapters by returning the user-provided rev_arg when present, otherwise falling back to rev_to_pretty_string(left, right). A new hook is needed because rev_to_pretty_string is also used as parseable rev text in other code paths, including opening a DiffView from file history. Returning a human description from rev_to_pretty_string would make those callers feed descriptions back into revision parsing and could also collide in selection persistence keys. rev_to_pretty_string therefore remains machine-readable, while rev_to_panel_name is allowed to return human-readable labels. The jj adapter overrides rev_to_panel_name so it can use resolved revision metadata even when the view was opened from an explicit rev argument. For commit-to-commit ranges, it checks whether the left commit is the first parent of the right commit. When that is true, the range represents one jj change, so the panel can show description.first_line() instead of the raw commit range. Other ranges keep the user-entered rev argument when one was provided. Wire the hook through the normal DiffView constructor, programmatic set_revs updates, and the public CDiffView wrapper so panel labels are handled consistently. This keeps arbitrary ranges such as main..@ and multi-change ranges unchanged, while making the common "open this selected jj change" workflow easier to read.
dlyongemallo
left a comment
There was a problem hiding this comment.
Please fix the failing tests and also change the git commit message so that its format is consistent with this repo's conventions.
| ---@param right Rev | ||
| ---@return string|nil | ||
| function JjAdapter:single_change_subject(left, right) | ||
| if not (left.commit and right.commit) then |
There was a problem hiding this comment.
You need to check for JjRev.NULL_TREE_SHA here, as it's a non-empty string (hence truthy). Otherwise jj show will run for a root commit diff.
| return nil | ||
| end | ||
|
|
||
| ---Convert revs to the string shown in the file panel. |
There was a problem hiding this comment.
Tighten the base docstring here so it's clear that the changed behaviour in the JjAdapter is intentional:
---Convert revs to the display-only label shown in the file panel.
---Unlike rev_to_pretty_string the result need not be parseable as a rev.
---The default prefers the user's rev_arg; adapters may substitute a
---friendlier label.There was a problem hiding this comment.
Pull request overview
This PR introduces a new adapter hook (rev_to_panel_name) to control the “Showing changes for” label in the diff file panel, enabling the jj adapter to display a single-change diff’s change description instead of the raw revision argument.
Changes:
- Add
VCSAdapter:rev_to_panel_name(rev_arg, left, right)(defaulting to the prior behavior). - Implement jj-specific panel naming by detecting single-parent ranges and using the change description’s first line.
- Switch DiffView construction/update paths to use
rev_to_panel_name, and add a functional jj test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/diffview/vcs/adapters/jj/init.lua | Adds jj logic to extract a single change’s description and overrides rev_to_panel_name. |
| lua/diffview/vcs/adapter.lua | Introduces the new rev_to_panel_name hook with a default implementation. |
| lua/diffview/tests/functional/jj_adapter_spec.lua | Adds integration coverage for jj’s rev_to_panel_name behavior on single-change ranges. |
| lua/diffview/scene/views/diff/diff_view.lua | Uses rev_to_panel_name for the file panel label across init / set_revs / refresh flows. |
| lua/diffview/api/views/diff/diff_view.lua | Updates API DiffView construction to use rev_to_panel_name for the file panel label. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not self.rev_arg then | ||
| self.panel.rev_pretty_name = self.adapter:rev_to_pretty_string(self.left, self.right) | ||
| self.panel.rev_pretty_name = self.adapter:rev_to_panel_name(nil, self.left, self.right) | ||
| end |
| panel = FilePanel( | ||
| self.adapter, | ||
| self.files, | ||
| self.path_args, | ||
| self.rev_arg or self.adapter:rev_to_pretty_string(self.left, self.right) | ||
| self.adapter:rev_to_panel_name(self.rev_arg, self.left, self.right) | ||
| ), |
| self.left = new_left | ||
| self.right = new_right | ||
| self.panel.rev_pretty_name = new_rev_arg | ||
| self.panel.rev_pretty_name = self.adapter:rev_to_panel_name(new_rev_arg, self.left, self.right) |
| panel = FilePanel( | ||
| adapter, | ||
| self.files, | ||
| self.path_args, | ||
| self.rev_arg or adapter:rev_to_pretty_string(opt.left, opt.right) | ||
| adapter:rev_to_panel_name(self.rev_arg, opt.left, opt.right) | ||
| ), |
Diffview currently uses the raw rev argument as the file-panel "Showing changes for" label whenever :DiffviewOpen is called with an explicit revision argument. Since with jj you are running
jj descas the work progresses, the label can instead show the description of the change. This needs a new hook rev_to_panel_name because the existing rev_to_pretty_string is used as parsable rev text in other code paths (such as opening history), so rev_to_pretty_string must keep the string as a valid revision.The new rev_to_panel_name hook is added and is identical in behavior to the existing code for all other adapters besides jj. For jj, we detect if the current diff is a single change and if so show the description. Although, now that I think about it, maybe we could expand and list all the changes in the diff? Well, this is a good first step.