Differences between revisions 1 and 2
Revision 1 as of 2010-09-01 22:13:46
Size: 2789
Editor: abuehl
Comment:
Revision 2 as of 2010-09-01 22:16:05
Size: 2790
Editor: abuehl
Comment:
Deletions are marked like this. Additions are marked like this.
Line 40: Line 40:
[alias] wclone = clone -u . [alias]
wclone = clone -u .

Mercurial allows to set default options and arguments for commands in the configuration file.

Full quote of http://www.selenic.com/mercurial/hgrc.5.html#defaults (as of Mercurial 1.6.3):

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

Use the [defaults] section to define command defaults, i.e. the default options/arguments to pass to the specified commands.

The following example makes hg log run in verbose mode, and hg hg status show only the modified files, by default:

  [defaults]
  log = -v
  status = -m

The actual commands, instead of their aliases, must be used when defining command defaults. The command defaults will also be applied to the aliases of the commands defined.

Controversy

Defaults are a controversial feature.

Project lead Matt Mackall has repeatedly expressed that defaults should not be used:

In http://markmail.org/message/hl3d6eprubmkkqh5 (Oct 21, 2009):

Defaults are a bad idea. They are deprecated. Don't use them. Don't
recommend them. Forget they existed. Use aliases.

Which lead to their deprecation with change 24dad078603b.

In http://mercurial.markmail.org/message/jkaw5nflizlirgzt (Oct 21, 2009):

... Again, this is one of the fundamental problems with defaults: once you've set a default, there's no way to bypass it. Don't use 'em. And please don't suggest them to other people.
Instead, make a new command:

[alias]
wclone = clone -u . 

In http://mercurial.markmail.org/message/eit7ip5sk2xzeyyi (Aug 13, 2010)

Breaking automation is only one of the reason to not use defaults.

Another is they form bad habits. One of the earliest versions of Slackware (circa 1993) used to ship with a shell configured with a default alias of 'rm = rm -i' under the assumption that most users were complete Linux newbs and they should be warned that they were deleting their files permanently. Result: lots of users' fingers 'learned' they could use 'rm' without any forethought and put off having their real learning experience about rm until they were on a different machine - possibly someone else's.

And a third is that our options aren't toggles (and aren't going to be). So if you want to disable one default option, you've got to switch -everything- into plain mode.

And a fourth is that aliases do everything that defaults did and more, while providing the ability to avoid shadowing built-ins (thus avoiding the above three points). So there really no reason to use defaults these days. We should probably drop the docs. 

However, crew member Martin Geisler is a fan of defaults and continues to recommend them to other people: http://markmail.org/message/tigm3ges7buf4wlw (Sep 1, 2010).

Defaults (last edited 2013-12-02 15:12:52 by MartinGeisler)