From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13906 invoked by alias); 4 Nov 2015 17:25:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37062 Received: (qmail 11083 invoked from network); 4 Nov 2015 17:25:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-da-563a3d33d3e6 Date: Wed, 04 Nov 2015 17:15:26 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: git commit descriptions Message-id: <20151104171526.23978d9f@pwslap01u.europe.root.pri> In-reply-to: <20151013111001.20a547d5@pwslap01u.europe.root.pri> References: <20151013111001.20a547d5@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xK7rGtlZhBkvWiVgcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujAt3drEXrFOpWNlzjK2B8bVsFyMnh4SAicTzKxdYIWwxiQv3 1rN1MXJxCAksZZTYt/wjK4Qzg0ni1JW/jBDOVkaJF/O/s4C0sAioSmw/ANLCycEmYCgxddNs oCIODhEBbYn2j2IgYWEBFYk1/9rYQWxeAXuJe99/gm3jFHCQ+HDpDFirEFD82/2HYDX8AvoS V/9+YoK4yF5i5pUzjBC9ghI/Jt8DW8ssoCWxeVsTK4QtL7F5zVtmiDnqEjfu7mafwCg0C0nL LCQts5C0LGBkXsUomlqaXFCclJ5rpFecmFtcmpeul5yfu4kRErRfdzAuPWZ1iFGAg1GJh/cm o2WYEGtiWXFl7iFGCQ5mJRHeecpWYUK8KYmVValF+fFFpTmpxYcYpTlYlMR5Z+56HyIkkJ5Y kpqdmlqQWgSTZeLglGpg9OWv+e9dfEV70qfr4pwi6Rq9r745lUlv3X6yO0SHK5iT45nOn+ur pz07URE7q803ot3h7mmZrtYEtYUt8/K2nZvOMesvB0+KtsR3sfq2wxnmD08JWupnpwc9m2mv YsC05uZsLauAx+yG780E3C+/Of27x3Zx6wRT29Uaqgobmk+wTbRepfhTiaU4I9FQi7moOBEA nzi9AlYCAAA= On Tue, 13 Oct 2015 11:10:01 +0100 Peter Stephenson wrote: > Next bit of git completion output usability. > > Sometimes it would be useful to get a one-line summary of the > commit corresponding to what you're about to e.g. checkout. I have lots > of similarly named branches and seeing the commit at the head of each > branch would help me work out which one I want to checkout. I'm going to commit this in its latest form, below, even though I don't think it's the final word on the subject. It has no effect unless you set the style max-verbose. The reasons for committing it are (i) it encapsulates the mechanism for verbose descriptions which can be used whatever the final solution is (ii) I'm using it anyway (iii) it's more useful if it keeps getting updated as part of the script in the repository even if it's not final (iv) it allows other people to play with logic for getting verbose descriptions. pws diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index df7a7d9..61386bf 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -5004,6 +5004,33 @@ __git_is_in_middle_of_merge () { [[ -f $gitdir/MERGE_HEAD ]] } +(( $+functions[__git_describe_branch] )) || +__git_describe_branch () { + local __commits_in=$1 + local __tag=$2 + local __desc=$3 + shift 3 + + integer maxverbose + if zstyle -s :completion:$curcontext max-verbose maxverbose && + (( ${compstate[nmatches]} <= maxverbose )); then + local __c + local -a __commits + for __c in ${(P)__commits_in}; do + __commits+=("${__c}:${$(_call_program describe git log -1 --oneline $__c)//:/\\:}") + done + _describe -t $__tag $__desc __commits "$@" + else + local expl + _wanted $__tag expl $__desc compadd "$@" -a - $__commits_in + fi +} + +(( $+functions[__git_describe_commit] )) || +__git_describe_commit () { + __git_describe_branch $1 $2 $3 -M 'r:|/=**' "${(@)argv[4,-1]}" +} + # Completion Wrappers (( $+functions[__git_ignore_line] )) || @@ -5541,29 +5568,27 @@ __git_branch_names () { branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}) __git_command_successful $pipestatus || return 1 - _wanted branch-names expl branch-name compadd -M 'r:|/=**' "$@" -a - branch_names + __git_describe_commit branch_names branch-names 'branch name' "$@" } (( $+functions[__git_remote_branch_names] )) || __git_remote_branch_names () { - local expl declare -a branch_names branch_names=(${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/}) __git_command_successful $pipestatus || return 1 - _wanted remote-branch-names expl 'remote branch name' compadd -M 'r:|/=**' "$@" -a - branch_names + __git_describe_commit branch_names remote-branch-names 'remote branch name' "$@" } (( $+functions[__git_remote_branch_names_noprefix] )) || __git_remote_branch_names_noprefix () { - local expl declare -a heads branch_names=(${${${${(f)"$(_call_program remote-branch-refs-noprefix git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/}#*/}:#HEAD}) __git_command_successful $pipestatus || return 1 - _wanted remote-branch-names-noprefix expl 'remote branch name' compadd -M 'r:|/=**' "$@" -a - branch_names + __git_describe_commit branch_names remote-branch-names-noprefix 'remote branch name' "$@" } (( $+functions[__git_commit_objects_prefer_recent] )) || @@ -5603,7 +5628,7 @@ __git_heads () { (( $+functions[__git_heads_local] )) || __git_heads_local () { - local gitdir expl start + local gitdir declare -a heads heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)" refs/heads' 2>/dev/null)"}) @@ -5615,17 +5640,16 @@ __git_heads_local () { [[ -f $gitdir/refs/stash ]] && heads+=stash fi - _wanted heads-local expl "local head" compadd -M 'r:|/=**' "$@" -a - heads + __git_describe_commit heads heads-local "local head" "$@" } (( $+functions[__git_heads_remote] )) || __git_heads_remote () { - local gitdir expl start declare -a heads heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)" refs/remotes' 2>/dev/null)"}) - _wanted heads-remote expl "remote head" compadd -M 'r:|/=**' "$@" -a - heads + __git_describe_commit heads heads-remote "remote head" "$@" } (( $+functions[__git_commit_objects] )) ||