Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Improve vcs_info example for ahead/behind git commits
- X-seq: zsh-workers 48528
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Tim Lee <progscriptclone@xxxxxxxxx>
- Cc: Lawrence Velázquez <larryv@xxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Improve vcs_info example for ahead/behind git commits
- Date: Tue, 13 Apr 2021 14:01:39 +0000
- Archived-at: <https://zsh.org/workers/48528>
- In-reply-to: <20210413115830.5wogi3e7dh2tthmw@localhost>
- List-id: <zsh-workers.zsh.org>
- References: <20210328213628.7rwz62bq5p2isd6b@home-guest> <20210329070611.GM18178@tarpaulin.shahaf.local2> <20210329093056.fegqam75id4yfkiq@home-guest> <ff17d1f9-d6ff-49bb-83d2-de0978ec61d4@www.fastmail.com> <20210329103927.qzky3fyevptfflvj@home-guest> <1b0343d9-87c2-4a0d-860f-30a390d7034d@www.fastmail.com> <87d2c775-18f3-4664-9a3f-de62f5b71777@www.fastmail.com> <20210413113441.GD6819@tarpaulin.shahaf.local2> <20210413115830.5wogi3e7dh2tthmw@localhost>
Tim Lee wrote on Tue, Apr 13, 2021 at 19:58:30 +0800:
> > Tim: Would you have time to address the remaining points from the
> > original review, https://zsh.org/workers/48306, either by implementing
> > them and sending a revised patch, or by counterarguing them?
>
> I think I'll just porpose something simple, since I'm not very familiar
> with ZSH.
>
> Patch:
Thanks, applied, and here's a patch series for implementing the other
outstanding points. Would you review it, please? See anything that
could go wrong, or that's missing?
Cheers,
Daniel
From 8a521515ce88802846df8884cabdd3966d0f32a8 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Tue, 13 Apr 2021 13:56:36 +0000
Subject: [PATCH 1/2] vcs_info git docs: ahead/behind commits: Don't run
rev-list when that would fail
---
Misc/vcs_info-examples | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index d33d0ceed..065ea6cb3 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -179,6 +179,9 @@ function +vi-git-st() {
local ahead behind
local -a gitstatus
+ # 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}" )
From d084af57318a98f5e3ff197e269f42611e5d2443 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
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}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author