Fast checking "Is this dir a hg repository?"
Anton Shestakov
engored at gmail.com
Tue Nov 25 10:16:15 UTC 2014
2014-11-25 16:32 GMT+08:00 Roman Inflianskas <infroma at gmail.com>:
> Hi, all.
>
> I'm interested in writing custom prompt for fish shell that displays current
> mercurial repository status (branch, is it dirty, etc.). What is the fastest
> way to check "Is this dir a hg repository?"?
The fastest way to check if a directory tracked in mercurial is
probably to write a small C program for directory traversal. Second
best option is a shell script. This is what I'm currently using for my
bash prompt [1].
> 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?
I think there is, but I would guess that involves hacking mercurial.
If you'd like to try, welcome.
> 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.
Well, I don't know. Isn't it a repository? Don't you want to see it in
the prompt?
> `hg root` shows home directory and `hg status` lists all the
> files inside it. Of course it slows the shell dramatically.
Why not speed up the prompt function then (as opposed to making a
blacklist of directories). Use as less separate calls to `hg` command
as possible, maybe use a dedicated extension: hg-prompt. With the
extension, my shell takes less than 100ms for showing the prompt in a
small repository and about 115ms in local mercurial clone. Not ideal
still, but quite workable. Considering the amount of info you can get
out of it (there are screenshots on overview page of [1]).
There are more options to speed up shell prompts, as I've learned on
the #mercurial irc channel [2], so maybe try idling there too.
[1]: https://bitbucket.org/engored/dotfiles/src/tip/.bash_prompt?at=default#cl-42
[2]: http://mercurial.selenic.com/wiki/IRC
More information about the Mercurial
mailing list