Corrected signature of s:DoCommand in SVK and SVN plugins.
[vcscommand.git] / plugin / vcssvk.vim
blobd05be4c6c17b02ddae3fda1421680bbfc7f60818
1 " vim600: set foldmethod=marker:
3 " SVK extension for VCSCommand.
5 " Version:       VCS development
6 " Maintainer:    Bob Hiestand <bob.hiestand@gmail.com>
7 " License:
8 " Copyright (c) 2007 Bob Hiestand
10 " Permission is hereby granted, free of charge, to any person obtaining a copy
11 " of this software and associated documentation files (the "Software"), to
12 " deal in the Software without restriction, including without limitation the
13 " rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 " sell copies of the Software, and to permit persons to whom the Software is
15 " furnished to do so, subject to the following conditions:
17 " The above copyright notice and this permission notice shall be included in
18 " all copies or substantial portions of the Software.
20 " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 " FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 " IN THE SOFTWARE.
28 " Section: Documentation {{{1
30 " Options documentation: {{{2
32 " VCSCommandSVKExec
33 "   This variable specifies the SVK executable.  If not set, it defaults to
34 "   'svk' executed from the user's executable path.
36 " Section: Plugin header {{{1
38 if v:version < 700
39   echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
40   finish
41 endif
43 runtime plugin/vcscommand.vim
45 if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
46   " SVK is not installed
47   finish
48 endif
50 let s:save_cpo=&cpo
51 set cpo&vim
53 " Section: Variable initialization {{{1
55 let s:svkFunctions = {}
57 " Section: Utility functions {{{1
59 " Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2
60 " Wrapper to VCSCommandDoCommand to add the name of the SVK executable to the
61 " command argument.
62 function! s:DoCommand(cmd, cmdName, statusText, options)
63   if VCSCommandGetVCSType(expand('%')) == 'SVK'
64     let fullCmd = VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' ' . a:cmd
65     return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
66   else
67     throw 'SVK VCSCommand plugin called on non-SVK item.'
68   endif
69 endfunction
71 " Section: VCS function implementations {{{1
73 " Function: s:svkFunctions.Identify(buffer) {{{2
74 function! s:svkFunctions.Identify(buffer)
75   let fileName = resolve(bufname(a:buffer))
76   if isdirectory(fileName)
77     let directoryName = fileName
78   else
79     let directoryName = fnamemodify(fileName, ':p:h')
80   endif
81   let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' info "' . directoryName . '"')
82   if(v:shell_error)
83     return 0
84   else
85     return 1
86   endif
87 endfunction
89 " Function: s:svkFunctions.Add() {{{2
90 function! s:svkFunctions.Add(argList)
91   return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
92 endfunction
94 " Function: s:svkFunctions.Annotate(argList) {{{2
95 function! s:svkFunctions.Annotate(argList)
96   if len(a:argList) == 0
97     if &filetype == 'SVKAnnotate'
98       " Perform annotation of the version indicated by the current line.
99       let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
100       let options = ' -r' . caption
101     else
102       let caption = ''
103       let options = ''
104     endif
105   elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
106     let caption = a:argList[0]
107     let options = ' -r' . caption
108   else
109     let caption = join(a:argList, ' ')
110     let options = ' ' . caption
111   endif
113   let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
114   if resultBuffer > 0
115     normal 1G2dd
116     set filetype=SVKAnnotate
117   endif
118   return resultBuffer
119 endfunction
121 " Function: s:svkFunctions.Commit(argList) {{{2
122 function! s:svkFunctions.Commit(argList)
123   let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
124   if resultBuffer == 0
125     echomsg 'No commit needed.'
126   endif
127 endfunction
129 " Function: s:svkFunctions.Delete() {{{2
130 function! s:svkFunctions.Delete(argList)
131   return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
132 endfunction
134 " Function: s:svkFunctions.Diff(argList) {{{2
135 function! s:svkFunctions.Diff(argList)
136   if len(a:argList) == 0
137     let revOptions = [] 
138     let caption = ''
139   elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
140     let revOptions = ['-r' . join(a:argList, ':')]
141     let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
142   else
143     " Pass-through
144     let caption = join(a:argList, ' ')
145     let revOptions = a:argList
146   endif
148   let resultBuffer = s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {})
149   if resultBuffer > 0
150     set filetype=diff
151   else
152     echomsg 'No differences found'
153   endif
154   return resultBuffer
155 endfunction
157 " Function: s:svkFunctions.GetBufferInfo() {{{2
158 " Provides version control details for the current file.  Current version
159 " number and current repository version number are required to be returned by
160 " the vcscommand plugin.
161 " Returns: List of results:  [revision, repository]
163 function! s:svkFunctions.GetBufferInfo()
164   let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
165   let fileName = resolve(bufname(originalBuffer))
166   let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' status -v "' . fileName . '"')
167   if(v:shell_error)
168     return []
169   endif
171   " File not under SVK control.
172   if statusText =~ '^?'
173     return ['Unknown']
174   endif
176   let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3]
177   if revision == ''
178     " Error
179     return ['Unknown']
180   elseif flags =~ '^A'
181     return ['New', 'New']
182   else
183     return [revision, repository]
184   endif
185 endfunction
187 " Function: s:svkFunctions.Info(argList) {{{2
188 function! s:svkFunctions.Info(argList)
189   return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
190 endfunction
192 " Function: s:svkFunctions.Lock(argList) {{{2
193 function! s:svkFunctions.Lock(argList)
194   return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
195 endfunction
197 " Function: s:svkFunctions.Log() {{{2
198 function! s:svkFunctions.Log(argList)
199   if len(a:argList) == 0
200     let options = []
201     let caption = ''
202   elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
203     let options = ['-r' . join(a:argList, ':')]
204     let caption = options[0]
205   else
206     " Pass-through
207     let options = a:argList
208     let caption = join(a:argList, ' ')
209   endif
211   let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
212   return resultBuffer
213 endfunction
215 " Function: s:svkFunctions.Revert(argList) {{{2
216 function! s:svkFunctions.Revert(argList)
217   return s:DoCommand('revert', 'revert', '', {})
218 endfunction
220 " Function: s:svkFunctions.Review(argList) {{{2
221 function! s:svkFunctions.Review(argList)
222   if len(a:argList) == 0
223     let versiontag = '(current)'
224     let versionOption = ''
225   else
226     let versiontag = a:argList[0]
227     let versionOption = ' -r ' . versiontag . ' '
228   endif
230   let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
231   if resultBuffer > 0
232     let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
233   endif
234   return resultBuffer
235 endfunction
237 " Function: s:svkFunctions.Status(argList) {{{2
238 function! s:svkFunctions.Status(argList)
239   let options = ['-v']
240   if len(a:argList) == 0
241     let options = a:argList
242   endif
243   return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
244 endfunction
246 " Function: s:svkFunctions.Unlock(argList) {{{2
247 function! s:svkFunctions.Unlock(argList)
248   return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
249 endfunction
250 " Function: s:svkFunctions.Update(argList) {{{2
251 function! s:svkFunctions.Update(argList)
252   return s:DoCommand('update', 'update', '', {})
253 endfunction
255 " Section: Plugin Registration {{{1
256 call VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
258 let &cpo = s:save_cpo