1 " vim600: set foldmethod=marker:
3 " BZR extension for VCSCommand.
5 " Version: VCS development
6 " Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
8 " Copyright (c) 2009 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
28 " Section: Documentation {{{1
30 " Options documentation: {{{2
33 " This variable specifies the BZR executable. If not set, it defaults to
34 " 'bzr' executed from the user's executable path.
36 " Section: Plugin header {{{1
38 if exists('VCSCommandDisableAll')
43 echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
47 runtime plugin/vcscommand.vim
49 if !executable(VCSCommandGetOption('VCSCommandBZRExec', 'bzr'))
50 " BZR is not installed
57 " Section: Variable initialization {{{1
59 let s:bzrFunctions = {}
61 " Section: Utility functions {{{1
63 " Function: s:Executable() {{{2
64 " Returns the executable used to invoke bzr suitable for use in a shell
66 function! s:Executable()
67 return shellescape(VCSCommandGetOption('VCSCommandBZRExec', 'bzr'))
70 " Function: s:DoCommand(cmd, cmdName, statusText) {{{2
71 " Wrapper to VCSCommandDoCommand to add the name of the BZR executable to the
73 function! s:DoCommand(cmd, cmdName, statusText, options)
74 if VCSCommandGetVCSType(expand('%')) == 'BZR'
75 let fullCmd = s:Executable() . ' ' . a:cmd
76 return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
78 throw 'BZR VCSCommand plugin called on non-BZR item.'
82 " Section: VCS function implementations {{{1
84 " Function: s:bzrFunctions.Identify(buffer) {{{2
85 function! s:bzrFunctions.Identify(buffer)
86 let fileName = resolve(bufname(a:buffer))
87 let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . fileName . '"')
95 " Function: s:bzrFunctions.Add() {{{2
96 function! s:bzrFunctions.Add(argList)
97 return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
100 " Function: s:bzrFunctions.Annotate(argList) {{{2
101 function! s:bzrFunctions.Annotate(argList)
102 if len(a:argList) == 0
103 if &filetype == 'BZRAnnotate'
104 " Perform annotation of the version indicated by the current line.
105 let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
106 let options = ' -r' . caption
111 elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
112 let caption = a:argList[0]
113 let options = ' -r' . caption
115 let caption = join(a:argList, ' ')
116 let options = ' ' . caption
119 let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
122 set filetype=BZRAnnotate
127 " Function: s:bzrFunctions.Commit(argList) {{{2
128 function! s:bzrFunctions.Commit(argList)
129 let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
131 echomsg 'No commit needed.'
135 " Function: s:bzrFunctions.Delete() {{{2
136 function! s:bzrFunctions.Delete(argList)
137 return s:DoCommand(join(['rm'] + a:argList, ' '), 'rm', join(a:argList, ' '), {})
140 " Function: s:bzrFunctions.Diff(argList) {{{2
141 function! s:bzrFunctions.Diff(argList)
142 if len(a:argList) == 0
145 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
146 let revOptions = ['-r' . join(a:argList, '..')]
147 let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
150 let caption = join(a:argList, ' ')
151 let revOptions = a:argList
154 let resultBuffer = s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {'allowNonZeroExit': 1})
158 echomsg 'No differences found'
163 " Function: s:bzrFunctions.GetBufferInfo() {{{2
164 " Provides version control details for the current file. Current version
165 " number and current repository version number are required to be returned by
166 " the vcscommand plugin.
167 " Returns: List of results: [revision, repository]
169 function! s:bzrFunctions.GetBufferInfo()
170 let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
171 let fileName = resolve(bufname(originalBuffer))
172 let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -S -- "' . fileName . '"')
173 let revision = s:VCSCommandUtility.system(s:Executable() . ' revno -- "' . fileName . '"')
178 " File not under BZR control.
179 if statusText =~ '^?'
183 let [flags, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)')[1:2]
188 return ['New', 'New']
190 return [revision, repository]
194 " Function: s:bzrFunctions.Info(argList) {{{2
195 function! s:bzrFunctions.Info(argList)
196 return s:DoCommand(join(['version-info'] + a:argList, ' '), 'version-info', join(a:argList, ' '), {})
199 " Function: s:bzrFunctions.Lock(argList) {{{2
200 function! s:bzrFunctions.Lock(argList)
201 echomsg 'bzr lock is not necessary'
204 " Function: s:bzrFunctions.Log() {{{2
205 function! s:bzrFunctions.Log(argList)
206 if len(a:argList) == 0
209 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
210 let options = ['-r' . join(a:argList, ':')]
211 let caption = options[0]
214 let options = a:argList
215 let caption = join(a:argList, ' ')
218 let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
222 " Function: s:bzrFunctions.Revert(argList) {{{2
223 function! s:bzrFunctions.Revert(argList)
224 return s:DoCommand('revert', 'revert', '', {})
227 " Function: s:bzrFunctions.Review(argList) {{{2
228 function! s:bzrFunctions.Review(argList)
229 if len(a:argList) == 0
230 let versiontag = '(current)'
231 let versionOption = ''
233 let versiontag = a:argList[0]
234 let versionOption = ' -r ' . versiontag . ' '
237 let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
239 let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
244 " Function: s:bzrFunctions.Status(argList) {{{2
245 function! s:bzrFunctions.Status(argList)
247 if len(a:argList) == 0
248 let options = a:argList
250 return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
253 " Function: s:bzrFunctions.Unlock(argList) {{{2
254 function! s:bzrFunctions.Unlock(argList)
255 echomsg 'bzr unlock is not necessary'
257 " Function: s:bzrFunctions.Update(argList) {{{2
258 function! s:bzrFunctions.Update(argList)
259 return s:DoCommand('update', 'update', '', {})
262 " Annotate setting {{{2
263 let s:bzrFunctions.AnnotateSplitRegex = '^[^|]\+ | '
265 " Section: Plugin Registration {{{1
266 let s:VCSCommandUtility = VCSCommandRegisterModule('BZR', expand('<sfile>'), s:bzrFunctions, [])
268 let &cpo = s:save_cpo