bash prompt: use bash builtins to find out current branch
commit3a43c4b5bd19528229ef36b28d648d5ac98f15f1
authorSZEDER Gábor <szeder@ira.uka.de>
Thu, 31 Mar 2011 21:41:18 +0000 (31 23:41 +0200)
committerSZEDER Gábor <szeder@ira.uka.de>
Mon, 24 Jun 2013 15:22:10 +0000 (24 17:22 +0200)
treee7674864945a9d030ab0528018538303e4b02a3a
parentb91b935f04e8dcb1cc9f247627fbd0346ce949f4
bash prompt: use bash builtins to find out current branch

__git_ps1() runs the '$(git symbolic-ref HEAD)' command substitution
to find out whether we are on a branch and to find out the name of
that branch.  This imposes the overhead of fork()ing a subshell and
fork()+exec()ing a git process.

Since HEAD is in most cases a single-line file and the symbolic ref
format is quite simple to recognize and parse, read and parse it using
only bash builtins, thereby sparing all that fork()+exec() overhead.
Don't display the git prompt if reading HEAD fails, because a readable
HEAD is required for a git repository.  HEAD can also be a symlink
symbolic ref (due to 'core.preferSymlinkRefs'), so use bash builtins
for reading HEAD only when HEAD is not a symlink.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
contrib/completion/git-prompt.sh