1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-06 23:56:16 +02:00

48528/0002: vcs_info git docs: ahead/behind commits: Reduce the number of forks

This commit is contained in:
Daniel Shahaf 2021-04-13 13:56:31 +00:00
parent d9ac5916ba
commit c40a63ab67
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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}