Fast checking "Is this dir a hg repository?"

Roman Inflianskas infroma at gmail.com
Tue Nov 25 08:32:48 UTC 2014


Hi, all.

I'm interested in writing custom prompt[1] for fish shell[2]  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[3] on GitHub that adds support for showing status of mercurial repositories for fish shell.

-- 
Regards, Roman Inflianskas

--------
[1] https://github.com/bpinto/oh-my-fish/tree/master/themes/bobthefish
[2] http://fishshell.com/
[3] https://github.com/bpinto/oh-my-fish/pull/262
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial/attachments/20141125/7a6c3569/attachment.html>


More information about the Mercurial mailing list