How to enable Mercurial extensions (such as mq)? - mercurial

I have installed Mercurial from the Ubuntu package repository. However I don't know how to enable extensions (q* commands). How should I do that? The help shows that
enabled extensions:
style (no help text available)
I want to enable mq and hgk.

Enable extensions in hgrc.
extensions
Mercurial has an extension mechanism for adding new features. To
enable an extension, create an entry for it in this section.
If you know that the extension is already in Python's search path, you
can give the name of the module, followed by =, with nothing after the
=.
Otherwise, give a name that you choose, followed by =, followed by the
path to the .py file (including the file name extension) that
defines the extension.
...
Example for ~/.hgrc:
[extensions]
# (the mq extension will get loaded from Mercurial's path)
mq =
# (this extension will get loaded from the file specified)
myfeature = ~/.hgext/myfeature.py
http://www.selenic.com/mercurial/hgrc.5.html#extensions

You can also enable an extension without editing the hgrc, if you want to do it one off. [Source]
hg --config extensions.histedit= --help

The documentation of both extensions shows how to enable them : MQ, Hgk.
The usual way to enable an extension is to add a line to your .hgrc (or Mercurial.ini on some Windows system). It is explained in the hgrc documentation.
In your following case, add this to your configuration file :
[extensions]
mq =
hgk=
You can put it in your global configuration file or the repository one, depending if you want to have the extensions activated in every repository or just a specific one.

The output of hg help extensions starts with
Using additional features
Mercurial has the ability to add new features through the use of
extensions. Extensions may add new commands, add options to existing
commands, change the default behavior of commands, or implement hooks.
Extensions are not loaded by default for a variety of reasons: they can
increase startup overhead; they may be meant for advanced usage only; they
may provide potentially dangerous abilities (such as letting you destroy
or modify history); they might not be ready for prime time; or they may
alter some usual behaviors of stock Mercurial. It is thus up to the user
to activate extensions as needed.
To enable the "foo" extension, either shipped with Mercurial or in the
Python search path, create an entry for it in your configuration file,
like this:
[extensions]
foo =
You may also specify the full path to an extension:
[extensions]
myfeature = ~/.hgext/myfeature.py
So just add
[extensions]
mq =
to enable the MQ extension.

Related

Enforcing hg settings on all users of a mercurial repository

Is there any way to centrally manage mercurial settings for all users of a repository? Are there additional [existing] tools, add-ons, extensions, etc for this?
My use case
We have a repository that includes a few Excel, Word etc files that constantly cause trouble with merging.
With [merge-patterns] entries a la **.doc = internal:fail I can specify the intended behaviour, but I have to set this up for each and every user.
I want this to propagate automatically to anyone who clones the repository.
Environment
We use Kiln 2.6 hosted on our own Windows Server and TortoiseHg 2.2 on our Windows clients.
As far as I know, this possibility doesn't exists in Mercurial and I'm not aware of any extension which let you clone the .hgrc along with the other files.
However, you can do some things to "ease" the process of setup for each user.
Provide a template hgrc in the repository
You can add a "template" .hgrc in the repository. When a user clone the repo, the only thing he as to do is move the template to the right place.
Change the system wide hgrc
If you have some kind of Configuration management system for your clients, you can set the system wide configuration file for each of your users. There's various way of doing it. From the documentation:
(Windows) <install-dir>\Mercurial.ini or
(Windows) <install-dir>\hgrc.d\*.rc or
(Windows) HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial
Per-installation/system configuration files, for the system on which
Mercurial is running. Options in these files apply to all Mercurial
commands executed by any user in any directory. Registry keys contain
PATH-like strings, every part of which must reference a Mercurial.ini
file or be a directory where *.rc files will be read. Mercurial checks
each of these locations in the specified order until one or more
configuration files are detected. If the pywin32 extensions are not
installed, Mercurial will only look for site-wide configuration in
C:\Mercurial\Mercurial.ini.
But obviously this depends on the way your clients are set up, so you will have to find the solution yourself. For example you can:
Set these files on the computer installation
Provide an executable which configure this that every user must run
Configure your in-house configuration management system to set up this on the next computer start
Change the roaming user profile if they have one.
You can use the projrc extension to push a project configuration file to others. It requires that the clients enable the extension first and that they fully trusts the server.

hgrc progress extension not loading

