zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@sunsite.dk, Vincent Lefevre <vincent@vinc17.org>,
	299950-forwarded@bugs.debian.org
Subject: Re: Bug#299950: zsh: Better completion for "svn revert"
Date: Thu, 31 Mar 2005 16:17:13 +0200	[thread overview]
Message-ID: <5059.1112278633@trentino.groupinfra.com> (raw)
In-Reply-To: <20050327003652.GA20238@scowler.net>

On 26 Mar, Clint wrote:
> > This wouldn't be sufficient. In the first column, this would be at
> > least 'A', 'D' (note that the file no longer exists, but completion
> > should be able to give the deleted file) and 'M'. In the second
> > column, this would be 'M'.
> 
> I'm not sure I understand.  Does this patch make it do the right thing?

In addition to the points made by Vincent, it is also better to use
_files instead of rewriting filename completion. If you need complicated
rules to decide which files to include then use a function with the e
glob qualifier. This is what _svn_controlled does to pick up files under
configuration control. The result is that the file-patterns style and
many other nice features of _files/_path_files will work.

The following patch adds two new functions: _svn_deletedfiles and
_svn_status for use with the e qualifier.

_svn_status checks files against the output of svn status. By default it
picks up modified and added files.

Of course _files doesn't complete files which don't already exist.
_svn_deletedfiles uses a trick I've never tried before with _files: it
fills up the reply array. Usage is along the lines of:
  _files -g '.svn(/e:_svn_deletedfiles:)'
This seems to work quite nicely but I won't be suprised if some problems
arrise. It'll be interesting to see. Only thing I've seen is that they
don't get a space suffix.

Oliver

Index: Completion/Unix/Command/_subversion
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_subversion,v
retrieving revision 1.9
diff -u -r1.9 _subversion
--- Completion/Unix/Command/_subversion	27 Mar 2005 00:41:00 -0000	1.9
+++ Completion/Unix/Command/_subversion	31 Mar 2005 14:13:34 -0000
@@ -21,9 +21,28 @@
   [[ -f ${(M)REPLY##*/}.svn/text-base/${REPLY##*/}.svn-base ]]
 }
 
-(( $+functions[_svn_adm_files] )) ||
-_svn_adm_files() {
-  compadd ${${(M)${(f)"$(svn status)"}:#(#s)[ADM]*}##[ADM] ##}
+(( $+functions[_svn_deletedfiles] )) ||
+_svn_deletedfiles() {
+  # Typical usage would be _files -g '.svn(/e:_svn_deletedfiles:)' 
+  local cont controlled
+  reply=( )
+  [[ $REPLY = (*/|).svn ]] || return
+  controlled=( $REPLY/text-base/*.svn-base(N:r:t) )
+  for cont in ${controlled}; do
+    [[ -e $REPLY:h/$cont ]] || reply+=( ${REPLY%.svn}$cont )
+  done
+}
+
+(( $+functions[_svn_status] )) ||
+_svn_status() {
+  local dir=$REPLY:h
+  local pat="${1:-([ADMR]|?M)}"
+
+  if (( ! $+_cache_svn_status[$dir] )); then
+    _cache_svn_status[$dir]="$(_call_program files svn status -N $dir)"
+  fi
+
+  (( ${(M)#${(f)_cache_svn_status[$dir]}:#(#s)${~pat}*$REPLY} ))
 }
 
 (( $+functions[_svn_urls] )) ||
@@ -68,6 +87,7 @@
 (( $+functions[_svn_subcommand] )) ||
 _svn_subcommand () {
   local subcmd _svn_subcmds _svn_subcmd_usage
+  typeset -A _cache_svn_status
 
   _svn_subcmd_usage=${${(M)${(f)"$(LC_MESSAGES=C _call_program options svn help $1)"}:#usage:*}#usage: $1 }
 
@@ -87,9 +107,14 @@
 	'*:file:_files -g "*(e:_svn_controlled:)"'
       )
     ;;
-    (revert)
+    delete)
+      _svn_subcmds+=(
+        '*:file:_files -g ".svn(/e:_svn_deletedfiles:)"'
+      )
+    ;;
+    revert|commit)
       _svn_subcmds+=(
-	'*:file:_svn_adm_files'
+        '*:file:_files -g "(.svn|*)(/e:_svn_deletedfiles:,e:_svn_status:)"'
       )
     ;;
     *)


      parent reply	other threads:[~2005-03-31 14:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20050317142638.GA23797@dixsept.loria.fr>
     [not found] ` <20050325142839.GA32333@scowler.net>
     [not found]   ` <20050325161734.GT19392@ay.vinc17.org>
2005-03-27  0:36     ` Clint Adams
2005-03-31  1:02       ` Vincent Lefevre
2005-03-31 14:17       ` Oliver Kiddle [this message]

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=5059.1112278633@trentino.groupinfra.com \
    --to=okiddle@yahoo.co.uk \
    --cc=299950-forwarded@bugs.debian.org \
    --cc=vincent@vinc17.org \
    --cc=zsh-workers@sunsite.dk \
    /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).