From d084af57318a98f5e3ff197e269f42611e5d2443 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 13 Apr 2021 13:56:31 +0000 Subject: [PATCH 2/2] vcs_info git docs: ahead/behind commits: Reduce the number of forks --- Misc/vcs_info-examples | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples index 065ea6cb3..ba94cca29 100644 --- a/Misc/vcs_info-examples +++ b/Misc/vcs_info-examples @@ -182,10 +182,14 @@ function +vi-git-st() { # Exit early in case the worktree is on a detached HEAD git rev-parse ${hook_com[branch]}@{upstream} >/dev/null 2>&1 || return 0 - ahead=$(git rev-list --count ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null) - (( $ahead )) && gitstatus+=( "+${ahead}" ) + local -a ahead_and_behind=( + $(git rev-list --left-right --count HEAD...${hook_com[branch]}@{upstream} 2>/dev/null) + ) - behind=$(git rev-list --count HEAD..${hook_com[branch]}@{upstream} 2>/dev/null) + ahead=${ahead_and_behind[1]} + behind=${ahead_and_behind[2]} + + (( $ahead )) && gitstatus+=( "+${ahead}" ) (( $behind )) && gitstatus+=( "-${behind}" ) hook_com[misc]+=${(j:/:)gitstatus}