Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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


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.
From fcaa9f4b92b0e660f0c2789560251f456314d8af Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@xxxxxxxxxxxxxxxxxxxxxxxx>
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



Messages sorted by: Reverse Date, Date, Thread, Author