1 " vim600: set foldmethod=marker:
3 " BZR 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 BZR executable. If not set, it defaults to
33 " 'bzr' 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('VCSCommandBZRExec', 'bzr'))
51 " BZR is not installed
58 " Section: Variable initialization {{{1
60 let s:bzrFunctions = {}
62 " Section: Utility functions {{{1
64 " Function: s:Executable() {{{2
65 " Returns the executable used to invoke bzr suitable for use in a shell
67 function! s:Executable()
68 return VCSCommandGetOption('VCSCommandBZRExec', 'bzr')
71 " Function: s:DoCommand(cmd, cmdName, statusText) {{{2
72 " Wrapper to VCSCommandDoCommand to add the name of the BZR executable to the
74 function! s:DoCommand(cmd, cmdName, statusText, options)
75 if VCSCommandGetVCSType(expand('%')) == 'BZR'
76 let fullCmd = s:Executable() . ' ' . a:cmd
77 return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
79 throw 'BZR VCSCommand plugin called on non-BZR item.'
83 " Section: VCS function implementations {{{1
85 " Function: s:bzrFunctions.Identify(buffer) {{{2
86 function! s:bzrFunctions.Identify(buffer)
87 let fileName = resolve(bufname(a:buffer))
88 let l:save_bzr_log=$BZR_LOG
90 let $BZR_LOG=has("win32") || has("win95") || has("win64") || has("win16") ? "nul" : "/dev/null"
91 let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . fileName . '"')
93 let $BZR_LOG=l:save_bzr_log
102 " Function: s:bzrFunctions.Add() {{{2
103 function! s:bzrFunctions.Add(argList)
104 return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
107 " Function: s:bzrFunctions.Annotate(argList) {{{2
108 function! s:bzrFunctions.Annotate(argList)
109 if len(a:argList) == 0
110 if &filetype ==? 'bzrannotate'
111 " Perform annotation of the version indicated by the current line.
112 let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
113 let options = ' -r' . caption
118 elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
119 let caption = a:argList[0]
120 let options = ' -r' . caption
122 let caption = join(a:argList, ' ')
123 let options = ' ' . caption
126 let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
133 " Function: s:bzrFunctions.Commit(argList) {{{2
134 function! s:bzrFunctions.Commit(argList)
135 let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
137 echomsg 'No commit needed.'
141 " Function: s:bzrFunctions.Delete() {{{2
142 function! s:bzrFunctions.Delete(argList)
143 return s:DoCommand(join(['rm'] + a:argList, ' '), 'rm', join(a:argList, ' '), {})
146 " Function: s:bzrFunctions.Diff(argList) {{{2
147 function! s:bzrFunctions.Diff(argList)
148 if len(a:argList) == 0
151 elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
152 let revOptions = ['-r' . join(a:argList, '..')]
153 let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
156 let caption = join(a:argList, ' ')
157 let revOptions = a:argList
160 return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {'allowNonZeroExit': 1})
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 return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
240 " Function: s:bzrFunctions.Status(argList) {{{2
241 function! s:bzrFunctions.Status(argList)
243 if len(a:argList) != 0
244 let options = a:argList
246 return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
249 " Function: s:bzrFunctions.Unlock(argList) {{{2
250 function! s:bzrFunctions.Unlock(argList)
251 echomsg 'bzr unlock is not necessary'
253 " Function: s:bzrFunctions.Update(argList) {{{2
254 function! s:bzrFunctions.Update(argList)
255 return s:DoCommand('update', 'update', '', {})
258 " Annotate setting {{{2
259 let s:bzrFunctions.AnnotateSplitRegex = '^[^|]\+ | '
261 " Section: Plugin Registration {{{1
262 let s:VCSCommandUtility = VCSCommandRegisterModule('BZR', expand('<sfile>'), s:bzrFunctions, [])
264 let &cpo = s:save_cpo