about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-13 13:56:31 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-20 22:34:34 +0000
commitc40a63ab673d270d7648b3d057e1c7c42cce73b6 (patch)
tree04e8e0a7b0606f4511b04e66d4568d9bad8c64f4
parentd9ac5916ba17889abf094c1ac45d88f431338d9c (diff)
downloadzsh-c40a63ab673d270d7648b3d057e1c7c42cce73b6.tar.gz
zsh-c40a63ab673d270d7648b3d057e1c7c42cce73b6.tar.xz
zsh-c40a63ab673d270d7648b3d057e1c7c42cce73b6.zip
48528/0002: vcs_info git docs: ahead/behind commits: Reduce the number of forks
-rw-r--r--ChangeLog3
-rw-r--r--Misc/vcs_info-examples10
2 files changed, 10 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index a7658fbcb..10447cccd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2021-04-20  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
+	* 48528/0002: Misc/vcs_info-examples: vcs_info git docs:
+	ahead/behind commits: Reduce the number of forks
+
 	* 48528/0001: Misc/vcs_info-examples: vcs_info git docs:
 	ahead/behind commits: Don't run rev-list when that would fail
 
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}