Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no
	version=3.4.1
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==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to
         :references:mime-version:content-disposition:in-reply-to:user-agent;
        bh=i9B2AsxGwvZjj3eSLIuZEI5mmSUlnzt1XXMyxtn//4k=;
        b=K3Yi0v1hs2AzZepHTVN8lr1qLMv7eY2MmunY3+HXhKsfP6qNqXOf5bMC0JfllbrLtR
         m/2UnbK92vplnBrzqrcU7QYCzyaYq3l+wgrEf/TjJZlkuPbdYt9enR20qKtU0IOBuvNr
         lLz1NmoWBfe0QrjTiBiL5U7cApyG14ibtCzmGMItKzalDCIBc4dTTbsEL7GX2An2PBz6
         L2ezbtJ6V/xic+RjDW2RqJ0itTThZGj8QogGy3kjQouxwt6gssmMMWc4KTol1fo1Vo6/
         pK0hvKNloqgl2g727ZedO0su6YBNItuY+Wg1uzssQHNuJ569JDbcp8IPOdAHrVoYZVHz
         AXAA==
X-Gm-Message-State: ALyK8tKZvnysU4MpxjBKyf+P9uNpprZVYZKJFmTpbUJNcwBV1DXbZDdWviQzBS8hzj/BqQ==
X-Received: by 10.157.46.9 with SMTP id q9mr8313099otb.58.1465220555683;
        Mon, 06 Jun 2016 06:42:35 -0700 (PDT)
Date: Mon, 6 Jun 2016 08:42:21 -0500
From: Matthew Martin <phy1729@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] New completion tag: __git_recent_branches
Message-ID: <20160606134221.GA30047@CptOrmolo.darkstar>
Mail-Followup-To: zsh-workers@zsh.org
References: <20160603204049.GA22304@tarsus.local2>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20160603204049.GA22304@tarsus.local2>
User-Agent: Mutt/1.6.1 (2016-04-27)
X-Seq: zsh-workers 38624

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

