hg: refactor outgoing commits counting
Rename variable 'has_commit' to 'commits' and declare it as integer.
This commit is contained in:
parent
35e39d8b50
commit
4955326aa5
16
liquidprompt
16
liquidprompt
@ -832,25 +832,23 @@ _lp_hg_branch_color()
|
||||
has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED"
|
||||
fi
|
||||
|
||||
local has_commit
|
||||
has_commit=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep -c '\(^changeset\:\)')
|
||||
if [[ -z "$has_commit" ]] ; then
|
||||
has_commit=0
|
||||
fi
|
||||
# Count local commits waiting for a push
|
||||
local -i commits
|
||||
commits=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep -c '\(^changeset\:\)')
|
||||
|
||||
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then
|
||||
if [[ "$has_commit" -gt "0" ]] ; then
|
||||
if (( commits > 0 )) ; then
|
||||
# some commit(s) to push
|
||||
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}"
|
||||
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$commits${NO_COL})${has_untracked}${NO_COL}"
|
||||
else
|
||||
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push
|
||||
fi
|
||||
else
|
||||
local has_lines
|
||||
has_lines=$(hg diff --stat 2>/dev/null | tail -n 1 | awk 'FS=" " {printf("+%s/-%s\n", $4, $6)}')
|
||||
if [[ "$has_commit" -gt "0" ]] ; then
|
||||
if (( commits > 0 )) ; then
|
||||
# Changes to commit and commits to push
|
||||
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}"
|
||||
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$commits${NO_COL})${has_untracked}${NO_COL}"
|
||||
else
|
||||
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user