From 997a59ff96dd5517aa8222a7e1387ee1d96b82e8 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Thu, 1 Feb 2018 19:56:27 +0500 Subject: [PATCH] Optimized gitinfo application and removed redundant calls. --- zsh/30-keys.zsh | 2 +- zsh/apps/gitinfo.app.zsh | 20 +++++--------------- zsh/prompts/pztrn.zsh | 1 - 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/zsh/30-keys.zsh b/zsh/30-keys.zsh index b7d6c28..5217e58 100644 --- a/zsh/30-keys.zsh +++ b/zsh/30-keys.zsh @@ -104,4 +104,4 @@ case "${TERM}" in bindkey '^[[1;5C' forward-word # ctrl right bindkey '^[[1;5D' backward-word # ctrl left ;; -esac +esac \ No newline at end of file diff --git a/zsh/apps/gitinfo.app.zsh b/zsh/apps/gitinfo.app.zsh index 2375981..577bf15 100644 --- a/zsh/apps/gitinfo.app.zsh +++ b/zsh/apps/gitinfo.app.zsh @@ -26,7 +26,6 @@ function gitinfo() gitinfo_get_info - gitinfo_check if [ $? -eq 0 ]; then echo "Git repository information:" echo "======================================================================" @@ -61,22 +60,10 @@ function gitinfo_check() GITINFO_TOPLEVEL_DIR=`git rev-parse --show-toplevel 2>/dev/null` if [ $? -ne 0 ]; then GITINFO_TOPLEVEL_DIR="" + log 1 "Failed to get git toplevel directory! (command 'git rev-parse --show-toplevel 2>/dev/null' failed)" return 1 fi - - 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 + log 1 "Git top directory: ${GITINFO_TOPLEVEL_DIR}" } ###################################################################### @@ -168,15 +155,18 @@ function gitinfo_get_untracked() function gitinfo_internal_checks() { if [ ${GITINFO_RECHECK} -eq 0 ]; then + error 1 "gitinfo_internal_checks() called without GITINFO_RECHECK=1, aborting" return 1 fi if [ ${#GITINFO_TOPLEVEL_DIR} -ne 0 ]; then objects=`ls ${GITINFO_TOPLEVEL_DIR}/.git/objects | grep -v "info\|index" | wc -l` if [ ${objects} -lt 1 ]; then + error 1 "Failed to get git objects directory members count!" return 1 fi else + log 1 "GITINFO_TOPLEVEL_DIR isn't specified." return 1 fi diff --git a/zsh/prompts/pztrn.zsh b/zsh/prompts/pztrn.zsh index 0868146..2fb9095 100644 --- a/zsh/prompts/pztrn.zsh +++ b/zsh/prompts/pztrn.zsh @@ -78,7 +78,6 @@ prompt_pztrn_gitinfo() gitinfo_check #echo $? if [[ $? -eq 0 ]]; then - gitinfo_get_info 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_remotes="$vars['brackets_start']%{$fg[green]%}${GITINFO_REMOTES} remote(s)$reset_color$vars['brackets_end']"