5

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.

1
  • 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. Jun 9, 2012 at 22:41

1 Answer 1

3

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.

9
  • 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? Jun 9, 2012 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? Jun 9, 2012 at 3:29
  • 1
    Yes, sometimes it takes a few seconds to display my prompt after cding into a git repo. Jun 9, 2012 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 Jun 9, 2012 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. Jun 9, 2012 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .