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 48311
- From: Tim Lee <progscriptclone@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Improve vcs_info example for ahead/behind git commits
- Date: Mon, 29 Mar 2021 17:30:56 +0800
- Archived-at: <https://zsh.org/workers/48311>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/20210329093056.fegqam75id4yfkiq%40home-guest>
- In-reply-to: <20210329070611.GM18178@tarpaulin.shahaf.local2>
- List-id: <zsh-workers.zsh.org>
- References: <20210328213628.7rwz62bq5p2isd6b@home-guest> <20210329070611.GM18178@tarpaulin.shahaf.local2>
> > * Remove unnecessary use of `${hook_com[branch]}` because `@{upstream}`
> > defaults to the current branch when no branch name is provided.
> > `@{upstream}` was introduced in git 1.7.0
> > (https://github.com/git/git/commit/28fb84382b0eb728534dbe2972bbfec3f3d83dd9)
>
> I'm not sure that's unnecessary, for two reasons:
>
> 1. hook_com[branch], as opposed to hook_com[branch_orig], may have been
> changed by a previous hook.
>
> 2. There may be educational value to demonstrating a use of
> hook_com[branch], even if it's implied.
>
> WDYT?
Okay. I was not aware of these reasons. I am still very much a beginner
(both to zsh and to mailing lists ...).
> > diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
> > index 94b8a7b5e..36d4d3bf8 100644
> > --- a/Misc/vcs_info-examples
> > +++ b/Misc/vcs_info-examples
> > @@ -179,14 +179,18 @@ function +vi-git-st() {
> > local ahead behind
> > local -a gitstatus
> >
> > - # for git prior to 1.7
> > + # for git prior to 1.7.0
> > # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
> > - ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
> > + # for git 1.7.0 and 1.7.1
> > + # ahead=$(git rev-list @{upstream}..HEAD 2>/dev/null | wc -l)
> > + ahead=$(git rev-list --count @{upstream}..HEAD 2>/dev/null)
> > (( $ahead )) && gitstatus+=( "+${ahead}" )
>
> The version of this function in my zshrc starts like this:
> .
> git rev-parse @{upstream} >/dev/null 2>&1 || return 0
> local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) )
The snippet below displays N/M. How would you make it display +N/-M
instead?
git rev-parse @{upstream} >/dev/null 2>&1 || return 0
local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) )
hook_com[misc]="${(j:/:)x}"
> The first line is to handle a detached HEAD, I think, and should
> presumably be added?
Why not do this instead:
local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null ) )
---
Note: when replying to my email, please ensure that my email address is
included in the 'To:' field, since I am not subscribed to the mailing
list.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author