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 if !exists('g:loaded_VCSCommand')
47 runtime plugin/vcscommand.vim
50 if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
51 " SVK is not installed
58 " Section: Variable initialization {{{1
60 let s:svkFunctions = {}
62 " Section: Utility functions {{{1
64 " Function: s:Executable() {{{2
65 " Returns the executable used to invoke SVK suitable for use in a shell
67 function! s:Executable()
68 return shellescape(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
71 " Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2
72 " Wrapper to VCSCommandDoCommand to add the name of the SVK executable to the
74 function! s:DoCommand(cmd, cmdName, statusText, options)
75 if VCSCommandGetVCSType(expand('%')) == 'SVK'
76 let fullCmd = s:Executable() . ' ' . a:cmd
77 return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
79 throw 'SVK VCSCommand plugin called on non-SVK item.'
83 " Section: VCS function implementations {{{1
85 " Function: s:svkFunctions.Identify(buffer) {{{2
86 function! s:svkFunctions.Identify(buffer)
87 let fileName = resolve(bufname(a:buffer))
88 if isdirectory(fileName)
89 let directoryName = fileName
91 let directoryName = fnamemodify(fileName, ':p:h')
93 let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"', "no")
101 " Function: s:svkFunctions.Add() {{{2
102 function! s:svkFunctions.Add(argList)
103 return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
106 " Function: s:svkFunctions.Annotate(argList) {{{2
107 function! s:svkFunctions.Annotate(argList)
108 if len(a:argList) == 0
109 if &filetype ==? 'svkannotate'
110 " Perform annotation of the version indicated by the current line.
111 let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
112 let options = ' -r' . caption
117 elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
118 let caption = a:argList[0]
119 let options = ' -r' . caption
121 let caption = join(a:argList, ' ')
122 let options = ' ' . caption
125 let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
132 " Function: s:svkFunctions.Commit(argList) {{{2
133 function! s:svkFunctions.Commit(argList)
134 let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
136 echomsg 'No commit needed.'
140 " Function: s:svkFunctions.Delete() {{{2
141 function! s:svkFunctions.Delete(argList)
142 return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
145 " Function: s:svkFunctions.Diff(argList) {{{2
146 function! s:svkFunctions.Diff(argList)
147 if len(a:argList) == 0
150 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
151 let revOptions = ['-r' . join(a:argList, ':')]
152 let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
155 let caption = join(a:argList, ' ')
156 let revOptions = a:argList
159 return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {})
162 " Function: s:svkFunctions.GetBufferInfo() {{{2
163 " Provides version control details for the current file. Current version
164 " number and current repository version number are required to be returned by
165 " the vcscommand plugin.
166 " Returns: List of results: [revision, repository]
168 function! s:svkFunctions.GetBufferInfo()
169 let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
170 let fileName = resolve(bufname(originalBuffer))
171 let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"')
176 " File not under SVK control.
177 if statusText =~ '^?'
181 let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3]
186 return ['New', 'New']
188 return [revision, repository]
192 " Function: s:svkFunctions.Info(argList) {{{2
193 function! s:svkFunctions.Info(argList)
194 return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
197 " Function: s:svkFunctions.Lock(argList) {{{2
198 function! s:svkFunctions.Lock(argList)
199 return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
202 " Function: s:svkFunctions.Log() {{{2
203 function! s:svkFunctions.Log(argList)
204 if len(a:argList) == 0
207 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
208 let options = ['-r' . join(a:argList, ':')]
209 let caption = options[0]
212 let options = a:argList
213 let caption = join(a:argList, ' ')
216 let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
220 " Function: s:svkFunctions.Revert(argList) {{{2
221 function! s:svkFunctions.Revert(argList)
222 return s:DoCommand('revert', 'revert', '', {})
225 " Function: s:svkFunctions.Review(argList) {{{2
226 function! s:svkFunctions.Review(argList)
227 if len(a:argList) == 0
228 let versiontag = '(current)'
229 let versionOption = ''
231 let versiontag = a:argList[0]
232 let versionOption = ' -r ' . versiontag . ' '
235 return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
238 " Function: s:svkFunctions.Status(argList) {{{2
239 function! s:svkFunctions.Status(argList)
241 if len(a:argList) != 0
242 let options = a:argList
244 return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
247 " Function: s:svkFunctions.Unlock(argList) {{{2
248 function! s:svkFunctions.Unlock(argList)
249 return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
251 " Function: s:svkFunctions.Update(argList) {{{2
252 function! s:svkFunctions.Update(argList)
253 return s:DoCommand('update', 'update', '', {})
256 " Section: Plugin Registration {{{1
257 let s:VCSCommandUtility = VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
259 let &cpo = s:save_cpo