Removed trailing white space in source.
[vcscommand.git] / plugin / vcssvk.vim
bloba28cd3011375eb8945fe3c9810fa9b76c51e81b7
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 exists('VCSCommandDisableAll')
39         finish
40 endif
42 if v:version < 700
43         echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
44         finish
45 endif
47 runtime plugin/vcscommand.vim
49 if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
50         " SVK is not installed
51         finish
52 endif
54 let s:save_cpo=&cpo
55 set cpo&vim
57 " Section: Variable initialization {{{1
59 let s:svkFunctions = {}
61 " Section: Utility functions {{{1
63 " Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2
64 " Wrapper to VCSCommandDoCommand to add the name of the SVK executable to the
65 " command argument.
66 function! s:DoCommand(cmd, cmdName, statusText, options)
67         if VCSCommandGetVCSType(expand('%')) == 'SVK'
68                 let fullCmd = VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' ' . a:cmd
69                 return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
70         else
71                 throw 'SVK VCSCommand plugin called on non-SVK item.'
72         endif
73 endfunction
75 " Section: VCS function implementations {{{1
77 " Function: s:svkFunctions.Identify(buffer) {{{2
78 function! s:svkFunctions.Identify(buffer)
79         let fileName = resolve(bufname(a:buffer))
80         if isdirectory(fileName)
81                 let directoryName = fileName
82         else
83                 let directoryName = fnamemodify(fileName, ':p:h')
84         endif
85         let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' info "' . directoryName . '"')
86         if(v:shell_error)
87                 return 0
88         else
89                 return 1
90         endif
91 endfunction
93 " Function: s:svkFunctions.Add() {{{2
94 function! s:svkFunctions.Add(argList)
95         return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
96 endfunction
98 " Function: s:svkFunctions.Annotate(argList) {{{2
99 function! s:svkFunctions.Annotate(argList)
100         if len(a:argList) == 0
101                 if &filetype == 'SVKAnnotate'
102                         " Perform annotation of the version indicated by the current line.
103                         let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
104                         let options = ' -r' . caption
105                 else
106                         let caption = ''
107                         let options = ''
108                 endif
109         elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
110                 let caption = a:argList[0]
111                 let options = ' -r' . caption
112         else
113                 let caption = join(a:argList, ' ')
114                 let options = ' ' . caption
115         endif
117         let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
118         if resultBuffer > 0
119                 normal 1G2dd
120                 set filetype=SVKAnnotate
121         endif
122         return resultBuffer
123 endfunction
125 " Function: s:svkFunctions.Commit(argList) {{{2
126 function! s:svkFunctions.Commit(argList)
127         let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
128         if resultBuffer == 0
129                 echomsg 'No commit needed.'
130         endif
131 endfunction
133 " Function: s:svkFunctions.Delete() {{{2
134 function! s:svkFunctions.Delete(argList)
135         return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
136 endfunction
138 " Function: s:svkFunctions.Diff(argList) {{{2
139 function! s:svkFunctions.Diff(argList)
140         if len(a:argList) == 0
141                 let revOptions = []
142                 let caption = ''
143         elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
144                 let revOptions = ['-r' . join(a:argList, ':')]
145                 let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
146         else
147                 " Pass-through
148                 let caption = join(a:argList, ' ')
149                 let revOptions = a:argList
150         endif
152         let resultBuffer = s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {})
153         if resultBuffer > 0
154                 set filetype=diff
155         else
156                 echomsg 'No differences found'
157         endif
158         return resultBuffer
159 endfunction
161 " Function: s:svkFunctions.GetBufferInfo() {{{2
162 " Provides version control details for the current file.  Current version
163 " number and current repository version number are required to be returned by
164 " the vcscommand plugin.
165 " Returns: List of results:  [revision, repository]
167 function! s:svkFunctions.GetBufferInfo()
168         let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
169         let fileName = resolve(bufname(originalBuffer))
170         let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' status -v "' . fileName . '"')
171         if(v:shell_error)
172                 return []
173         endif
175         " File not under SVK control.
176         if statusText =~ '^?'
177                 return ['Unknown']
178         endif
180         let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3]
181         if revision == ''
182                 " Error
183                 return ['Unknown']
184         elseif flags =~ '^A'
185                 return ['New', 'New']
186         else
187                 return [revision, repository]
188         endif
189 endfunction
191 " Function: s:svkFunctions.Info(argList) {{{2
192 function! s:svkFunctions.Info(argList)
193         return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
194 endfunction
196 " Function: s:svkFunctions.Lock(argList) {{{2
197 function! s:svkFunctions.Lock(argList)
198         return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
199 endfunction
201 " Function: s:svkFunctions.Log() {{{2
202 function! s:svkFunctions.Log(argList)
203         if len(a:argList) == 0
204                 let options = []
205                 let caption = ''
206         elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
207                 let options = ['-r' . join(a:argList, ':')]
208                 let caption = options[0]
209         else
210                 " Pass-through
211                 let options = a:argList
212                 let caption = join(a:argList, ' ')
213         endif
215         let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
216         return resultBuffer
217 endfunction
219 " Function: s:svkFunctions.Revert(argList) {{{2
220 function! s:svkFunctions.Revert(argList)
221         return s:DoCommand('revert', 'revert', '', {})
222 endfunction
224 " Function: s:svkFunctions.Review(argList) {{{2
225 function! s:svkFunctions.Review(argList)
226         if len(a:argList) == 0
227                 let versiontag = '(current)'
228                 let versionOption = ''
229         else
230                 let versiontag = a:argList[0]
231                 let versionOption = ' -r ' . versiontag . ' '
232         endif
234         let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
235         if resultBuffer > 0
236                 let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
237         endif
238         return resultBuffer
239 endfunction
241 " Function: s:svkFunctions.Status(argList) {{{2
242 function! s:svkFunctions.Status(argList)
243         let options = ['-v']
244         if len(a:argList) == 0
245                 let options = a:argList
246         endif
247         return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
248 endfunction
250 " Function: s:svkFunctions.Unlock(argList) {{{2
251 function! s:svkFunctions.Unlock(argList)
252         return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
253 endfunction
254 " Function: s:svkFunctions.Update(argList) {{{2
255 function! s:svkFunctions.Update(argList)
256         return s:DoCommand('update', 'update', '', {})
257 endfunction
259 " Section: Plugin Registration {{{1
260 call VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
262 let &cpo = s:save_cpo