While you can accomplish that with an alias (see below), the cleanest approach here is an extension:
from mercurial import extensions, commands
testedwith = "3.5"
default_log_rev = "reverse(ancestors(.))"
def override_log(original_cmd, ui, repo, *pats, **opts):
have_rev = False
for opt in ["rev", "branch"]:
if opts.has_key(opt) and opts[opt]:
have_rev = True
if not have_rev:
opts["rev"] = [default_log_rev]
return original_cmd(ui, repo, *pats, **opts)
def uisetup(ui):
extensions.wrapcommand(commands.table, "log", override_log)
This will only use your new default if neither the --rev
nor the --branch
options (or their abbreviations -r
and -b
) of log
are set, thus preserving the original behavior if one of them is provided.
You can install such an extension in the usual way, i.e. by adding something like the following to your ~/.hgrc
(assuming that the above code is in /path/to/logdefault.py
):
[extensions]
logdefault = /path/to/logdefault.py
If an extension is to heavyweight for you, you can also create an alias in your ~/.hgrc
:
[alias]
log = log --rev 'reverse(ancestors(.))'
rawlog = !$HG --config alias.log=log log "$@"
The second alias (rawlog
) exists so that you can still access the original log
functionality.