6

I have configured hg log in ~/.hgrc to only list commits from the current branch by default:

[defaults]
log = --branch .

However, occasionally I'd like to really see commits from all branches. Is there a way to tell hg log when invoked form the command line to not use the configured defaults but fall back to the built-in behavior? As a brute-force solution ignoring ~/.hgrc altogether for this particular invocation of hg log would be fine for me.

I'm aware that defaults are deprecated in favor of aliases, but aliases cannot be created with the same names as existing commands, which is what I want in order to not have to learn new command names, esp. when ~/.hgrc settings are to be shared by multiple developers.

Edit: Not being able to create aliases with the same names as existing commands was a regression that has been fixed.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sschuberth
  • 28,386
  • 6
  • 101
  • 146
  • 1
    I guess your problem is exactly why defaults were deprecated :) Also, your argument for not using aliases is a bit weird since, by definition, even if there was a solution, you would have to learn a new command or, at least, a new argument (e.g. you could look into writing an extension that adds a "--no-defaults" parameter to ignore defaults, but that's pretty complicated for what it is). – Ludovic Chabant Jul 25 '12 at 16:58
  • I would have to learn a new argument if there was one to fall back to the built-in behavior, that's right. But I rarely have a need for that, so that would be ok. On the other hand, in my opinion it's an unreasonable design decision that a commonly used command like `log` lists commits from all branches by default. That makes it close to impossible to easily work with multiple branches, which is why I've changed the defaults. It's much easier to give people your `.hgrc` file instead of telling them "Yeah, forget about `log`, use `logb` (or whatever) instead". – sschuberth Jul 26 '12 at 06:58
  • I disagree but I get your point. I myself rarely use `log` -- I prefer [`graphlog`](https://www.mercurial-scm.org/wiki/GraphlogExtension/), which I've aliased to `clog` to use a more compact template and limit to 10 entries. But as I said, there's maybe a way to add a `--no-defaults` parameter as an extension. You could look into that. – Ludovic Chabant Jul 27 '12 at 20:51

4 Answers4

6

You should be able to use --config to override the setting in your .hgrc:

hg --config defaults.log= log

From the man page:

--config    set/override config option (use 'section.name=value')
jyu
  • 76
  • 1
  • Works great, thanks a lot. This is better than my `HGRCPATH=""` approach as it does not ignore `~/.hgrc` completely. – sschuberth Aug 21 '12 at 07:47
  • Just noting that this also works for aliases, and the "section" refers to whatever section the definition is in in your .hgrc: `--config alias.log=log` – Joshua Goldberg Sep 23 '16 at 18:43
  • By "works for aliases" I mean you can use `--config` on the commandline in this way to forget an alias, like you can forget default options. – Joshua Goldberg Feb 02 '17 at 16:09
3

I have gone through the bug reports on the Mercurial website and cannot find any workarounds for this, the response being a blanket "this is deprecated".

Personally, not learning the commands to me is not a valid reason for not migrating away from default command values. A possible alternative would be to move away from per-repository settings and have some settings at the user level, so you can set your own defaults / aliases.


Defaults are now deprecated, so you should likely remove this and specify the arguments each time. Confirmed in the documentation:

https://www.mercurial-scm.org/wiki/Defaults

(defaults are deprecated. Don't use them. Use aliases instead)

Try:

[alias]
blog = log --branch

Usage:

hg blog <branch name>
hg blog default
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
  • Please see my last paragraph above, I'm aware that defaults are deprecated, but aliases are not an option for me. – sschuberth Jul 24 '12 at 08:44
  • 1
    @sschuberth No idea, sorry. I'd say learn the commands, should be easy considering you'd have to make the commands too. We configure mercurial on a per-user basis, so no specific configuration with the repository. My set-up is different to my colleagues in some ways because I work differently to him. Some settings are shared. – Adam Houldsworth Jul 24 '12 at 08:47
2

I know I'm resurrecting an old question here, but this statement

aliases cannot be created with the same names as existing commands

is incorrect.

In your .hgrc file in the [alias] section, you can, for example, have:

[alias]
add = add --dry-run

This will make the add command always do a dry-run, instead of actually recursively adding all unknown files in the repository.

moswald
  • 11,491
  • 7
  • 52
  • 78
  • 1
    By now [this page](http://www.selenic.com/mercurial/hgrc.5.html) indeed says "It is possible to create aliases with the same names as existing commands, which will then override the original definitions". I can confirm this with Mercurial 2.7.2. However, it has not always been like this. I did some research and found that [this seems to have been a regression which was fixed in Mercurial 2.0.1](http://bz.selenic.com/show_bug.cgi?id=3104). So I was probably just using a bad version of Mercurial by the time I've asked this question. – sschuberth Aug 02 '14 at 19:11
  • Very likely. I was merely leaving this here for future readers. :) – moswald Aug 02 '14 at 19:32
0

It seems the best solution to my use-case indeed it to temporarily ignore the ~/.hgrc file altogether. This can be done by setting HGRCPATH to an empty string, which causes Mercurial to only read the .hg/hgrc file from the current repository:

HGRCPATH="" hg log
sschuberth
  • 28,386
  • 6
  • 101
  • 146