Modern Mercurial
I recently came across Josef Sipek’s series of articles on setting up
a “modern Mercurial”. In the first post, he realizes that he was missing
out on a lot of the new features that had been added to our beloved hg
along the years, due to the maintainers’ policy of not changing the default CLI
behaviour.
I realized I had the opposite problem – my .hgrc
is a loose collection of
snippets I gathered from all around the web, at various times, and as such it
has accumulated several layers of Mercurial history.
Extensions
The main thing to clean up was my list of extensions. I had 14 built-in
extensions enabled, several of which had been deprecated in favour of something
better, or incorporated in the core. Now I’m down to 8:
-
color
: self-explanatory… make it pretty. -
extdiff
: lets you specify an external diff/merge tool. -
histedit
: lets you shoot yourself in the foot, a.k.a editing history with
a workflow similar togit rebase --interactive
. -
pager
: lets you specify a custom “pager”, i.e. the thing that stops the
text from scrolling off the top of the screen, and lets you “paginate”
a command’s long output, likehg log
. This mostly saves you from always
having to dohg whatever | less
or similar. -
purge
: adds a command for removing all untracked files. Useful sometimes to
clean up temp files,.orig
files, etc. -
rebase
: this is a basic operation for DVCSes so go figure why this isn’t
enabled by default, especially now that we have phases. -
schemes
: super useful for making aliases of hosting providers like Github,
Bitbucket, and even your own private domains. -
shelve
: I used to use that, along with MQ, to manage my works-in-progress,
but now that I’m usingevolve
(see below), I don’t really use it anymore…
still, I prefer to keep it around.
I also have a few third-party extensions:
-
hg-git
: required for mirroring Mercurial repositories to Github. -
hg-onsub
: run a command on all sub-repositories. I don’t use sub-repositories
much anymore, since I figured they are a pain to work with, but it’s still
occasionally handy to batch-pull/update sub-repos. -
hg-allpaths
: runhg pushall
and push to all paths in one go. -
evolve
: enables the changeset evolution features that are inactive by
default in the Mercurial core. This is totally awesome, and quite mind-blowing
sometimes. -
terse-status
: when you have a directory with lots of untracked files and
nothing else, makehg status
show you just the directory… not 3 pages of
untracked filenames.
Logging
Nothing fancy here, really… I’ve cloned Steve Losh’s templates a long
time ago and never looked back.
Multi-plaform
One cool thing that .hgrc
files have is support for including other config
files that may or may not exist, and support for environment variable expansion.
My .hgrc
is actually generated by my Dotfiles’ install
script, but it includes the “real” hgrc
(which you can see
here). At the end, I can include further configuration files, like
a “local” file that could contain secret or temporary stuff, and a platform
specific configuration file:
# OS-specific settings
%include hgrc-${OS}
# Local settings (if any)
%include hgrc-local
That’s how I keep things working between Mac, Linux, and Windows between home
and work.