martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
8.23k stars 273 forks source link

FR: git log --shortstat alternative #4154

Open xzfc opened 1 month ago

xzfc commented 1 month ago

Is your feature request related to a problem? Please describe.

The git log command has a --shortstat option. It gives a quick overview of how "heavy" a particular commit is and allows a user to visually filter out heavy commits at a glance to the log output. I use it as a signal whether it is time to split current feature branch into multiple PRs.

I want something similar for jj log.

$ git log --graph --oneline --shortstat -n 5
* d6e97883 (HEAD -> main, origin/main, origin/HEAD) cli: port description template to templater
|  11 files changed, 131 insertions(+), 41 deletions(-)
* 5a19eb63 cli: merge description_template_for_*() functions
|  4 files changed, 8 insertions(+), 35 deletions(-)
* 45d16f4b cli: commit, split: set default description to intermediate commit object
|  3 files changed, 9 insertions(+), 15 deletions(-)
* 6395d323 cli: commit, split: pass temporary commit object to description helper
|  3 files changed, 21 insertions(+), 30 deletions(-)
* b9cc61b5 cli: describe: set default description to temporary commit object
|  2 files changed, 7 insertions(+), 12 deletions(-)

Describe the solution you'd like

Given that after d1912bf0 ("templater: add commit.diff().\() methods") we have TreeDiff exposed to the templates, I think this use-case could be covered by exposing changed files/additions/deletions out of it. Thus, a user-configured log template could produce something like this:

$ jj log -r ::main -n 5
◆  yxyrwptq yuya@tcha.org 2024-07-25 13:39:00 main main@origin HEAD@git d6e97883
│  [:11 +131 -41] cli: port description template to templater
◆  knmxwwnk yuya@tcha.org 2024-07-25 13:39:00 5a19eb63
│  [:4 +8 -35] cli: merge description_template_for_*() functions
◆  yxtkoqyl yuya@tcha.org 2024-07-25 13:39:00 45d16f4b
│  [:3 +9 -15] cli: commit, split: set default description to intermediate commit object
◆  nvrptqtt yuya@tcha.org 2024-07-25 13:39:00 6395d323
│  [:3 +21 -30] cli: commit, split: pass temporary commit object to description helper
◆  rxmmrysu yuya@tcha.org 2024-07-25 13:39:00 b9cc61b5
│  [:2 +7 -12] cli: describe: set default description to temporary commit object

Describe alternatives you've considered

Provide a --shortstat option for jj log just like git log does.

PhilipMetzger commented 1 month ago

I think this only needs a diff().stat() method and optionally the --shortstat option although you could achieve it also via template then.

xzfc commented 1 month ago

The diff().stat() output is not concise, it lists every file affected.

PhilipMetzger commented 1 month ago

Then it should have a way of providing a conciser output either via parameter or some other option.

yuja commented 1 month ago

We'll need something like diff.files().len(), diff.line_stat().added()/.removed(). If we don't care the formatting, diff.stat().last_line() (i.e. add template.last_line() method) will also work.