Fast checking "Is this dir a hg repository?"
Simon King
simon at simonking.org.uk
Tue Nov 25 14:23:30 UTC 2014
On Tue, Nov 25, 2014 at 1:57 PM, Roman Inflianskas <infroma at gmail.com> wrote:
> On Tuesday 25 November 2014 00:35:19 Tynor Fujimoto wrote:
>> > On Nov 25, 2014, at 12:32 AM, Roman Inflianskas <infroma at gmail.com> wrote:
>> >
>> > Hi, all.
>> >
>> > I'm interested in writing custom prompt <https://github.com/bpinto/oh-my-fish/tree/master/themes/bobthefish> for fish shell <http://fishshell.com/> that displays current mercurial repository status (branch, is it dirty, etc.). What is the fastest way to check "Is this dir a hg repository?"?
>> >
>> > For now we are using checking for `.hg` directory (in the current directory and parents) to quickly filter all directories that are 100% not a repositories. If it contains `.hg` repository, we call `hg root --cwd $dir`. We need the first step because even such easy command as `hg root` work very slow compared with recursive search for `.hg` directory. Is there way to make it faster?
>> >
>> > Also, when the current directory is a home directory with `.hg` directory inside (or in any of its children directories) `hg` works just like it's a repository. `hg root` shows home directory and `hg status` lists all the files inside it. Of course it slows the shell dramatically. How can I process home directories correctly (that means I want to filter them out). Of course, it's easy to expand `~` and check string equivalence. But it's not enough, because root user (with home `/root`) can be inside `/home/user` directory. I don't know a fast and reliable way how to get all homes. Yes, I know about `/etc/passwd`. The problem is that there could be other sources like NIS, LDAP, etc.
>> >
>> > Here is PR <https://github.com/bpinto/oh-my-fish/pull/262> on GitHub that adds support for showing status of mercurial repositories for fish shell.
>> >
>> I just check for output on `hg branch`. Have you tried that?
>>
>> -T
>>
>>
> Of course I've tried this. How is it better, than `hg root`? It seems that it doesn't work faster, than `hg root`. Moreover, it shows no difference between home and repos:
> $ cd ~
> $ hg branch
> default
> $ cd repo
> $ hg branch
> default
>
I don't understand why you think there is a difference between home
and repos. If a ".hg" directory exists, the directory is a repository
as far as mercurial is concerned. (The .hg directory can even be
empty). If you don't want mercurial to treat the directory as a
repository, rename the .hg directory (or don't run mercurial in
there...).
As for speeding up "hg root", the only suggestion I have is to set
HGRCPATH to an empty string, and HGPLAIN=1. The first should prevent
mercurial from loading any extensions, which might speed it up a bit,
and the second should ensure that the output is always parseable
(probably not necessary in this instance, but good practice
generally).
Simon
More information about the Mercurial
mailing list