From 5d17b0508e7957b873301357157945bf2dfe2d42 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Wed, 6 May 2026 03:48:53 -0400 Subject: Use faster command to obtain stash count Using git-rev-list, we can directly return a count of stashes without the need for additional external calls like wc. As a result, the line_count helper function is now unused, so remove it. Signed-off-by: Matt Hunter --- git-sonar | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/git-sonar b/git-sonar index 06fcf1e..9fd3264 100755 --- a/git-sonar +++ b/git-sonar @@ -114,13 +114,6 @@ determine_default_branch() { done } -line_count() { - # macos 'wc' produces odd formatting (extra spaces) - # The grep is present to deal with this, filter out cases where the count - # is zero, and provide a return value (true if count is non-zero). - wc -l 2>/dev/null | grep -oE '[1-9][0-9]*' -} - print_commit_range() { if [ -n "$1" ] && [ -n "$2" ]; then ahead="$(git rev-list --count "${1}..${2}" 2>/dev/null)" || ahead="0" @@ -166,7 +159,8 @@ element_local() { element_stash() { if [ -n "$opt_stash" ]; then - if cnt="$(git stash list | line_count)"; then + cnt="$(git rev-list --walk-reflogs --ignore-missing --count refs/stash)" + if [ "$cnt" -ne 0 ]; then printf '%s%b%b' "$cnt" "$STASH_ICON" "$COLOR_DEF" fi fi -- cgit v1.2.3