Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to improve the performance of my fish prompt, and since my prompt includes my current git branch, I'm wondering if there may be a way to make it faster.

Right now I'm using git symbolic-ref HEAD | sed 's/refs\/heads\///', and when I first cd into a git repo, it sometimes hangs for a little while. I'm wondering if there is a known faster method, or how I could find out. Whenever I run time git symbolic-ref HEAD, it simply outputs 0.00 real.

share|improve this question
1  
Run strace -rtt -o git.strace git symbolic-ref HEAD to see where it's spending time. Or strace -f -rtt -o fish.strace 1234, where 1234 is the PID of your shell, to see where the prompt setting is spending time. –  Gilles Jun 9 '12 at 22:41
    
@Gilles Awesome. Thanks. –  mybuddymichael Jun 10 '12 at 3:02
add comment

1 Answer 1

up vote 2 down vote accepted

git symbolic-ref HEAD is as far as I know the fastest method, it basically just opens .git/HEAD and some config files (/etc/gitconfig, $HOME/.gitconfig and .git/config). If you are sure that the delay is caused by the git command it is probably due to some io delay.

If you want a faster method you have to read .git/HEAD yourself but I doubt that it will make things faster.

share|improve this answer
    
Sweet, thanks. I updated my question to reflect that I'm using sed to strip refs/heads. Is that likely to slow it down much? –  mybuddymichael Jun 9 '12 at 3:21
2  
@mybuddymichael i don't know fish but you should be able to strip the stuff from within your shell (at least with bash/zsh). Btw. what time region are we talking about? Multiple seconds? –  Ulrich Dangel Jun 9 '12 at 3:29
1  
Yes, sometimes it takes a few seconds to display my prompt after cding into a git repo. –  mybuddymichael Jun 9 '12 at 4:05
    
@mybuddymichael is this a network file system or do you change into a subdirectory/have a big directory layout? git has to recursively change directories and check for the .git/HEAD file. Anyway best guess is some kind of io delay –  Ulrich Dangel Jun 9 '12 at 4:10
    
Nope, this is simply cding into the top-level directory of a git project on my local drive. It's weird stuff, I know, but it only happens in git repos. –  mybuddymichael Jun 9 '12 at 20:26
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.