zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] improved git completion
@ 2008-01-24 18:47 Dominik Vogt
  2008-01-24 23:12 ` Jörg Sommer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Dominik Vogt @ 2008-01-24 18:47 UTC (permalink / raw)
  To: Zsh Workers

[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]

Attached to this message you can find a series of patches to the
git completion file (installed as
/usr/share/zsh/4.3.2/functions/Completion/Unix/_git, no idea where
it lives in the source tree).  The five patches are base upon each
other and need to be applied in order.  I've split them up for
better readability.

0001*

  Removes trailing whitespace from the file.

0002*

  Fixes a syntax error in the completion code for git-clone.  Also
  replaces $* with $@ in some places and fixes a TODO in
  _git-rev-list.

0003*

  Adds completion of generic git options like "git --git-dir"

0004*

  Ports bash's completion code for heads, tags, branches etc. to
  zsh.  This code is *much* faster because is does not depend on
  the git-ls-remote command, does not require a network connection
  (for the same reason) and also properly handles the --git-dir
  argument as well as the GIT_DIR environment variable (for all
  git commands).

  Finally it rewrites the completion code of git-branch completely
  so that it works in all modes (list/create/delete/move
  branches).

Ciao

Dominik ^_^  ^_^

-- 
Dominik Vogt

[-- Attachment #2: 0001-removed-trailing-whitespace.patch --]
[-- Type: text/x-diff, Size: 1251 bytes --]

>From 565a6553c2612a041c6a8b8e71fb1789938490e2 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <dvogt@ffm.tc.iot.dtag.de>
Date: Wed, 23 Jan 2008 08:53:41 +0100
Subject: [PATCH] removed trailing whitespace

---
 _git |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/_git b/_git
index 7b76d5a..0a6cebf 100644
--- a/_git
+++ b/_git
@@ -3,8 +3,8 @@
 # Commands not completed:
 # git-sh-setup
 # git-shell
-# git-parse-remote 
-# git-rev-parse 
+# git-parse-remote
+# git-rev-parse
 
 # TODO: most commands need a valid git repository to run, so add a check for it
 # so that we can make our handling a little bit cleaner (need to deal with
@@ -544,7 +544,7 @@ _git-verify-pack () {
     '-v[show objects contained in pack]' \
     '*:index file:_files -g "*.idx"' && ret=0
 }
- 
+
 __git-clone_or_fetch-pack () {
   _arguments \
     $exec_arg \
@@ -1220,7 +1220,7 @@ _remote_files () {
     while _tags; do
       while _next_label files expl ${suf:-remote directory}; do
 #        [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
-#	    ${(q)remdispf%[*=@|]} && ret=0 
+#	    ${(q)remdispf%[*=@|]} && ret=0
 	compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
 	    ${(q)remdispd%/} && ret=0
       done
-- 
1.5.3.5.GIT


[-- Attachment #3: 0002-Fixed-syntax-error-in-git-clone-completion.patch --]
[-- Type: text/x-diff, Size: 2389 bytes --]

>From 247eef0799cba3938f59d746830ef108d277acb6 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <dvogt@ffm.tc.iot.dtag.de>
Date: Wed, 23 Jan 2008 08:54:03 +0100
Subject: [PATCH] Fixed syntax error in git-clone completion

Fixed a todo and cleanup.
---
 _git |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/_git b/_git
index 0a6cebf..6677bac 100644
--- a/_git
+++ b/_git
@@ -488,7 +488,6 @@ _git-name-rev () {
     '(--stdin --all)*:commit-ish:__git_revisions' && ret=0
 }
 
-# TODO: --no-merges undocumented
 _git-rev-list () {
   if (( $words[(I)--] && $words[(I)--] != CURRENT )); then
     _arguments \
@@ -507,6 +506,7 @@ _git-rev-list () {
       '--max-count[maximum number of commits to output]: :_guard "[[\:digit\:]]#" timestamp' \
       '(--topo-order)--merge-order[decompose into minimal and maximal epochs]' \
       '--min-age[minimum age of commits to output]: :_guard "[[\:digit\:]]#" timestamp' \
+      '--no-merges[do not print commits with more than one parent]'
       '--parents[show parent commits]' \
       '(--header)'$pretty_arg \
       '(--dense)--sparse[when paths are given, output only commits that changes any of them]' \
@@ -726,7 +726,7 @@ _git-clone () {
 
   _arguments \
     '(-l --local)'{-l,--local}'[perform a local cloning of a repository]' \
-    $shared
+    $shared \
     '(-q --quiet)'{-q,--quiet}'[operate quietly]' \
     '-n[do not checkout HEAD after clone is complete]' \
     '(-u --upload-pack)'{-u,--uploadpack}'[specify path to git-upload-pack on remote side]:remote path' \
@@ -1138,23 +1138,23 @@ __git_guard () {
 }
 
 __git_objects () {
-  __git_guard $* "[[:xdigit:]]#" "object"
+  __git_guard $@ "[[:xdigit:]]#" "object"
 }
 
 __git_trees () {
-  __git_guard $* "[[:xdigit:]]#" "tree"
+  __git_guard $@ "[[:xdigit:]]#" "tree"
 }
 
 __git_tree_ishs () {
-  __git_guard $* "[[:xdigit:]]#" "tree-ish"
+  __git_guard $@ "[[:xdigit:]]#" "tree-ish"
 }
 
 __git_blobs () {
-  _git_guard $* "[[:xdigit:]]#" 'blob id'
+  _git_guard $@ "[[:xdigit:]]#" 'blob id'
 }
 
 __git_stages () {
-  __git_guard $* "[[:digit:]]#" 'stage'
+  __git_guard $@ "[[:digit:]]#" 'stage'
 }
 
 __git_files () {
@@ -1189,7 +1189,7 @@ __git_commits () {
 
 # TODO: deal with prefixes and suffixes listed in git-rev-parse
 __git_revisions () {
-  __git_commits $*
+  __git_commits
 }
 
 __git_commits2 () {
-- 
1.5.3.5.GIT


[-- Attachment #4: 0003-Add-completion-of-git-options.patch --]
[-- Type: text/x-diff, Size: 13429 bytes --]

>From 12950b7b976a85e6d60a2df4213b98a50e5696c6 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <dvogt@ffm.tc.iot.dtag.de>
Date: Wed, 23 Jan 2008 12:44:54 +0100
Subject: [PATCH] Add completion of git options.

---
 _git |  214 ++++++++++++++++++++++++++++++++++--------------------------------
 1 files changed, 111 insertions(+), 103 deletions(-)

diff --git a/_git b/_git
index 6677bac..6f6e82d 100644
--- a/_git
+++ b/_git
@@ -76,116 +76,124 @@ tags_fetch_arg=('(-t --tags)'{-t,--tags}'[fetch remote tags]')
 
 # TODO: either skip uninteresting commands or skip the description - the list
 # is just too long
-_git_commands () {
-  local -a commands
-
-  commands=(
-    'add:add paths to the index'
-    'am:apply patches from a mailbox (cooler than applymbox)'
-    'apply:apply patch on a git index file and a work tree'
-    'applymbox:apply patches from a mailbox'
-    'applypatch:apply one patch extracted from an e-mail'
-    'archimport:import an Arch repository into git'
-    'bisect:find the change that introduced a bug'
-    'branch:create and show branches'
-    'cat-file:provide content or type information for repository objects'
-    'check-ref-format:makes sure that a reference-name is well formed'
-    'checkout:checkout and switch to a branch'
-    'checkout-index:copy files from the index to the working directory'
-    'cherry:find commits not merged upstream'
-    'cherry-pick:cherry-pick the effect of an existing commit'
-    'clone:clones a repository into a new directory'
-    'clone-pack:clones a repository into the current repository (transport)'
-    'commit:record changes to the repository'
-    'commit-tree:creates a new commit object'
-    'convert-objects:converts old-style git repository'
-    'count-objects:count unpacked objects and display their disk consumption'
-    'cvsimport:import a CVS "repository" into a git repository'
-    'daemon:starts a really simple server for git repositories'
-    'diff:show changes between commits, commit and working tree, etc.'
-    'diff-files:compares files in the working tree and the index'
-    'diff-index:compares content and mode of blobs between index and repository'
-    'diff-stages:compares two "merge states" in the index file'
-    'diff-tree:compares the content and mode of blobs found via two tree objects'
-    'fetch:download objects and a head from another repository'
-    'fetch-pack:receive missing objects from another repository'
-    'format-patch:prepare patches for e-mail submission'
-    'fsck-objects:verifies the connectivity and validity of the objects in the database'
-    'get-tar-commit-id:extract commit ID from an archive created using tar-tree'
-    'grep:print lines matching a pattern'
-    'hash-object:computes the object ID from a file'
-    'http-fetch:downloads a remote git repository via HTTP'
-    'index-pack:build pack index file for an existing packed archive'
-    'init-db:creates an empty git object database'
-    'local-fetch:duplicates another git repository on a local system'
-    'log:shows commit logs'
-    'lost-found:recovers lost references that luckily have not yet been pruned'
-    'ls-files:information about files in the index/working directory'
-    'ls-remote:shows references in a remote or local repository'
-    'ls-tree:displays a tree object in human-readable form'
-    'mailinfo:extracts patch from a single e-mail message'
-    'mailsplit:splits an mbox file into a list of files'
-    'merge:grand unified merge driver'
-    'merge-base:finds a good common ancestor as possible for a merge'
-    'merge-index:runs a merge for files needing merging'
-    'merge-one-file:standard helper-program to use with merge-index'
-    'mktag:creates a tag object'
-    'mv:moves or renames a file, directory, or symlink'
-    'name-rev:find symbolic names for given revisions'
-    'octopus:merges more than two commits'
-    'pack-objects:creates a packed archive of objects'
-    'parse-remote:routines to help parsing $GIT_DIR/remotes/'
-    'patch-id:computes unique ID for a apatch'
-    'peek-remote:lists references on a remote repository using the upload-pack protocol'
-    'prune:prunes all unreachable objects from the object database'
-    'prune-packed:removes extra objects that are already in pack files'
-    'pull:fetch from and merge with a remote repository'
-    'push:update remote refs along with associated objects'
-    'read-tree:reads tree information into the directory index'
-    'rebase:rebases local commits to new upstream head'
-    'receive-pack:command invoked by send-pack to receive what is pushed to it'
-    'relink:hardlinks acommon objects in local repositories'
-    'repack:packs unpacked objects in a repository'
-    'request-pull:generates a summary of pending changes'
-    'reset:resets current HEAD to the specified state'
-    'resolve:merges two commits'
-    'rev-list:lists commit object in reverse chronological order'
-    'rev-parse:picks out and massages parameters for other git commands'
-    'revert:reverts an existing commit'
-    'send-email:sends patch-e-mails out of "format-patch --mbox" output'
-    'send-pack:pushes to a remote repository, intelligently'
-    'shortlog:summarizes git log output'
-    'show-branch:shows branches and their commits'
-    'show-index:displays contents of a pack idx file'
-    'ssh-fetch:pulls from a remote repository over an SSH connection'
-    'ssh-upload:helper "server-side" program used by ssh-fetch'
-    "status:shows the working-tree's status"
-    'stripspace:filters out empty lines'
-    'svnimport:imports a SVN repository into git'
-    'symbolic-ref:reads and modifies symbolic references'
-    'tag:creates a tag object signed with GPG'
-    'tar-tree:creates a tar archive of the files in the named tree'
-    "unpack-file:creates a temporary file with a blob's contents"
-    'unpack-objects:unpacks objects out of a packed archive'
-    'update-index:modifies the index in some given way'
-    'update-ref:updates the object name stored in a reference safely'
-    'update-server-info:updates auxiliary information on a dumb server'
-    'upload-pack:command invoked by clone-pack and fetch-pack'
-    'var:displays a git logical variable'
-    'verify-pack:validates packed git archive files'
-    'verify-tag:checks the GPG signature of a tag'
-    'whatchanged:shows commit-logs and differences they introduce'
-    'write-tree:creates a tree from the current index')
-
-  _describe -t commands 'git command' commands && ret=0
+_git_command_options () {
+  _values 'gitoptions' \
+    '--git-dir[path to repository]:git dir:_directories' \
+    '--exec-path[path to git core files]:git core dir:_directories' \
+    '--work-tree[path to the working tree]:work dir:_directories' \
+    '--bare[treat repository as bare]' \
+    '--help[print help]' \
+    '(-p --paginate)'{-p,--paginate}'[pipe all output into less]' \
+    '--no-pager[do not pipe output into a pager]' \
+    '--version[print git version]' \
+    'add[add paths to the index]' \
+    'am[apply patches from a mailbox (cooler than applymbox)]' \
+    'apply[apply patch on a git index file and a work tree]' \
+    'applymbox[apply patches from a mailbox]' \
+    'applypatch[apply one patch extracted from an e-mail]' \
+    'archimport[import an Arch repository into git]' \
+    'bisect[find the change that introduced a bug]' \
+    'branch[create and show branches]' \
+    'cat-file[provide content or type information for repository objects]' \
+    'check-ref-format[makes sure that a reference-name is well formed]' \
+    'checkout[checkout and switch to a branch]' \
+    'checkout-index[copy files from the index to the working directory]' \
+    'cherry[find commits not merged upstream]' \
+    'cherry-pick[cherry-pick the effect of an existing commit]' \
+    'clone[clones a repository into a new directory]' \
+    'clone-pack[clones a repository into the current repository (transport)]' \
+    'commit[record changes to the repository]' \
+    'commit-tree[creates a new commit object]' \
+    'convert-objects[converts old-style git repository]' \
+    'count-objects[count unpacked objects and display their disk consumption]' \
+    'cvsimport[import a CVS "repository" into a git repository]' \
+    'daemon[starts a really simple server for git repositories]' \
+    'diff[show changes between commits, commit and working tree, etc.]' \
+    'diff-files[compares files in the working tree and the index]' \
+    'diff-index[compares content and mode of blobs between index and repository]' \
+    'diff-stages[compares two "merge states" in the index file]' \
+    'diff-tree[compares the content and mode of blobs found via two tree objects]' \
+    'fetch[download objects and a head from another repository]' \
+    'fetch-pack[receive missing objects from another repository]' \
+    'format-patch[prepare patches for e-mail submission]' \
+    'fsck-objects[verifies the connectivity and validity of the objects in the database]' \
+    'get-tar-commit-id[extract commit ID from an archive created using tar-tree]' \
+    'grep[print lines matching a pattern]' \
+    'hash-object[computes the object ID from a file]' \
+    'http-fetch[downloads a remote git repository via HTTP]' \
+    'index-pack[build pack index file for an existing packed archive]' \
+    'init-db[creates an empty git object database]' \
+    'local-fetch[duplicates another git repository on a local system]' \
+    'log[shows commit logs]' \
+    'lost-found[recovers lost references that luckily have not yet been pruned]' \
+    'ls-files[information about files in the index/working directory]' \
+    'ls-remote[shows references in a remote or local repository]' \
+    'ls-tree[displays a tree object in human-readable form]' \
+    'mailinfo[extracts patch from a single e-mail message]' \
+    'mailsplit[splits an mbox file into a list of files]' \
+    'merge[grand unified merge driver]' \
+    'merge-base[finds a good common ancestor as possible for a merge]' \
+    'merge-index[runs a merge for files needing merging]' \
+    'merge-one-file[standard helper-program to use with merge-index]' \
+    'mktag[creates a tag object]' \
+    'mv[moves or renames a file, directory, or symlink]' \
+    'name-rev[find symbolic names for given revisions]' \
+    'octopus[merges more than two commits]' \
+    'pack-objects[creates a packed archive of objects]' \
+    'parse-remote[routines to help parsing $GIT_DIR/remotes/]' \
+    'patch-id[computes unique ID for a apatch]' \
+    'peek-remote[lists references on a remote repository using the upload-pack protocol]' \
+    'prune[prunes all unreachable objects from the object database]' \
+    'prune-packed[removes extra objects that are already in pack files]' \
+    'pull[fetch from and merge with a remote repository]' \
+    'push[update remote refs along with associated objects]' \
+    'read-tree[reads tree information into the directory index]' \
+    'rebase[rebases local commits to new upstream head]' \
+    'receive-pack[command invoked by send-pack to receive what is pushed to it]' \
+    'relink[hardlinks acommon objects in local repositories]' \
+    'repack[packs unpacked objects in a repository]' \
+    'request-pull[generates a summary of pending changes]' \
+    'reset[resets current HEAD to the specified state]' \
+    'resolve[merges two commits]' \
+    'rev-list[lists commit object in reverse chronological order]' \
+    'rev-parse[picks out and massages parameters for other git commands]' \
+    'revert[reverts an existing commit]' \
+    'send-email[sends patch-e-mails out of "format-patch --mbox" output]' \
+    'send-pack[pushes to a remote repository, intelligently]' \
+    'shortlog[summarizes git log output]' \
+    'show-branch[shows branches and their commits]' \
+    'show-index[displays contents of a pack idx file]' \
+    'ssh-fetch[pulls from a remote repository over an SSH connection]' \
+    'ssh-upload[helper "server-side" program used by ssh-fetch]' \
+    "status[shows the working-tree's status]" \
+    'stripspace[filters out empty lines]' \
+    'svnimport[imports a SVN repository into git]' \
+    'symbolic-ref[reads and modifies symbolic references]' \
+    'tag[creates a tag object signed with GPG]' \
+    'tar-tree[creates a tar archive of the files in the named tree]' \
+    "unpack-file[creates a temporary file with a blob's contents]" \
+    'unpack-objects[unpacks objects out of a packed archive]' \
+    'update-index[modifies the index in some given way]' \
+    'update-ref[updates the object name stored in a reference safely]' \
+    'update-server-info[updates auxiliary information on a dumb server]' \
+    'upload-pack[command invoked by clone-pack and fetch-pack]' \
+    'var[displays a git logical variable]' \
+    'verify-pack[validates packed git archive files]' \
+    'verify-tag[checks the GPG signature of a tag]' \
+    'whatchanged[shows commit-logs and differences they introduce]' \
+    'write-tree[creates a tree from the current index]' && ret=0
 }
 
 # TODO: this needs to be cleaned up and fixed
 local curcontext=$curcontext ret=1
+local first=1
 
 if [[ $words[1] == git ]]; then
+  while [[ $#words -ge 3 && $words[2] == -* ]]; do
+    compset -n 2
+  done
   if (( CURRENT == 2 )); then
-    _git_commands
+    _git_command_options
   else
     shift words
     (( CURRENT-- ))
-- 
1.5.3.5.GIT


[-- Attachment #5: 0004-ported-completion-of-remote-heads-and-tags-from-bash.patch --]
[-- Type: text/x-diff, Size: 7000 bytes --]

>From e5f00906cf7c8644500ad1eff39ad7f70be9d103 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <dvogt@ffm.tc.iot.dtag.de>
Date: Wed, 23 Jan 2008 13:02:49 +0100
Subject: [PATCH] ported completion of remote heads and tags from bash

also handle --git-dir= option and GIT_DIR environment variable

better completion of git-branch
---
 _git |  170 +++++++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 112 insertions(+), 58 deletions(-)

diff --git a/_git b/_git
index 6f6e82d..6bc8a37 100644
--- a/_git
+++ b/_git
@@ -184,13 +184,30 @@ _git_command_options () {
     'write-tree[creates a tree from the current index]' && ret=0
 }
 
-# TODO: this needs to be cleaned up and fixed
 local curcontext=$curcontext ret=1
-local first=1
+local gitdir="$GITDIR"
+local curgitdir=""
+local gitdir_arg=""
 
 if [[ $words[1] == git ]]; then
   while [[ $#words -ge 3 && $words[2] == -* ]]; do
-    compset -n 2
+    if [[ $words[2] == --git-dir=* ]]; then
+      gitdir=${words[2]#--git-dir=}
+      compset -n 2
+    elif [[ $words[2] == --git-dir && $#words -ge 4 ]]; then
+      gitdir=$words[3]
+      compset -n 2
+      compset -n 2
+    elif [[ "$words[2]" == --exec-path=* || "$words[2]" == --work-tree=* ]];
+    then
+      compset -n 2
+    elif [[ $words[2] == --exec-path || $words[2] == --work-tree && \
+      $#words -ge 4 ]]; then
+      compset -n 2
+      compset -n 2
+    else
+      compset -n 2
+    fi
   done
   if (( CURRENT == 2 )); then
     _git_command_options
@@ -204,6 +221,27 @@ else
   _call_function ret _$words[1]
 fi
 
+__gitdir ()
+{
+  if [[ "$1" != "$gitdir_arg" || -z "$curgitdir" ]]; then
+    if [[ -z $gitdir ]]; then
+      if [[ -z "$1" ]]; then
+        if [[ -n "$gitdir" ]]; then
+          curgitdir="$gitdir"
+        elif [[ -d .git ]]; then
+          curgitdir=".git"
+        else
+          curgitdir=$(git-rev-parse --git-dir 2>/dev/null)
+        fi
+      elif [[ -d "$1/.git" ]]; then
+        curgitdir="$1/.git"
+      else
+        curgitdir="$1"
+      fi
+    fi
+  fi
+}
+
 _git-apply () {
   _arguments \
     $nul_arg \
@@ -703,11 +741,46 @@ _git-bisect () {
 }
 
 _git-branch () {
-  _arguments \
-    '(-D)-d[delete a branch, which must be fully merged]' \
-    '(-d)-D[delete a branch]' \
-    ':branch-name' \
-    ':base branch:__git_revisions' && ret=0
+  local mode=
+
+  # find out syntax mode
+  { (( $words[(I)-(d|D)] )) && mode=del } ||
+  { (( $words[(I)-(m|M)] )) && mode=move } ||
+  { (( $words[(I)-(a|r|f)] )) && mode=list_create } ||
+  { (( CURRENT > 2 && CURRENT > $words[(i)^-*] )) && mode=list_create }
+  # remove options
+  while [[ CURRENT -gt 2 && -n $words[2] && $words[2] == -* ]]; do
+    compset -n 2
+  done
+  case "$mode" in
+    list_create)
+      ;;
+    del)
+      if (( $words[(I)-r] )); then
+        _arguments '*:new branch:__git_remote_branch' && ret=0
+      else
+        _arguments \
+          '(-r)-r[delete remote tracking branches]' \
+          '*:old branch:__git_local_branch' && ret=0
+      fi
+      ;;
+    move)
+      _arguments \
+        '1:old branch:__git_local_branch' \
+        '2:new branch:' && ret=0
+      ;;
+    *)
+      _arguments \
+        - '(options)' \
+          '-f[create branch forcefully]' \
+          '-a[list all branches]' \
+          '-r[list remote branches]' \
+          '-d[delete a branch, which must be fully merged]' \
+          '-D[delete a branch forcefully]' \
+          '-m[move branch]:m:->move' \
+          '-M[move branch forcefully]:M:->move' && ret=0
+      ;;
+  esac
 }
 
 _git-checkout () {
@@ -809,7 +882,7 @@ _git-ls-remote () {
     '(-h --heads)'{-h,--heads}'[show only refs under refs/heads]' \
     '(-t --tags)'{-t,--tags}'[show only refs under refs/tags]' \
     ':repository:__git_any_repositories' \
-    '*: :__git_references' && ret=0
+    '*: :__git_all_references' && ret=0
 }
 
 _git-merge () {
@@ -1190,9 +1263,7 @@ __git_tree_files () {
 # TODO: deal with things that __git_heads and __git_tags has in common (i.e.,
 # if both exists, they need to be completed to heads/x and tags/x.
 __git_commits () {
-  _alternative \
-    'heads::__git_heads' \
-    'tags::__git_tags'
+  __git_all_references
 }
 
 # TODO: deal with prefixes and suffixes listed in git-rev-parse
@@ -1283,70 +1354,53 @@ __git_signoff_file () {
 __git_tag_ids () {
 }
 
-__git_heads_or_tags () {
+__git_references () {
+  local cmd i is_hash=y
   local expl
-  typeset -a refs opts
-  typeset -A ours
-
-  zparseopts -K -D -a opts S: M: J: V: 1 2 n F: X: P:=ours T:=ours
-
-  (( $+ours[-P] )) || ours[-P]=./.
-
-  refs=(${${"${(@f)$(git ls-remote --$ours[-T] $ours[-P] 2>/dev/null)}"#*$'\t'}#refs/$ours[-T]/})
-  if (( $? == 0 )); then
-    _wanted $ours[-T] expl $ours[-T] compadd $opts - $refs
+  local path1="$1" path2="$2"
+
+  shift 2
+  __gitdir
+  if [[ -d "$curgitdir" ]]; then
+    for i in $(git --git-dir="$curgitdir" \
+      for-each-ref --format='%(refname)' \
+      refs"$path1$path2" ); do
+      _wanted "$path2" expl "$path2" compadd $@ - "${i#refs$path1$path2/}"
+    done
   else
     _message 'not a git repository'
   fi
 }
 
 __git_heads () {
-  __git_heads_or_tags $* -T heads && ret=0
+  __git_references / heads $@ && ret=0
 }
 
 __git_tags () {
-  __git_heads_or_tags $* -T tags && ret=0
+  __git_references / tags $@ && ret=0
 }
 
-# TODO: depending on what options are on the command-line already, complete
-# only tags or heads
-# TODO: perhaps caching is unnecessary.  usually won’t contain that much data
-# TODO: perhaps provide alternative here for both heads and tags (and use
-# __git_heads and __git_tags)
-# TODO: instead of "./.", we should be looking in the repository specified as
-# an argument to the command (but default to "./." I suppose (why not "."?))
-__git_references () {
-#  _alternative \
-#    'heads::__git_heads' \
-#    'tags::__git_tags' && ret=0
-  local expl
-
-  # TODO: deal with GIT_DIR
-  if [[ $_git_refs_cache_pwd != $PWD ]]; then
-    _git_refs_cache=(${${"${(@f)$(git ls-remote ./. 2>/dev/null)}"#*$'\t'}#refs/(heads|tags)/})
-    _git_refs_cache_pwd=$PWD
-  fi
+__git_remotes () {
+  __git_references /remotes "" $@ && ret=0
+}
 
-  if (( $? == 0 )); then
-    _wanted references expl 'references' compadd - $_git_refs_cache
-  else
-    _message 'not a git repository'
-  fi
+__git_all_references () {
+  __git_heads && ret=0
+  __git_tags && ret=0
+  __git_remotes && ret=0
 }
 
 __git_local_references () {
-  local expl
+  __git_heads && ret=0
+  __git_tags && ret=0
+}
 
-  if [[ $_git_local_refs_cache_pwd != $PWD ]]; then
-    _git_local_refs_cache=(${${"${(@f)$(git ls-remote ./. 2>/dev/null)}"#*$'\t'}#refs/})
-    _git_local_refs_cache_pwd=$PWD
-  fi
+__git_local_branch () {
+  __git_heads && ret=0
+}
 
-  if (( $? == 0 )); then
-    _wanted references expl 'references' compadd - $_git_local_refs_cache
-  else
-    _message 'not a git repository'
-  fi
+__git_remote_branch () {
+  __git_remotes && ret=0
 }
 
 # ---
-- 
1.5.3.5.GIT


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

* Re: [PATCH] improved git completion
  2008-01-24 18:47 [PATCH] improved git completion Dominik Vogt
@ 2008-01-24 23:12 ` Jörg Sommer
  2008-01-25 13:38   ` Dominik Vogt
  2008-01-25 13:50 ` Clint Adams
  2008-01-28  9:45 ` Nikolai Weibull
  2 siblings, 1 reply; 10+ messages in thread
From: Jörg Sommer @ 2008-01-24 23:12 UTC (permalink / raw)
  To: zsh-workers

Hi Dominik,

Dominik Vogt <dominik.vogt@gmx.de> wrote:
> Attached to this message you can find a series of patches to the
> git completion file (installed as
> /usr/share/zsh/4.3.2/functions/Completion/Unix/_git, no idea where
> it lives in the source tree).

Your patches don't apply at me. Can you use the repository at
git://repo.or.cz/zsh.git and resend the patches?

Regards, Jörg.
-- 
Im Leben lernt der Mensch als erstes das Gehen und Sprechen.
Später lernt er still zu sitzen und den Mund zu halten.


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

* Re: [PATCH] improved git completion
  2008-01-24 23:12 ` Jörg Sommer
