zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Remove redundancies from `git` completion
@ 2021-08-30 11:17 Marlon Richert
  2021-08-30 11:41 ` Mikael Magnusson
  2021-09-01 13:56 ` Daniel Shahaf
  0 siblings, 2 replies; 13+ messages in thread
From: Marlon Richert @ 2021-08-30 11:17 UTC (permalink / raw)
  To: Zsh hackers list

[-- 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-09-02 21:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 11:17 [PATCH] Remove redundancies from `git` completion Marlon Richert
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

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).