Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I limit the size of a Mercurial log?

When I run Mercurial's "hg log" command from a terminal window, the results often fall off the screen, forcing me to scroll up to the top. As a result, I created a template to reduce the verboseness and format of the log:

[alias]
slog = log --template '{rev}:{node|short} {desc|firstline} ({author})\n'

However, I'd like to improve this even further by either a) limiting the size of the "slog" to just the last 10 commits or b) using a command like "hg slog ##", where "##" would be the number of logs shown in the results.

Any thoughts on how to achieve either A or B?

like image 775
Huuuze Avatar asked Jul 06 '11 14:07

Huuuze


2 Answers

You could define your alias to do only a fixed limit in this way:

slog = log --limit 10 --template "{rev}:{node|short} {desc|firstline} ({author})\n"

Or, you could put --limit on the end so that you can pass a number to it, as arguments to an alias will be appended to the end:

slog = log --template "{rev}:{node|short} {desc|firstline} ({author})\n" --limit

The above could be called like this for the last 10 changesets:

hg slog 10

You should also be able to define the parameterized version in this way, but it doesn't seem to be property expanding the $1:

slog = log --limit $1 --template "{rev}:{node|short} {desc|firstline} ({author})\n"

#I had to use shell execute to make it expand:
#slog = !hg log --limit $1 --template "{rev}:{node|short} {desc|firstline} ({author})\n"
like image 109
Joel B Fant Avatar answered Sep 28 '22 09:09

Joel B Fant


To get last 10 changeset:
hg log -l10

Alternative solution:
Configure autopager plugin in the .hgrc file.
The end result is similar to already mentioned solution

hg log | less
like image 29
bbaja42 Avatar answered Sep 28 '22 07:09

bbaja42