@ 2008-01-25 13:38   ` Dominik Vogt
  2008-01-26  0:17     ` Jörg Sommer
  0 siblings, 1 reply; 10+ messages in thread
From: Dominik Vogt @ 2008-01-25 13:38 UTC (permalink / raw)
  To: zsh-workers

On Thu, Jan 24, 2008 at 11:12:49PM +0000, Jörg Sommer wrote:
> Hi Dominik,
> 
> Dominik Vogt <dominik.vogt@gmx.de> wrote:
> > Attached to this message you can find a series of patches to the
> > git completion file (installed as
> > /usr/share/zsh/4.3.2/functions/Completion/Unix/_git, no idea where
> > it lives in the source tree).
> 
> Your patches don't apply at me. Can you use the repository at
> git://repo.or.cz/zsh.git and resend the patches?

Hm, the original code has changed dramatically since I began
writing the patches, and I don't have the time to do it again from
scratch.  All I can do is to offer the original author of the git
completion stuff to take the last two patches as a base to rewrite
his own completion code to

1) handle GIT_DIR and --git-dir=,
2) copy without git-ls-remote (which ist *slooow* and potentially
   requires a network connection),
3) improve git-branch completion.

Actually, the use of git-ls-remote renders the current git
completion pretty much useless for me as I am not going to wait
four seconds for the completion list or tags and heads to be
built.  Until there's a solution for this problem I'll just have
to use my own version of git completion.  Sorry.

