made the check for git version happen only once to save on time

This commit is contained in:
Alex Light 2012-01-27 11:34:08 -05:00
commit 6bd2afe1b8

View file

@ -6,7 +6,7 @@ function git_prompt_info() {
# Checks if working tree is dirty # Checks if working tree is dirty
parse_git_dirty() { parse_git_dirty() {
if $(is_legacy_git); then if [ "true" = "$IS_LEGACY_GIT" ]; then
echo $(parse_legacy_git_dirty) echo $(parse_legacy_git_dirty)
else else
echo $(parse_recent_git_dirty) echo $(parse_recent_git_dirty)
@ -15,21 +15,27 @@ parse_git_dirty() {
# echos the string 'true' if this git is old enough not to have --ignore-submodules # echos the string 'true' if this git is old enough not to have --ignore-submodules
# echos false otherwise # echos false otherwise
is_legacy_git() { get_is_legacy_git() {
checkit() { checkit() {
if [ $1 -gt 1 ]; then if [ $1 -gt 1 ]; then
echo false echo "false"
elif [ $1 -eq 1 -a $2 -gt 7 ]; then elif [ $1 -eq 1 -a $2 -gt 7 ]; then
echo false echo "false"
elif [ $1 -eq 1 -a $2 -eq 7 -a $3 -ge 2 ]; then elif [ $1 -eq 1 -a $2 -eq 7 -a $3 -ge 2 ]; then
echo false echo "false"
else else
echo true echo "true"
fi fi
} }
echo $(checkit $(git --version | cut -d " " -f 3 | tr '.' ' ')) echo $(checkit $(git --version | cut -d " " -f 3 | tr '.' ' '))
} }
#this is unlikely to change so make it all statically assigned
IS_LEGACY_GIT=$(get_is_legacy_git)
#clean up the namespace slightly by removing the checker function
unset -f get_is_legacy_git
# Checks if working tree is dirty when --ignore-submodules is not present # Checks if working tree is dirty when --ignore-submodules is not present
parse_legacy_git_dirty() { parse_legacy_git_dirty() {
if [[ -n $(git status --porcelain 2> /dev/null) ]]; then if [[ -n $(git status --porcelain 2> /dev/null) ]]; then