From: Marlon Richert <marlon.richert@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Remove redundancies from `git` completion
Date: Mon, 30 Aug 2021 14:17:17 +0300 [thread overview]
Message-ID: <CAHLkEDt9=VdVFqvvwUfXb8HBO_uxZAnaS7f_gtBTSHy_XLMWsg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 667 bytes --]
In _git-show, remove calls to __git_commits and __git_tags.
Rationale: 'commits' and 'tags' are already added by __git_trees.
Adding them twice makes `zstyle ... tag-order` give unexpected
results.
In __git_recent_commits, remove the line that adds 'heads'.
Rationale: The completion for most subcommands already adds
'heads-local' and 'heads-remote'. Adding an additional 'heads' inside
__git_recent_commits results in heads being listed twice in two
separate groups.
By the way: Why is there a `(( $+functions[_git-XXX] )) ||` statement
in front of each function inside Completion/Unix/Command/_git ? Can
those be removed?
Patch attached, below.
[-- Attachment #2: 0001-Remove-redundancies-from-git-completion.txt --]
[-- Type: text/plain, Size: 3742 bytes --]
From fcaa9f4b92b0e660f0c2789560251f456314d8af Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Mon, 30 Aug 2021 12:55:05 +0300
Subject: [PATCH] Remove redundancies from `git` completion
In _git-show, remove calls to __git_commits and __git_tags.
Rationale: 'commits' and 'tags' are already added by __git_trees.
Adding them twice makes `zstyle ... tag-order` give unexpected
results.
In __git_recent_commits, remove the line that adds 'heads'.
Rationale: The completion for most subcommands already adds
'heads-local' and 'heads-remote'. Adding an additional 'heads' inside
__git_recent_commits results in heads being listed twice in two
separate groups.
---
Completion/Unix/Command/_git | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index a82b70e83..569ca7a1e 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -685,8 +685,8 @@ _git-commit () {
# TODO: --interactive isn't explicitly listed in the documentation.
_arguments -S -s $endopt \
'(-a --all --interactive -o --only -i --include *)'{-a,--all}'[stage all modified and deleted paths]' \
- '--fixup=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
- '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
+ '--fixup=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_commit_objects_prefer_recent' \
+ '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_commit_objects_prefer_recent' \
$reset_author_opt \
'( --porcelain --dry-run)--short[dry run with short output format]' \
'--branch[show branch information]' \
@@ -1656,7 +1656,7 @@ _git-revert () {
'*'{-X,--strategy-option=}'[pass merge-strategy-specific option to merge strategy]:option' \
'(-S --gpg-sign --no-gpg-sign)'{-S-,--gpg-sign=-}'[GPG-sign the commit]::key id' \
"(-S --gpg-sign --no-gpg-sign)--no-gpg-sign[don't GPG-sign the commit]" \
- ': :__git_recent_commits'
+ ': :__git_commit_objects_prefer_recent'
}
(( $+functions[_git-rm] )) ||
@@ -1763,10 +1763,9 @@ _git-show () {
case $state in
(object)
_alternative \
- 'commits::__git_commits' \
- 'tags::__git_tags' \
- 'trees::__git_trees' \
- 'blobs::__git_blobs' && ret=0
+ 'trees::__git_trees' \
+ 'blobs::__git_blobs' \
+ && ret=0
;;
esac
@@ -6920,7 +6919,7 @@ __git_commit_objects () {
(( $+functions[__git_recent_commits] )) ||
__git_recent_commits () {
local gitdir expl start
- declare -a descr tags heads commits argument_array_names commit_opts
+ declare -a descr tags commits argument_array_names commit_opts
local h i j k ret
integer distance_from_head
local label
@@ -6985,11 +6984,8 @@ __git_recent_commits () {
j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
j=${j/ ->/,} # Convert " -> master, origin/master".
for j in ${(s:, :)j}; do
- if [[ $j == 'tag: '* ]] ; then
- tags+=( ${j#tag: } )
- else
- heads+=( $j )
- fi
+ [[ $j == 'tag: '* ]] &&
+ tags+=( ${j#tag: } )
done
done
@@ -6999,8 +6995,6 @@ __git_recent_commits () {
_describe -V -t commits 'recent commit object name' descr && ret=0
expl=()
_wanted commit-tags expl 'commit tag' compadd "$@" -a - tags && ret=0
- expl=()
- _wanted heads expl 'head' compadd -M "r:|/=* r:|=*" "$@" -a - heads && ret=0
return ret
}
--
2.33.0
next reply other threads:[~2021-08-30 11:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-30 11:17 Marlon Richert [this message]
2021-08-30 11:41 ` Mikael Magnusson
2021-08-30 12:34 ` Marlon Richert
2021-08-30 12:42 ` Mikael Magnusson
2021-08-31 5:52 ` Marlon Richert
2021-09-01 14:03 ` Daniel Shahaf
2021-09-01 18:22 ` Bart Schaefer
2021-09-02 6:17 ` Marlon Richert
2021-09-02 20:51 ` Oliver Kiddle
2021-09-02 20:54 ` Bart Schaefer
2021-09-02 21:17 ` Oliver Kiddle
2021-09-01 13:56 ` Daniel Shahaf
2021-09-02 8:57 ` Marlon Richert
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='CAHLkEDt9=VdVFqvvwUfXb8HBO_uxZAnaS7f_gtBTSHy_XLMWsg@mail.gmail.com' \
--to=marlon.richert@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).