Ciao

Dominik ^_^  ^_^

-- 
Dominik Vogt


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

* Re: [PATCH] improved git completion
  2008-01-24 18:47 [PATCH] improved git completion Dominik Vogt
  2008-01-24 23:12 ` Jörg Sommer
@ 2008-01-25 13:50 ` Clint Adams
  2008-01-28  9:45 ` Nikolai Weibull
  2 siblings, 0 replies; 10+ messages in thread
From: Clint Adams @ 2008-01-25 13:50 UTC (permalink / raw)
  To: Dominik Vogt; +Cc: Zsh Workers

On Thu, Jan 24, 2008 at 07:47:04PM +0100, Dominik Vogt wrote:
> 0001*
> 
>   Removes trailing whitespace from the file.

This should achieve that.

Index: Completion/Unix/Command/_git
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_git,v
retrieving revision 1.58
diff -u -r1.58 _git
--- Completion/Unix/Command/_git	22 Jan 2008 17:17:00 -0000	1.58
+++ Completion/Unix/Command/_git	25 Jan 2008 13:47:17 -0000
@@ -1663,7 +1663,7 @@
     '--all-match[all patterns must match]' \
     ':pattern:' \
     '*::tree-or-file:->files' && ret=0
-  
+
   case $state in
     (files)
       integer first_tree last_tree start end
@@ -2573,7 +2573,7 @@
 
 (( $+functions[__git_tree_ishs] )) ||
 __git_tree_ishs () {
-  __git_commits 
+  __git_commits
 }
 
 (( $+functions[__git_blobs] )) ||
@@ -2726,7 +2726,7 @@
     while _tags; do
       while _next_label files expl ${suf:-remote directory}; do
 #        [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
-#	    ${(q)remdispf%[*=@|]} && ret=0 
+#	    ${(q)remdispf%[*=@|]} && ret=0
 	compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
 	    ${(q)remdispd%/} && ret=0
       done
@@ -2934,7 +2934,7 @@
     compset -P 'remotes.'
 
     __git_remote-groups
-    return 
+    return
   elif [[ -prefix gitcvs.* ]]; then
     names=(
       'enabled:whether the cvs pserver interface is enabled'
@@ -3805,7 +3805,7 @@
 #
 # -t can be used to specify a tag to use (default: booleans).
 # -l can be used to specify a label to use (default: 'boolean').
-# 
+#
 # The first argument is the default value, so that the description of the
 # default value can be suffixed with " (default)".  The second argument
 # is the description for the true value.  If a third argument is given,
@@ -3814,7 +3814,7 @@
 # "don't ".
 (( $+functions[__git_boolean_settings] )) ||
 __git_boolean_settings () {
-  local tag label garbage 
+  local tag label garbage
 
   zparseopts -D -E -a garba S: M: J: V: 1 2 n F: X: -t=tag -l=label
 


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

* Re: [PATCH] improved git completion
  2008-01-25 13:38   ` Dominik Vogt
