diff options
author | SZEDER Gábor <szeder@ira.uka.de> | 2013-06-24 02:16:02 +0200 |
---|---|---|
committer | SZEDER Gábor <szeder@ira.uka.de> | 2013-06-24 18:03:30 +0200 |
commit | e3e0b9378b6e51ea50c023d92d4d2a1f4d4cc676 (patch) | |
tree | 69ccf36e7901ea42488bb5f2682802fcf04a493b /prompt.h | |
parent | bash prompt: combine 'git rev-parse' executions in the main code path (diff) | |
download | tgif-e3e0b9378b6e51ea50c023d92d4d2a1f4d4cc676.tar.xz |
bash prompt: combine 'git rev-parse' for detached head
When describing a detached HEAD according to the $GIT_PS1_DESCRIBE
environment variable fails, __git_ps1() now runs the '$(git rev-parse
--short HEAD)' command substitution to get the abbreviated detached
HEAD commit object name. This imposes the overhead of fork()ing a
subshell and fork()+exec()ing a git process.
Avoid this overhead by combining this command substitution with the
"main" 'git rev-parse' execution for getting the path to the .git
directory & co. This means that we'll look for the abbreviated commit
object name even when it's not necessary, because we're on a branch or
the detached HEAD can be described. It doesn't matter, however,
because once 'git rev-parse' is up and running to fulfill all those
other queries, the additional overhead of looking for the abbreviated
commit object name is not measurable because it's lost in the noise.
There is a caveat, however, when we are on an unborn branch, because
in that case HEAD doesn't point to a valid commit, hence the query for
the abbreviated commit object name fails. Therefore, '--short HEAD'
must be the last options to 'git rev-parse' in order to get all the
other necessary information for the prompt even on an unborn branch.
Furthermore, in that case, and in that case only, 'git rev-parse'
doesn't output the last line containing the abbreviated commit object
name, obviously, so we have to take care to only parse it if 'git
rev-parse' exited without any error.
Although there are tests already excercising __git_ps1() on unborn
branches, they all do so implicitly. Add a test that checks this
explicitly.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Diffstat (limited to 'prompt.h')
0 files changed, 0 insertions, 0 deletions