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

Re: Bug#299950: zsh: Better completion for "svn revert"



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:)"'
       )
     ;;
     *)



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