@ 2008-01-26  0:17     ` Jörg Sommer
  2008-01-26 11:34       ` Dominik Vogt
  0 siblings, 1 reply; 10+ messages in thread
From: Jörg Sommer @ 2008-01-26  0:17 UTC (permalink / raw)
  To: zsh-workers

Hallo Dominik,

Dominik Vogt <dominik.vogt@gmx.de> wrote:
> On Thu, Jan 24, 2008 at 11:12:49PM +0000, Jörg Sommer wrote:
>> Hi Dominik,
>> 
>> Dominik Vogt <dominik.vogt@gmx.de> wrote:
>> > Attached to this message you can find a series of patches to the
>> > git completion file (installed as
>> > /usr/share/zsh/4.3.2/functions/Completion/Unix/_git, no idea where
>> > it lives in the source tree).
>> 
>> Your patches don't apply at me. Can you use the repository at
>> git://repo.or.cz/zsh.git and resend the patches?
>
> Hm, the original code has changed dramatically since I began
> writing the patches, and I don't have the time to do it again from
> scratch.

Which Zsh version did you use?

Bye, Jörg.
-- 
Du kannst einem Schwein einen goldenen Ring durch die Nase ziehen,
deswegen bleibt es trozdem ein Schwein!


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

* Re: [PATCH] improved git completion
  2008-01-26  0:17     ` Jörg Sommer
@ 2008-01-26 11:34       ` Dominik Vogt
  0 siblings, 0 replies; 10+ messages in thread
