jj icon indicating copy to clipboard operation
jj copied to clipboard

`TreeDiffEntry` template method `summary()`

Open Jollywatt opened this issue 6 months ago • 5 comments

It is currently possible to obtain a diff summary like this, using the summary() template method of TreeDiff:

❯ jj log -r @ --no-graph --template "diff.summary()"
M docs/conflicts.md
R docs/design/{run.md => walk.md}
D docs/filesets.md

This PR adds a summary() method to TreeDiffEntry, to allow things like:

❯ target/debug/jj log -r @ --no-graph --template 'diff.files().map(|f| f.summary()).join("\n")'
docs/conflicts.md
docs/design/{run.md => walk.md}
docs/filesets.md

This template method is useful for tools like https://github.com/idursun/jjui which rely on templates to produce output. There, a template like

❯ jj log -r @ --no-graph --template 'diff.files().map(|file| separate(":",
	file.status(),
	file.path(),
	file.summary(),
)).join("\n")'
modified:docs/conflicts.md:docs/conflicts.md
renamed:docs/design/walk.md:docs/design/{run.md => walk.md}
removed:docs/filesets.md:docs/filesets.md

could be used to obtain both the machine readable path and the { => }-style summary together.

Checklist

If applicable:

  • [x] I have updated CHANGELOG.md
  • [x] I have updated the documentation (README.md, docs/, demos/)
  • [ ] I have updated the config schema (cli/src/config-schema.json)
  • [ ] I have added/updated tests to cover my changes

Jollywatt avatar Jun 03 '25 15:06 Jollywatt

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jun 03 '25 15:06 google-cla[bot]

It looks like you haven't signed the Google CLA yet. We cannot accept he PR without it.

martinvonz avatar Jun 04 '25 06:06 martinvonz

If the goal is to get formatted (or combined) source/target path instead of source().path()/target().path() pair, it might be better to add .display_copied_path() -> String or something.

yuja avatar Jun 04 '25 07:06 yuja

FYI, there may be some changes in this area for the new copy tracking design because the data model supports multiple files being merged into one.

martinvonz avatar Jun 06 '25 16:06 martinvonz

Good points. I will change the name to .copied_path_summary() or similar if you want.

Jollywatt avatar Jun 06 '25 17:06 Jollywatt