Skip to content

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

Merged
dlyongemallo merged 1 commit into
dlyongemallo:mainfrom
wuzzeb:jj-change-descr
Jul 4, 2026
Merged

jj: label single-change diffs with the description#250
dlyongemallo merged 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.

@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.

Comment thread lua/diffview/vcs/adapters/jj/init.lua Outdated
---@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.

Comment thread lua/diffview/vcs/adapter.lua Outdated
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)
),

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.

self.files, sefl.path_args, and self.rev_arg are all nil here, as they're not assigned until Diffview:init() runs. Actually, why is panel even being constructed here? Is something relying on opt.panel being set before Diffview:init() is called?

@dlyongemallo

Copy link
Copy Markdown
Owner

@wuzzeb Are you still working on this? I've made a number of changes to the jj adapter recently and you'll probably have to rebase your changes.

@wuzzeb

wuzzeb commented Jul 1, 2026

Copy link
Copy Markdown
Author

Yeah sorry I've been travelling, I will work on it in the next few days

@wuzzeb wuzzeb force-pushed the jj-change-descr branch from f5a85e9 to 22875a8 Compare July 3, 2026 15:39
@wuzzeb

wuzzeb commented Jul 3, 2026

Copy link
Copy Markdown
Author

Since a bunch changed in main I just rebased and force-pushed. I like the overall jj changes you made in main and this now compliments them with adding the description.

"-r",
right_rev,
"-T",
[[parents.first().commit_id() ++ "\x1f" ++ description.first_line() ++ "\n"]]

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.

This seems fragile. It's depending the literal string \x1f being interpreted by jj in its template strings. Why not just use \n? Why leak a control character into the label which then has to be stripped out (line 610)? I think the way you've done this enables an invisible glyph to accidentally be copied by a user, which can lead to mysterious bugs.

}
)

if code ~= 0 or not out[1] 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.

Can't out itself be nil, or out[1] be ""?

return
end

if left.commit == JjRev.NULL_TREE_SHA 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.

This drops the initial commit description. Is this intentional?

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)
),

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.

self.files, sefl.path_args, and self.rev_arg are all nil here, as they're not assigned until Diffview:init() runs. Actually, why is panel even being constructed here? Is something relying on opt.panel being set before Diffview:init() is called?

end

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

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.

Should have backticks around rev_to_pretty_string and rev_arg.

return
end

subject = vim.trim(subject or "")

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.

subject can't be nil here (because return would've happened on line 612).

@dlyongemallo dlyongemallo dismissed their stale review July 4, 2026 08:13

I'll make the minor follow-up changes myself.

@dlyongemallo dlyongemallo merged commit 3d17e1b into dlyongemallo:main Jul 4, 2026
8 checks passed
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