Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] New completion tag: __git_recent_branches
- X-seq: zsh-workers 38624
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] New completion tag: __git_recent_branches
- Date: Mon, 6 Jun 2016 08:42:21 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=i9B2AsxGwvZjj3eSLIuZEI5mmSUlnzt1XXMyxtn//4k=; b=MgalqNvWGRMhL5OIoMUJKNLzpGBp7IP8bkyFqrPWC927ObZw1eeiDkj/6ilOWJXJ+X FSX/dcsv+VWyhF0h4/Dosx5clN5kUcscQnr45uoBiwXPCoqd85HWXbo3pmJ38RHK+A3a 9xw7CGnCYUm+Ctnq0xu5qg9ahsYKwcakVZhUUbpkfzWbUDTsoGOOxek3g6R+MT0UnNoE izTRRMFjnD5AaOtSPTnMepu+CgUBjLqz4QxggEESceWCGtrB7JkdR6GFSiry/MCiwmxI lu8RhGo2PiKKitBp0Io/9F/29ToFZhmKrspJ6tgCRWlbozUiDhdQPoZan3+wIyEBggc/ 8iOw==
- In-reply-to: <20160603204049.GA22304@tarsus.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20160603204049.GA22304@tarsus.local2>
On Fri, Jun 03, 2016 at 08:40:49PM +0000, Daniel Shahaf wrote:
> # This function returns in $reply recently-checked-out refs' names, in order
> # from most to least recent.
> __git_recent_branches__names()
> {
> local -a reflog
> local reflog_subject
> local new_head
> local -A seen
> reply=()
>
> reflog=(${(ps:\0:)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs' 2>/dev/null)"})
> for reflog_subject in $reflog; do
> new_head=${${=reflog_subject}[4]}
>
> # Skip values added in previous iterations.
> if (( ${+seen[$new_head]} )); then
> continue
> fi
> seen[$new_head]="" # value is ignored
>
> # Filter out hashes, to leave only ref names.
> if [[ $new_head =~ '^[0-9a-f]{40}$' ]]; then
> continue
> fi
>
> # All checks passed. Add it.
> reply+=( $new_head )
> done
> }
reply=(${${(u)${${(0)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs')"}#checkout: moving from }%% *}:#[[:xdigit]](#c40)})
time (repeat 100; __git_recent_branches__names) uses about 4.32 seconds;
time (repeat 100; __git_recent_branches__names2) uses about 3.64
seconds on one of my more used repos.
Slight speed improvement for reduced readability. Although it does seem
to match _git's style better.
- Matthew Martin
Messages sorted by:
Reverse Date,
Date,
Thread,
Author