zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Martin <phy1729@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] New completion tag: __git_recent_branches
Date: Mon, 6 Jun 2016 08:42:21 -0500	[thread overview]
Message-ID: <20160606134221.GA30047@CptOrmolo.darkstar> (raw)
In-Reply-To: <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


  reply	other threads:[~2016-06-06 13:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 20:40 Daniel Shahaf
2016-06-06 13:42 ` Matthew Martin [this message]
2016-06-07 22:53   ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160606134221.GA30047@CptOrmolo.darkstar \
    --to=phy1729@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).