Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 'hg log --verbose' show files on multiple lines?

By default all files changed in a changeset are on the same line, which makes them very easily to skip one or two, and hard to read.

How to make each file show on its own separate line?

like image 495
Rook Avatar asked Dec 27 '11 10:12

Rook


2 Answers

The real way to see information about changed files is to use hg status. This shows the files that were modified in revision 100:

$ hg status -c 100

But if you want to have the log messages as well, then hg log is of course a natural starting point. Unfortunately there is no built-in switch that will make it display one file per line.

However, the output of hg log is controlled by a template system and you can write your own styles for it. The default style is here and you can customize to do what you want by changing

file = ' {file}'

to

file = '{file}\n'

Then save the new style as my-default.style and add

[ui]
style = ~/path/to/my-default.style

to your configuration file. This gives you one file per line and it even works when there are spaces in your file names.

I'm aware of one problem: you lose colors in the hg log output. It turns out that Mercurial is cheating here! It doesn't actually use the default template I showed you when generating log output. It doesn't use any template system at all, it just generates the output using direct code since this is faster. The problem is that the color extension only work with the hard-coded template. When you switch to a custom template and thereby invoke the template engine, you lose the color output.

However, you can recover the colors by inserting the ANSI escape codes directly into your template (on Unix-like systems). Changing

changeset = 'changeset:   {rev}:{node|short}\n{branches}...

to

changeset = '\033[33mchangeset:   {rev}:{node|short}\033[0m\n{branches}...

does the trick and hard-codes a yellow header line for the changeset. Adjust the changeset_verbose and changeset_quiet lines as well and you'll have colored output with your own template.

like image 91
Martin Geisler Avatar answered Nov 15 '22 23:11

Martin Geisler


The hg template help file has this gem in its examples.

Format lists, e.g. files:

$ hg log -r 0 --template "files:\n{files % ' {file}\n'}"

This works on Windows without any translation.

like image 26
EmFi Avatar answered Nov 16 '22 00:11

EmFi