Jujutsu History Template




Jujutsu Version Control

Recently I’ve been using Jujutsu or jj for version control. It is, in effect, an alternate front-end to Git. There are any number of articles, tutorials and other online resources that can explain the finer details.

One feature I’ve been exploring more lately is Jujutsu’s ability to use templates to control how output is presented.

Compact history

I like a one-line history. jj provides that ability, but I was unhappy with the column order. Templates to the rescue. The following template shows the change id, then the commit id, the date and time, the author, and finally the description.

For the date and time I like to use the .ago() option to get relative time offsets. However the width of that information is variable, which ruins a nice table-like appearance. So I’ve opted for a 12-character format with a 24 hour clock.

The author on all of my own repositories is me, so having my name displayed on each line seems silly. The template compares the author email on the commit to my email address, and only displays the name if the two are different. Nice.

Here’s the template:

 
history = ["log", "-T", '''
  change_id.shortest(12)
  ++ " " ++ commit_id.shortest(12)
  ++ " " ++ committer.timestamp().format("%y-%m-%d %H:%M")
  ++ if(author.email() != "mark@zanshin.net",
      " " ++ author.email().local(),
      "",
    )
  ++ " " ++ if(description,
      description.first_line(),
      label("hint", "(no description set)"),
    )
''']

Put that into the [aliases] section of your configuration TOML. I have a bash alias setup to trigger this template. The results look like this:

Image of formatted jj log output: