When not in the repo root dir `in_hg` used `hg summary` which is terribly slow on big repositories, and `hg_get_branch_name` called `hg branch` which is also pretty slow as well.
Based on the [branch](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/branch) plugin, I created the function `hg_get_dir` that fetch the `.hg` directory if it exists, going up in the directory tree. From there, we know if we're in an HG repository if `in_hg` returns a non empty string, and we can simply get the branch name from the content of the `.hg/branch` file.
### Benchmarks
Based on 10 calls to `hg_get_branch_name` in subdir (so that the old `hg summary` is called), here are the average times:
* Before: `/tmp/test.zsh 0.08s user 0.04s system 96% cpu 0.133 total`
* After: `/tmp/test.zsh 0.00s user 0.00s system 71% cpu 0.008 total`
It's faster and it uses less CPU!
The other changes after that are purely esthetic (fit in 80 columns and indentation fix).
Rather than trying to emulate `git commit --amend` using mercurial queues (which might have side effects if you're using MQ for other things) use the `commit --amend` command which was introduced in Mercurial 2.2 (2012-05-01).
Closes#4616
Changes the `plugins=(... mercurial ...)` to be closer to correct zsh syntax, removing commas and extra spaces.
Revises discussion on configuring themes to avoid sounding like users should modify the theme definition file in the main OMZ folder. Prioritizes the suggestion of using a theme which already supports hg_prompt_info.
If a user sets ZSH_THEME_HG_PROMPT_* as the following, he ends up with
%{$reset_color%} resetting the bold style of last character ")" because
_SUFFIX was expanded before calling hg_dirty():
ZSH_THEME_HG_PROMPT_PREFIX="%{$fg_bold[blue]%}hg:(%{$fg[white]%}"
ZSH_THEME_HG_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_HG_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_HG_PROMPT_CLEAN="%{$fg[blue]%})"
With this patch, the variable ZSH_THEME_HG_PROMPT_SUFFIX is lastly
displayed, following the same order as in git_prompt_info(),
i.e. <prefix><dirty><suffix>.
The original hgic and hgoc aliases worked well for the default path, but attempting to call them with a different path failed. I created functions to handle them instead.
implement in_hg(), hg_get_branch_name(), hg_prompt_info(), and hg_dirty() for the mercurial plugin
named functions similar to subversion plugin, to give theme maintainers an easier life
The -v flag for these commands really isn't very useful. It will
output some information about the hooks it is running, but that is
generally not useful and just noisy. The desire to add -v to these
commands is exceptional and IMHO it's better to make the common
case of not seeing those messages the supported behavior.