Rook
Rook

Reputation: 62538

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?

Upvotes: 14

Views: 6269

Answers (5)

Jonathan Potter
Jonathan Potter

Reputation: 3081

To see all files that changed in a revision, use:

hg status --change REV

Upvotes: 2

EmFi
EmFi

Reputation: 23450

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.

Upvotes: 6

user
user

Reputation: 18529

  • hg log --style changelog

OR

  • hg log --template "Description: {desc}\n" - supported keywords like desc, files etc. are listed here

Upvotes: 0

Martin Geisler
Martin Geisler

Reputation: 73768

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.

Upvotes: 13

daniel kullmann
daniel kullmann

Reputation: 14023

I believe there is no built-in way to achieve this, but a bit of sed (also available for Windows: http://gnuwin32.sourceforge.net/packages/sed.htm) can help:

hg log --template "Rev: {rev}:{node}\nDate: {date|isodate}\nFiles: {files}\n\n" -l 10 | sed -e '/^Files:/s/ /\n  /g'

Output:

Rev: 1:2538bd4661c755ccab9b68e1d5e91144f6f97d33
Date: 2011-12-20 15:47 +0100
Files:
  test1.txt

Rev: 2:853a6f3c505308c9babff5a5a2f1e09303f1689c
Date: 2011-12-20 15:44 +0100
Files:
  test2.txt
  test3.txt

Explanation of sed -e '/^Files:/s/ /\n /g':

  1. /^Files:/ searches for lines starting woth "Files:", and applies the following search and replace just to those line
  2. s/ /\n /g replaces all lines with a newline, followed by the spaces.

This solution won't work when file names contain spaces.

Upvotes: 2

Related Questions