Merge branch 'refactor/hg-cleanup' into develop

Cleanup _lp_hg_branch_color implementation for improved speed.
This commit is contained in:
Olivier Mengué 2014-01-19 20:18:14 +01:00
commit dd9a024b48

View File

@ -827,32 +827,31 @@ _lp_hg_branch_color()
if [[ -n "$branch" ]] ; then if [[ -n "$branch" ]] ; then
local has_untracked local has_untracked
has_untracked=$(hg status 2>/dev/null | grep -c '\(^\?\)') has_untracked=
if [[ -z "$has_untracked" ]] ; then if hg status -u 2>/dev/null | grep -q '^\?' >/dev/null ; then
has_untracked=""
else
has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED" has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED"
fi fi
local has_commit # Count local commits waiting for a push
has_commit=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep -c '\(^changeset\:\)') local -i commits
if [[ -z "$has_commit" ]] ; then commits=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep -c '\(^changeset\:\)')
has_commit=0
fi
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then # Check if there is some uncommitted stuff
if [[ "$has_commit" -gt "0" ]] ; then if [[ -z "$(hg status --quiet -n)" ]] ; then
if (( commits > 0 )) ; then
# some commit(s) to push # 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 else
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push # nothing to commit or push
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}"
fi fi
else else
local has_lines local has_lines
has_lines=$(hg diff --stat 2>/dev/null | tail -n 1 | awk 'FS=" " {printf("+%s/-%s\n", $4, $6)}') # Parse the last line of the diffstat-style output
if [[ "$has_commit" -gt "0" ]] ; then has_lines="$(hg diff --stat 2>/dev/null | sed -n '$ s!^.*, \([0-9]*\) .*, \([0-9]*\).*$!+\1/-\2!p')"
if (( commits > 0 )) ; then
# Changes to commit and commits to push # 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 else
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit
fi fi