Replace over use of grep/cut with sed or awk, globally reduce number of fossil call

This commit is contained in:
Étienne Deparis 2014-02-01 13:30:43 +01:00 committed by Olivier Mengué
parent fc5e045d34
commit edb4cb1dce

View File

@ -926,8 +926,8 @@ _lp_fossil_branch()
{ {
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return [[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
local branch local branch
branch="$(fossil status 2>/dev/null | grep tags: | cut -c17-)" branch=$(fossil status 2>/dev/null | sed -n "s/tags:[ ]*\(\w*\)$/\1/Ip")
if [[ -n "$branch" ]] ; then if [ -n "$branch" ]; then
_lp_escape "$branch" _lp_escape "$branch"
else else
if fossil info &>/dev/null ; then if fossil info &>/dev/null ; then
@ -951,76 +951,32 @@ _lp_fossil_branch_color()
local branch local branch
branch="$(_lp_fossil_branch)" branch="$(_lp_fossil_branch)"
if [[ -n "$branch" ]] ; then if [ -n "$branch" ]; then
local C2E # Modified files (added or edited) local C2E # Modified files (added or edited)
local C2D # Deleted files
local C2A # Extras files local C2A # Extras files
local C2AA # Added files
local PLUSLINE # Added lines
local MINUSLINE # Deleted lines
local ret local ret
C2E=$(fossil changes | wc -l) C2E=$(fossil changes | wc -l)
C2A=$(fossil extras | wc -l) C2A=$(fossil extras | wc -l)
PLUSLINE=$(fossil diff | egrep -c '^\+[^+].+$') ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}")
MINUSLINE=$(fossil diff | egrep -c '^-[^-].+$')
ret=""
C2AA=$(fossil changes | grep -c "ADDED") if [ "$C2E" -gt 0 ]; then
if [[ $C2AA -gt 0 ]] ; then if [ -n "$ret" ]; then
# We count the line "à la" git ret+=" in "
local ADDFILE fi
local FILE ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})"
ADDFILE=$(fossil changes | grep ADDED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2)
for FILE in $ADDFILE ; do
PLULI=$(wc -l < $FILE)
let PLUSLINE=$PLUSLINE+$PLULI
done
fi fi
if [[ $PLUSLINE -gt 0 ]] ; then if [ "$C2A" -gt 0 ]; then
ret+="+$PLUSLINE"
fi
C2D=$(fossil changes | grep -c "DELETED")
if [[ $C2D -gt 0 ]] ; then
# We count the line "à la" git
local DELFILE
local FILE
DELFILE=$(fossil changes | grep DELETED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2)
for FILE in $DELFILE ; do
MINLI=$(wc -l < $FILE)
let MINUSLINE=$MINUSLINE+$MINLI
done
fi
if [[ $MINUSLINE -gt 0 ]] ; then
if [[ "$ret" = "" ]] ; then
ret+="-$MINUSLINE"
else
ret+="/-$MINUSLINE"
fi
fi
if [[ "$C2E" -gt 0 ]] ; then
ret+=" in $C2E"
fi
if [[ "$C2A" -gt 0 ]] ; then
C2A="$LP_MARK_UNTRACKED" C2A="$LP_MARK_UNTRACKED"
else else
C2A="" C2A=""
fi fi
if [[ "$ret" != "" ]] ; then if [ "$branch" = "no-tag" ]; then
ret="(${LP_COLOR_DIFF}$ret${NO_COL})"
fi
if [[ "$branch" = "no-tag" ]] ; then
# Warning, your branch has no tag name ! # Warning, your branch has no tag name !
branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}" branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}"
else else
if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then if [ "$C2E" -eq 0 ]; then
# All is up-to-date # All is up-to-date
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}" branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
else else
@ -1028,7 +984,7 @@ _lp_fossil_branch_color()
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}" branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
fi fi
fi fi
_lp_escape "$branch" echo "$branch"
fi fi
} }