Optimized gitinfo application and removed redundant calls.

This commit is contained in:
Stanislav Nikitin 2018-02-01 19:56:27 +05:00
parent 86d4eab5d2
commit 997a59ff96
3 changed files with 6 additions and 17 deletions

View File

@ -26,7 +26,6 @@ function gitinfo()
gitinfo_get_info gitinfo_get_info
gitinfo_check
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Git repository information:" echo "Git repository information:"
echo "======================================================================" echo "======================================================================"
@ -61,22 +60,10 @@ function gitinfo_check()
GITINFO_TOPLEVEL_DIR=`git rev-parse --show-toplevel 2>/dev/null` GITINFO_TOPLEVEL_DIR=`git rev-parse --show-toplevel 2>/dev/null`
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
GITINFO_TOPLEVEL_DIR="" GITINFO_TOPLEVEL_DIR=""
log 1 "Failed to get git toplevel directory! (command 'git rev-parse --show-toplevel 2>/dev/null' failed)"
return 1 return 1
fi fi
log 1 "Git top directory: ${GITINFO_TOPLEVEL_DIR}"
if [ "${curdir/${GITINFO_TOPLEVEL_DIR}}" != "${curdir}" ]; then
GITINFO_RECHECK=1
gitinfo_internal_checks
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
else
GITINFO_RECHECK=0
return 1
fi
} }
###################################################################### ######################################################################
@ -168,15 +155,18 @@ function gitinfo_get_untracked()
function gitinfo_internal_checks() function gitinfo_internal_checks()
{ {
if [ ${GITINFO_RECHECK} -eq 0 ]; then if [ ${GITINFO_RECHECK} -eq 0 ]; then
error 1 "gitinfo_internal_checks() called without GITINFO_RECHECK=1, aborting"
return 1 return 1
fi fi
if [ ${#GITINFO_TOPLEVEL_DIR} -ne 0 ]; then if [ ${#GITINFO_TOPLEVEL_DIR} -ne 0 ]; then
objects=`ls ${GITINFO_TOPLEVEL_DIR}/.git/objects | grep -v "info\|index" | wc -l` objects=`ls ${GITINFO_TOPLEVEL_DIR}/.git/objects | grep -v "info\|index" | wc -l`
if [ ${objects} -lt 1 ]; then if [ ${objects} -lt 1 ]; then
error 1 "Failed to get git objects directory members count!"
return 1 return 1
fi fi
else else
log 1 "GITINFO_TOPLEVEL_DIR isn't specified."
return 1 return 1
fi fi

View File

@ -78,7 +78,6 @@ prompt_pztrn_gitinfo()
gitinfo_check gitinfo_check
#echo $? #echo $?
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
gitinfo_get_info
p_gitinfo_branch="$vars['brackets_start']$vars['usercolor']${GITINFO_BRANCH}$reset_color$vars['brackets_end']" p_gitinfo_branch="$vars['brackets_start']$vars['usercolor']${GITINFO_BRANCH}$reset_color$vars['brackets_end']"
p_gitinfo_commit="$vars['brackets_start']%{$fg[magenta]%}${GITINFO_COMMIT_SHORTID}$reset_color (%{$fg[cyan]%}${GITINFO_COMMIT_COUNT}$reset_color)$vars['brackets_end']" p_gitinfo_commit="$vars['brackets_start']%{$fg[magenta]%}${GITINFO_COMMIT_SHORTID}$reset_color (%{$fg[cyan]%}${GITINFO_COMMIT_COUNT}$reset_color)$vars['brackets_end']"
p_gitinfo_remotes="$vars['brackets_start']%{$fg[green]%}${GITINFO_REMOTES} remote(s)$reset_color$vars['brackets_end']" p_gitinfo_remotes="$vars['brackets_start']%{$fg[green]%}${GITINFO_REMOTES} remote(s)$reset_color$vars['brackets_end']"