1 " vim600: set foldmethod=marker:
3 " SVK extension for VCSCommand.
5 " Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
7 " Copyright (c) Bob Hiestand
9 " Permission is hereby granted, free of charge, to any person obtaining a copy
10 " of this software and associated documentation files (the "Software"), to
11 " deal in the Software without restriction, including without limitation the
12 " rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 " sell copies of the Software, and to permit persons to whom the Software is
14 " furnished to do so, subject to the following conditions:
16 " The above copyright notice and this permission notice shall be included in
17 " all copies or substantial portions of the Software.
19 " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 " FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 " Section: Documentation {{{1
29 " Options documentation: {{{2
32 " This variable specifies the SVK executable. If not set, it defaults to
33 " 'svk' executed from the user's executable path.
35 " Section: Plugin header {{{1
37 if exists('VCSCommandDisableAll')
42 echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
46 runtime plugin/vcscommand.vim
48 if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
49 " SVK is not installed
56 " Section: Variable initialization {{{1
58 let s:svkFunctions = {}
60 " Section: Utility functions {{{1
62 " Function: s:Executable() {{{2
63 " Returns the executable used to invoke SVK suitable for use in a shell
65 function! s:Executable()
66 return shellescape(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
69 " Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2
70 " Wrapper to VCSCommandDoCommand to add the name of the SVK executable to the
72 function! s:DoCommand(cmd, cmdName, statusText, options)
73 if VCSCommandGetVCSType(expand('%')) == 'SVK'
74 let fullCmd = s:Executable() . ' ' . a:cmd
75 return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
77 throw 'SVK VCSCommand plugin called on non-SVK item.'
81 " Section: VCS function implementations {{{1
83 " Function: s:svkFunctions.Identify(buffer) {{{2
84 function! s:svkFunctions.Identify(buffer)
85 let fileName = resolve(bufname(a:buffer))
86 if isdirectory(fileName)
87 let directoryName = fileName
89 let directoryName = fnamemodify(fileName, ':p:h')
91 let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"', "no")
99 " Function: s:svkFunctions.Add() {{{2
100 function! s:svkFunctions.Add(argList)
101 return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
104 " Function: s:svkFunctions.Annotate(argList) {{{2
105 function! s:svkFunctions.Annotate(argList)
106 if len(a:argList) == 0
107 if &filetype == 'SVKannotate'
108 " Perform annotation of the version indicated by the current line.
109 let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
110 let options = ' -r' . caption
115 elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
116 let caption = a:argList[0]
117 let options = ' -r' . caption
119 let caption = join(a:argList, ' ')
120 let options = ' ' . caption
123 let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
130 " Function: s:svkFunctions.Commit(argList) {{{2
131 function! s:svkFunctions.Commit(argList)
132 let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
134 echomsg 'No commit needed.'
138 " Function: s:svkFunctions.Delete() {{{2
139 function! s:svkFunctions.Delete(argList)
140 return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
143 " Function: s:svkFunctions.Diff(argList) {{{2
144 function! s:svkFunctions.Diff(argList)
145 if len(a:argList) == 0
148 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
149 let revOptions = ['-r' . join(a:argList, ':')]
150 let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
153 let caption = join(a:argList, ' ')
154 let revOptions = a:argList
157 return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {})
160 " Function: s:svkFunctions.GetBufferInfo() {{{2
161 " Provides version control details for the current file. Current version
162 " number and current repository version number are required to be returned by
163 " the vcscommand plugin.
164 " Returns: List of results: [revision, repository]
166 function! s:svkFunctions.GetBufferInfo()
167 let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
168 let fileName = resolve(bufname(originalBuffer))
169 let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"')
174 " File not under SVK control.
175 if statusText =~ '^?'
179 let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3]
184 return ['New', 'New']
186 return [revision, repository]
190 " Function: s:svkFunctions.Info(argList) {{{2
191 function! s:svkFunctions.Info(argList)
192 return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
195 " Function: s:svkFunctions.Lock(argList) {{{2
196 function! s:svkFunctions.Lock(argList)
197 return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
200 " Function: s:svkFunctions.Log() {{{2
201 function! s:svkFunctions.Log(argList)
202 if len(a:argList) == 0
205 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
206 let options = ['-r' . join(a:argList, ':')]
207 let caption = options[0]
210 let options = a:argList
211 let caption = join(a:argList, ' ')
214 let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
218 " Function: s:svkFunctions.Revert(argList) {{{2
219 function! s:svkFunctions.Revert(argList)
220 return s:DoCommand('revert', 'revert', '', {})
223 " Function: s:svkFunctions.Review(argList) {{{2
224 function! s:svkFunctions.Review(argList)
225 if len(a:argList) == 0
226 let versiontag = '(current)'
227 let versionOption = ''
229 let versiontag = a:argList[0]
230 let versionOption = ' -r ' . versiontag . ' '
233 return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
236 " Function: s:svkFunctions.Status(argList) {{{2
237 function! s:svkFunctions.Status(argList)
239 if len(a:argList) != 0
240 let options = a:argList
242 return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
245 " Function: s:svkFunctions.Unlock(argList) {{{2
246 function! s:svkFunctions.Unlock(argList)
247 return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
249 " Function: s:svkFunctions.Update(argList) {{{2
250 function! s:svkFunctions.Update(argList)
251 return s:DoCommand('update', 'update', '', {})
254 " Section: Plugin Registration {{{1
255 let s:VCSCommandUtility = VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
257 let &cpo = s:save_cpo