From: Dominik Vogt @ 2008-01-26 11:34 UTC (permalink / raw)
  To: zsh-workers

On Sat, Jan 26, 2008 at 12:17:12AM +0000, Jörg Sommer wrote:
> Hallo Dominik,
> 
> Dominik Vogt <dominik.vogt@gmx.de> wrote:
> > On Thu, Jan 24, 2008 at 11:12:49PM +0000, Jörg Sommer wrote:
> >> Hi Dominik,
> >> 
> >> Dominik Vogt <dominik.vogt@gmx.de> wrote:
> >> > Attached to this message you can find a series of patches to the
> >> > git completion file (installed as
> >> > /usr/share/zsh/4.3.2/functions/Completion/Unix/_git, no idea where
> >> > it lives in the source tree).
> >> 
> >> Your patches don't apply at me. Can you use the repository at
> >> git://repo.or.cz/zsh.git and resend the patches?
> >
> > Hm, the original code has changed dramatically since I began
> > writing the patches, and I don't have the time to do it again from
> > scratch.
> 
> Which Zsh version did you use?

4.3.2; I compared the the _git file to the one in some cvs or git
repository, some time in december and they were identical back
then.  I concluded that the git completion file wasn't maintained
anymore (as it contained a blatant sytax error in git-clone for
quite a while) and never bothered to check again :-(

Ciao

Dominik ^_^  ^_^

-- 
Dominik Vogt


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

* Re: [PATCH] improved git completion
  2008-01-24 18:47 [PATCH] improved git completion Dominik Vogt
  2008-01-24 23:12 ` Jörg Sommer
  2008-01-25 13:50 ` Clint Adams
@ 2008-01-28  9:45 ` Nikolai Weibull
  2008-01-29  8:38   ` Dominik Vogt
  2 siblings, 1 reply; 10+ messages in thread
From: Nikolai Weibull @ 2008-01-28  9:45 UTC (permalink / raw)
  To: dominik.vogt; +Cc: Zsh Workers

On Jan 24, 2008 7:47 PM, Dominik Vogt <dominik.vogt@gmx.de> wrote:

> 0002*
>
> Also replaces $* with $@ in some places

Why?


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

* Re: [PATCH] improved git completion
  2008-01-28  9:45 ` Nikolai Weibull
@ 2008-01-29  8:38   ` Dominik Vogt
  2008-01-29  8:51     ` Nikolai Weibull
  0 siblings, 1 reply; 10+ messages in thread
From: Dominik Vogt @ 2008-01-29  8:38 UTC (permalink / raw)
  To: Zsh Workers

On Mon, Jan 28, 2008 at 10:45:50AM +0100, Nikolai Weibull wrote:
> On Jan 24, 2008 7:47 PM, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> 
> > 0002*
> >
> > Also replaces $* with $@ in some places
> 
> Why?

It should have been "$@", not just $@, sorry.

The reason is that $*, $@ or "$*" don't handle whitespace in the
arguments.  Only "$@" keeps the original tokens.

Ciao

Dominik ^_^  ^_^

-- 
Dominik Vogt


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

* Re: [PATCH] improved git completion
  2008-01-29  8:38   ` Dominik Vogt
@ 2008-01-29  8:51     ` Nikolai Weibull
  2008-01-29  9:01       ` Dominik Vogt
  0 siblings, 1 reply; 10+ messages in thread
From: Nikolai Weibull @ 2008-01-29  8:51 UTC (permalink / raw)
  To: dominik.vogt, Zsh Workers

On Jan 29, 2008 9:38 AM, Dominik Vogt <dominik.vogt@gmx.de> wrote:

> On Mon, Jan 28, 2008 at 10:45:50AM +0100, Nikolai Weibull wrote:
> > On Jan 24, 2008 7:47 PM, Dominik Vogt <dominik.vogt@gmx.de> wrote:

> > > 0002*

> > > Also replaces $* with $@ in some places

> > Why?

> It should have been "$@", not just $@, sorry.
>
> The reason is that $*, $@ or "$*" don't handle whitespace in the
> arguments.  Only "$@" keeps the original tokens.

Not in Zsh, unless you set a funky environment up for yourself, which
isn't the case in this completion definition.


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

* Re: [PATCH] improved git completion
  2008-01-29  8:51     ` Nikolai Weibull
@ 2008-01-29  9:01       ` Dominik Vogt
  0 siblings, 0 replies; 10+ messages in thread
From: Dominik Vogt @ 2008-01-29  9:01 UTC (permalink / raw)
  To: Zsh Workers

On Tue, Jan 29, 2008 at 09:51:52AM +0100, Nikolai Weibull wrote:
> On Jan 29, 2008 9:38 AM, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> 
> > On Mon, Jan 28, 2008 at 10:45:50AM +0100, Nikolai Weibull wrote:
> > > On Jan 24, 2008 7:47 PM, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> 
> > > > 0002*
> 
> > > > Also replaces $* with $@ in some places
> 
> > > Why?
> 
> > It should have been "$@", not just $@, sorry.
> >
> > The reason is that $*, $@ or "$*" don't handle whitespace in the
> > arguments.  Only "$@" keeps the original tokens.
> 
> Not in Zsh, unless you set a funky environment up for yourself, which
> isn't the case in this completion definition.

Yes, sorry; I'm so used to SH_WORD_SPLIT that I forgot it is there.

Ciao

Dominik ^_^  ^_^

-- 
Dominik Vogt


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

end of thread, other threads:[~2008-01-29  9:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-24 18:47 [PATCH] improved git completion Dominik Vogt
2008-01-24 23:12 ` Jörg Sommer
2008-01-25 13:38   ` Dominik Vogt
2008-01-26  0:17     ` Jörg Sommer
2008-01-26 11:34       ` Dominik Vogt
2008-01-25 13:50 ` Clint Adams
2008-01-28  9:45 ` Nikolai Weibull
2008-01-29  8:38   ` Dominik Vogt
2008-01-29  8:51     ` Nikolai Weibull
2008-01-29  9:01       ` Dominik Vogt

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