The docs say all I need to do is add this:
[extensions]
progress = # shows progress bar for certain tasks
but when I try to clone this repo it doesn't let me because the extension can't be found. It says it's packaged with 1.5 and later and I'm running 1.9.2:
> hg --version
Mercurial Distributed SCM (version 1.9.2)
(see https://www.mercurial-scm.org for more information)
Any ideas on why it's not loading?
The problem is coming from the "comment" you added on the line. According to the documentation :
Lines beginning with # or ; are ignored and may be used to provide
comments.
You can't put a comment like this where you did. Just replace your config with :
[extensions]
# shows progress bar for certain tasks
progress=
And everything will be fine.
Secondly, as I understand you have activated the extension on the server side ? This extension must be activated on the client side.

Specify Editors in Mercurial

In general, if I've got a custom file of type W and want to use custom application/editor X to open/view it how do i set up Hg to call the application X when i want to edit/view the file?
Specific example: I'm using TortoiseHg to track a set of files, that are created by a custom application, an OPC server application called Kepserver. Kepserver creates .OPF files, while Hg can tell when the files have changed, I'd like to use the Kepserver application to view the files from Hg Workbench.
I see a setting that allows me to set an editor. I specified the path to the Kepserver application, but when i click on the files in workbench it tries to do a binary diff, using Kdiff3, How can i specify editors for specific repositories?
The default behavior when double-clicking a file in TortoiseHg workbench is to run a visual diff. To open the file in an editor, you must right-click on the file and select "Edit Local" or one of the similar options.
The editor used when this option is selected is controlled by the
[tortoisehg]
editor = <editor>
setting in your .hgrc or mercurial.ini.

How can I share a commit-hook in mercurial with all fellow developers?

we are working with mercurial and now we would like to introduce precommit hooks to keep the code clean. We would like everyone to somehow get the hooks, but we would also like to be able to update this in some centralized way. Mercurial does not version control hooks, so what would be our alternative option?
Do any of you have found a solution for this?
Thanks in advance!
Nemmi
Hooks are not cloned (as detailed in "Version-controlled extension configuration in Mercurial"), but you can have a common hgrc file (see hgrc Syntax):
A line of the form %include file will include file into the current configuration file
In that central configuration file, you can then modify the [hooks] section.
If you have control over their desktops (it's a standard corporate install) you can put the hook in the system-wide entries /etc/mercurial/hgrc or /etc/mercurial/hgrc.d/ourcommithook
If you're remotely administering the machines you could automate this using something like the very excellent puppet or by building your own .rpm, .deb, or .msi installer which both installed Mercurial and places the everyone hooks in the machine-global config.
Have a look at the projrc extension. You then simply need to have designers put a small number of common lines in their ~/.hgrc files and they will automatically get pushed whatever you put in your centralized repo's repo/.hg/projrc file.
You will still need a common place to put these hooks but you probably already have some sort of shared mounted drive that users all mount, right? Or you could have a "tools" repository that everybody has to have checked out in a standard location.
Steve

Load multiple .hgrc files - ie, some with machine-specific settings?

I'd like to keep two ~/.hgrc files: ~/.hgrc and ~/.hgrc.local – one with "standard" settings (eg, username), the other with machine-specific settings (eg, setting a graphical merge tool).
How can I do this with hg?
For example, this is how I do it with Vim:
# ~/.vimrc
syntax enable
source ~/.vimrc.local
Then:
# ~/.vimrc.local
let work_code = 'code/work/.*'
if expand('%:p:h') =~ work_code ... fi
There's a not-often used %include directive in mercurial 1.3 and later:
From man hgrc:
A line of the form %include file will include file into the current
configuration file. The inclusion is recursive, which means that
included files can include other files. Filenames are relative to the
configuration file in which the %include directive is found.
so go with:
%include ~/.hgrc.local
and you should be good to go.
I solve this problem for all my "dot files" in a similar way. On login my shell checks a list of files (hgrc, vimrc, ....) and checks if any of them is older than ${that_name}.global or ${that_name}.local. If it is - cat ${that_name}.{global,local} > ${that_name}. Simple and works great so far. While there's a "better" way (using %include) sometimes processing the config files manually has advantages - for example it will work with mercurial pre-1.3.
Mercurial checks for a number of configuration files with a specific priority. This way you can have global, user-specific and repository-specific settings.
Mercurial version >= 1.4 has a hg help config command which describes this in a nice overview:
$ hg help config
Configuration Files
Mercurial reads configuration data from several files, if they exist. Below we list the most specific file first.
On Windows, these configuration files are read:
- "<repo>\.hg\hgrc"
- "%USERPROFILE%\.hgrc"
- "%USERPROFILE%\Mercurial.ini"
- "%HOME%\.hgrc"
- "%HOME%\Mercurial.ini"
- "C:\Mercurial\Mercurial.ini"
- "HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial"
- "<install-dir>\Mercurial.ini"
On Unix, these files are read:
- "<repo>/.hg/hgrc"
- "$HOME/.hgrc"
- "/etc/mercurial/hgrc"
- "/etc/mercurial/hgrc.d/*.rc"
- "<install-root>/etc/mercurial/hgrc"
- "<install-root>/etc/mercurial/hgrc.d/*.rc"
The configuration files for Mercurial use a simple ini-file format. A configuration file consists of sections, led by a "[section]" header and followed by
"name = value" entries:
[ui]
username = Firstname Lastname <firstname.lastname#example.net>
verbose = True
This above entries will be referred to as "ui.username" and "ui.verbose", respectively. Please see the hgrc man page for a full description of the possible
configuration values:
- on Unix-like systems: "man hgrc"
- online: http://www.selenic.com/mercurial/hgrc.5.html
You can list your current settings with hg showconfig.
Mercurial will look in several different locations for hgrc files and will load them if present. For system-wide configuration the standard (on UNIX) would be to use /etc/mercurial/hgrc.
See the files section of the hgrc man page for more information.