Skip to content

jj: label single-change diffs with the description#250

Open
wuzzeb wants to merge 1 commit into
dlyongemallo:mainfrom
wuzzeb:jj-change-descr
Open

jj: label single-change diffs with the description#250
wuzzeb wants to merge 1 commit into
dlyongemallo:mainfrom
wuzzeb:jj-change-descr

Conversation

@wuzzeb

@wuzzeb wuzzeb commented Jun 21, 2026

Copy link
Copy Markdown

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 desc as 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.

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 dlyongemallo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 710 to 712
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
Comment on lines 74 to 79
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)
Comment on lines 66 to 71
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)
),
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.

3 participants