config/.vim/plugin/vcssvn.vim

282 lines
8.6 KiB
VimL
Raw Normal View History

2009-11-01 19:04:42 +01:00
" vim600: set foldmethod=marker:
"
" SVN extension for VCSCommand.
"
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
2013-03-01 17:29:45 +01:00
" Copyright (c) Bob Hiestand
2009-11-01 19:04:42 +01:00
"
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to
" deal in the Software without restriction, including without limitation the
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
" sell copies of the Software, and to permit persons to whom the Software is
" furnished to do so, subject to the following conditions:
"
" The above copyright notice and this permission notice shall be included in
" all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
" IN THE SOFTWARE.
"
" Section: Documentation {{{1
"
" Options documentation: {{{2
"
" VCSCommandSVNExec
" This variable specifies the SVN executable. If not set, it defaults to
" 'svn' executed from the user's executable path.
"
" VCSCommandSVNDiffExt
" This variable, if set, sets the external diff program used by Subversion.
"
" VCSCommandSVNDiffOpt
" This variable, if set, determines the options passed to the svn diff
" command (such as 'u', 'w', or 'b').
" Section: Plugin header {{{1
2013-03-01 17:29:45 +01:00
if exists('VCSCommandDisableAll')
finish
endif
2009-11-01 19:04:42 +01:00
if v:version < 700
echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
finish
endif
2013-03-01 17:29:45 +01:00
if !exists('g:loaded_VCSCommand')
runtime plugin/vcscommand.vim
endif
2009-11-01 19:04:42 +01:00
if !executable(VCSCommandGetOption('VCSCommandSVNExec', 'svn'))
" SVN is not installed
finish
endif
let s:save_cpo=&cpo
set cpo&vim
" Section: Variable initialization {{{1
let s:svnFunctions = {}
" Section: Utility functions {{{1
2013-03-01 17:29:45 +01:00
" Function: s:Executable() {{{2
" Returns the executable used to invoke git suitable for use in a shell
" command.
function! s:Executable()
return VCSCommandGetOption('VCSCommandSVNExec', 'svn')
endfunction
2009-11-01 19:04:42 +01:00
" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2
" Wrapper to VCSCommandDoCommand to add the name of the SVN executable to the
" command argument.
function! s:DoCommand(cmd, cmdName, statusText, options)
if VCSCommandGetVCSType(expand('%')) == 'SVN'
2013-03-01 17:29:45 +01:00
let fullCmd = s:Executable() . ' ' . a:cmd
2009-11-01 19:04:42 +01:00
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
else
throw 'SVN VCSCommand plugin called on non-SVN item.'
endif
endfunction
" Section: VCS function implementations {{{1
" Function: s:svnFunctions.Identify(buffer) {{{2
function! s:svnFunctions.Identify(buffer)
2013-03-01 17:29:45 +01:00
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer)))
try
call s:VCSCommandUtility.system(s:Executable() . ' info .')
if(v:shell_error)
return 0
else
return g:VCSCOMMAND_IDENTIFY_EXACT
endif
finally
call VCSCommandChdir(oldCwd)
endtry
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Add() {{{2
function! s:svnFunctions.Add(argList)
return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
endfunction
" Function: s:svnFunctions.Annotate(argList) {{{2
function! s:svnFunctions.Annotate(argList)
if len(a:argList) == 0
2013-03-01 17:29:45 +01:00
if &filetype ==? 'svnannotate'
2009-11-01 19:04:42 +01:00
" Perform annotation of the version indicated by the current line.
let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
let options = ' -r' . caption
else
let caption = ''
let options = ''
endif
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
let caption = a:argList[0]
let options = ' -r' . caption
else
let caption = join(a:argList, ' ')
let options = ' ' . caption
endif
2013-03-01 17:29:45 +01:00
return s:DoCommand('blame --non-interactive' . options, 'annotate', caption, {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Commit(argList) {{{2
function! s:svnFunctions.Commit(argList)
2013-03-01 17:29:45 +01:00
let resultBuffer = s:DoCommand('commit --non-interactive -F "' . a:argList[0] . '"', 'commit', '', {})
2009-11-01 19:04:42 +01:00
if resultBuffer == 0
echomsg 'No commit needed.'
endif
endfunction
" Function: s:svnFunctions.Delete() {{{2
function! s:svnFunctions.Delete(argList)
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['delete --non-interactive'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Diff(argList) {{{2
function! s:svnFunctions.Diff(argList)
if len(a:argList) == 0
2013-03-01 17:29:45 +01:00
let revOptions = []
2009-11-01 19:04:42 +01:00
let caption = ''
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
let revOptions = ['-r' . join(a:argList, ':')]
let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
else
" Pass-through
let caption = join(a:argList, ' ')
let revOptions = a:argList
endif
let svnDiffExt = VCSCommandGetOption('VCSCommandSVNDiffExt', '')
if svnDiffExt == ''
let diffExt = []
else
let diffExt = ['--diff-cmd ' . svnDiffExt]
endif
let svnDiffOpt = VCSCommandGetOption('VCSCommandSVNDiffOpt', '')
if svnDiffOpt == ''
let diffOptions = []
else
let diffOptions = ['-x -' . svnDiffOpt]
endif
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['diff --non-interactive'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.GetBufferInfo() {{{2
" Provides version control details for the current file. Current version
" number and current repository version number are required to be returned by
" the vcscommand plugin.
" Returns: List of results: [revision, repository, branch]
function! s:svnFunctions.GetBufferInfo()
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
let fileName = bufname(originalBuffer)
2013-03-01 17:29:45 +01:00
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status --non-interactive -v -- "' . fileName . '"')
2009-11-01 19:04:42 +01:00
if(v:shell_error)
return []
endif
" File not under SVN control.
if statusText =~ '^?'
return ['Unknown']
endif
2013-03-01 17:29:45 +01:00
let [flags, revision, repository] = matchlist(statusText, '^\(.\{9}\)\s*\(\d\+\)\s\+\(\d\+\)')[1:3]
2009-11-01 19:04:42 +01:00
if revision == ''
" Error
return ['Unknown']
elseif flags =~ '^A'
return ['New', 'New']
2013-03-01 17:29:45 +01:00
elseif flags =~ '*'
return [revision, repository, '*']
2009-11-01 19:04:42 +01:00
else
return [revision, repository]
endif
endfunction
" Function: s:svnFunctions.Info(argList) {{{2
function! s:svnFunctions.Info(argList)
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['info --non-interactive'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Lock(argList) {{{2
function! s:svnFunctions.Lock(argList)
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['lock --non-interactive'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Log(argList) {{{2
function! s:svnFunctions.Log(argList)
if len(a:argList) == 0
let options = []
let caption = ''
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
let options = ['-r' . join(a:argList, ':')]
let caption = options[0]
else
" Pass-through
let options = a:argList
let caption = join(a:argList, ' ')
endif
2013-03-01 17:29:45 +01:00
let resultBuffer = s:DoCommand(join(['log --non-interactive', '-v'] + options), 'log', caption, {})
2009-11-01 19:04:42 +01:00
return resultBuffer
endfunction
" Function: s:svnFunctions.Revert(argList) {{{2
function! s:svnFunctions.Revert(argList)
return s:DoCommand('revert', 'revert', '', {})
endfunction
" Function: s:svnFunctions.Review(argList) {{{2
function! s:svnFunctions.Review(argList)
if len(a:argList) == 0
let versiontag = '(current)'
let versionOption = ''
else
let versiontag = a:argList[0]
let versionOption = ' -r ' . versiontag . ' '
endif
2013-03-01 17:29:45 +01:00
return s:DoCommand('cat --non-interactive' . versionOption, 'review', versiontag, {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Status(argList) {{{2
function! s:svnFunctions.Status(argList)
let options = ['-u', '-v']
2013-03-01 17:29:45 +01:00
if len(a:argList) != 0
2009-11-01 19:04:42 +01:00
let options = a:argList
endif
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['status --non-interactive'] + options, ' '), 'status', join(options, ' '), {})
2009-11-01 19:04:42 +01:00
endfunction
" Function: s:svnFunctions.Unlock(argList) {{{2
function! s:svnFunctions.Unlock(argList)
2013-03-01 17:29:45 +01:00
return s:DoCommand(join(['unlock --non-interactive'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
2009-11-01 19:04:42 +01:00
endfunction
2013-03-01 17:29:45 +01:00
2009-11-01 19:04:42 +01:00
" Function: s:svnFunctions.Update(argList) {{{2
function! s:svnFunctions.Update(argList)
2013-03-01 17:29:45 +01:00
return s:DoCommand('update --non-interactive', 'update', '', {})
2009-11-01 19:04:42 +01:00
endfunction
2013-03-01 17:29:45 +01:00
" Annotate setting {{{2
let s:svnFunctions.AnnotateSplitRegex = '\s\+\S\+\s\+\S\+ '
2009-11-01 19:04:42 +01:00
" Section: Plugin Registration {{{1
2013-03-01 17:29:45 +01:00
let s:VCSCommandUtility = VCSCommandRegisterModule('SVN', expand('<sfile>'), s:svnFunctions, [])
2009-11-01 19:04:42 +01:00
let &cpo = s:save_cpo