1
" vim600: set foldmethod=marker:
3
" Mercurial extension for VCSCommand. This extension is based on svn extension
4
" to VCSCommand made by Bob Hiestand <bob.hiestand@gmail.com>
7
" Maintainer: Vladimir Marek <vlmarek@volny.cz>
9
" Copyright (c) 2007 Vladimir Marek
11
" Permission is hereby granted, free of charge, to any person obtaining a copy
12
" of this software and associated documentation files (the "Software"), to
13
" deal in the Software without restriction, including without limitation the
14
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
" sell copies of the Software, and to permit persons to whom the Software is
16
" furnished to do so, subject to the following conditions:
18
" The above copyright notice and this permission notice shall be included in
19
" all copies or substantial portions of the Software.
21
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
" Section: Documentation {{{1
31
" Command documentation {{{2
33
" The following command only applies to files under SCCS source control.
35
" Those functions are NOT implemented (yet?). Their implementation would differ
36
" for using sccs or TeamWare. Current implementation has enough features to
37
" support VCSVimDiff and VCSAnnotate
46
" Mapping documentation: {{{2
48
" By default, a mapping is defined for each command. User-provided mappings
49
" can be used instead by mapping to <Plug>CommandName, for instance:
53
" The default mappings are as follow:
57
" Options documentation: {{{2
60
" This variable specifies path to the sccs binaries. If not set, it defaults
61
" to empty string (which means use your $PATH). If set, it MUST end by slash
67
" Section: Variable initialization {{{1
69
let s:sccsFunctions = {}
72
" Section: Mercurial help functions {{{1
74
" Function: s:Pushd(filename)
75
" Similar to pushd in shell. Argument can be either directory or filename next
76
" to which we want to get
77
function! s:Pushd(filename)
78
call insert (s:pushdList, VCSCommandChangeToCurrentFileDir(a:filename))
82
" Does reverse of s:Pushd, similar to shell popd
84
execute 'cd' escape(remove(s:pushdList,0), ' ')
87
" Function: s:getToMyBuffer()
88
" Does several things:
89
" * Tries to get original buffer number (1)
90
" * Tries to get original buffer name (2)
91
" * Tries to get just filename (3)
92
" * Chdirs to the filename (uses s:Pushd(...))
93
" * Returns [(1), (2), (3)]
94
function! s:getToMyBuffer()
95
let originalBuffer=VCSCommandGetOriginalBuffer(bufnr('%'))
96
let fileName=bufname(originalBuffer)
97
if !filereadable(fileName)
98
throw 'Unable to access the file '.fileName
100
let realFileName = fnamemodify(resolve(fileName), ':t')
101
call s:Pushd(fileName)
102
return [originalBuffer, fileName, realFileName]
105
" Section: Utility functions {{{1
107
" Function: s:DoCommand(binary, cmd, cmdName, statusText) {{{2
108
" Wrapper to VCSCommandDoCommand to add the path to sccs tools
109
function! s:DoCommand(binary, cmd, cmdName, statusText)
111
if VCSCommandGetVCSType(expand('%')) == 'SCCS'
112
let fullCmd = VCSCommandGetOption('VCSCommandSCCSPath', '') . a:binary . ' ' . a:cmd
113
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText)
115
throw 'No suitable plugin'
117
catch /No suitable plugin/
118
echohl WarningMsg|echomsg 'Cannot apply SCCS commands to this file.'|echohl None
122
" Section: VCS function implementations {{{1
124
" Function: s:sccsFunctions.Identify(buffer) {{{2
125
function! s:sccsFunctions.Identify(buffer)
126
let fileName = resolve(bufname(a:buffer))
127
if isdirectory(fileName)
128
let directoryName = fileName
130
let directoryName = fnamemodify(fileName, ':h')
132
if strlen(directoryName) > 0
133
let sccsDir = directoryName . '/SCCS'
137
if isdirectory(sccsDir)
144
" Function: s:sccsFunctions.Add() {{{2
145
function! s:sccsFunctions.Add(argList)
146
echoerr "vcssccs: VCSAdd not implemented"
149
" Function: s:sccsFunctions.Annotate(argList) {{{2
150
function! s:sccsFunctions.Annotate(argList)
151
let [originalBuffer, fileName, realFileName] = s:getToMyBuffer()
153
if len(a:argList) == 0
154
if &filetype == 'SCCSAnnotate'
155
" Perform annotation of the version indicated by the current line.
156
let revision = matchstr(getline('.'),'\v^\s*\zs\d+\.\d+')
158
let revision=VCSCommandGetRevision()
160
throw 'vcssccs: Unable to obtain version information.'
164
let revision=a:argList[0]
167
let resultBuffer=s:DoCommand('sccs', 'get -p -m -s -r' . revision . ' "'. realFileName . '"', 'annotate', revision)
169
set filetype=SCCSAnnotate
177
" Function: s:sccsFunctions.Commit(argList) {{{2
178
function! s:sccsFunctions.Commit(argList)
182
" This commits only first line :(
183
" return s:DoCommand("sccs", "deledit <" . a:argList[0] , 'commit', '')
185
" This seems to work ok, but may depend on your shell installed ...
186
return s:DoCommand("sccs", "deledit -y\"$(cat " . a:argList[0] .")\"" , 'commit', '')
189
" Function: s:sccsFunctions.Delete() {{{2
190
function! s:sccsFunctions.Delete(argList)
191
echoerr "vcssccs: VCSDelete not implemented"
194
" 0 args - current file
195
" 1 args - current file revision REV
196
" 2 args - current file revisions REV1 & REV2
197
" Function: s:sccsFunctions.Diff(argList) {{{2
198
function! s:sccsFunctions.Diff(argList)
199
if len(a:argList) == 1 " Compare working copy
201
let revOptions = 'diffs -r' . a:argList[0] . ' -u'
202
let caption = '(' . a:argList[0] . ' : working copy)'
203
elseif len(a:argList) == 2
204
let command = 'sccsdiff'
205
let revOptions = ' -r ' . a:argList[0] . ' -r ' . a:argList[1] . ' -u'
206
let caption = '(' . a:argList[0] . ' : ' . a:argList[1] . ')'
209
let revOptions = 'diffs -u'
213
let resultBuffer = s:DoCommand(command, revOptions , 'diff', caption)
217
echomsg 'No differences found'
222
" Function: s:sccsFunctions.GetBufferInfo() {{{2
223
" Provides version control details for the current file. Current version
224
" number and current repository version number are required to be returned by
225
" the vcscommand plugin.
226
" Returns: List of results: [revision, repository, branch]
228
function! s:sccsFunctions.GetBufferInfo()
229
let [originalBuffer, fileName, realFileName] = s:getToMyBuffer()
231
let statusText=system(VCSCommandGetOption('VCSCommandSCCSPath', '') . 'sccs prt -y "' . realFileName . '"')
236
" Error is returned above anyway
237
if statusText =~ ' nonexistent (ut4)'
241
" We can't have 'new', sccs create already commits the file
242
" if statusText =~ '^A'
246
let statusText=substitute(statusText, '^[^\t]*...', "", "")
247
let statusText=substitute(statusText, "\t.*", "", "")
255
" Function: s:sccsFunctions.Lock(argList) {{{2
256
function! s:sccsFunctions.Lock(argList)
257
echoerr "vcssccs: VCSLock not implemented"
260
" 0 parameters - full log
261
" 1 parameter - log of the given commit
262
" Function: s:sccsFunctions.Log() {{{2
263
function! s:sccsFunctions.Log(argList)
264
if len(a:argList) == 0
265
let versionOption = ''
268
let versionOption=' -y' . a:argList[0]
269
let caption = a:argList[0]
272
let resultBuffer=s:DoCommand('sccs', 'prt ' . versionOption, 'log', caption)
276
" Function: s:sccsFunctions.Revert(argList) {{{2
277
function! s:sccsFunctions.Revert(argList)
278
echoerr "vcssccs: VCSRevert not implemented"
281
" Function: s:sccsFunctions.Review(argList) {{{2
282
function! s:sccsFunctions.Review(argList)
283
if len(a:argList) == 0
284
let versiontag = '(current)'
285
let versionOption = ''
287
let versiontag = a:argList[0]
288
let versionOption = ' -r ' . versiontag . ' '
291
let resultBuffer = s:DoCommand('sccs', 'get -p -s -k' . versionOption, 'review', versiontag)
293
let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
298
" Function: s:sccsFunctions.Status(argList) {{{2
299
function! s:sccsFunctions.Status(argList)
300
return s:DoCommand('sccs', join(['sact'] + a:argList, ' '), 'status', join(a:argList, ' '))
303
" Function: s:sccsFunctions.Unlock(argList) {{{2
304
function! s:sccsFunctions.Unlock(argList)
305
echoerr "vcssccs: VCSUnlock not implemented"
308
" Function: s:sccsFunctions.Update(argList) {{{2
309
function! s:sccsFunctions.Update(argList)
310
echoerr "vcssccs: VCSUpdate not implemented"
313
" Section: SCCS-specific functions {{{1
315
" Section: Command definitions {{{1
316
" Section: Primary commands {{{2
320
" Section: Plugin command mappings {{{1
322
let s:sccsExtensionMappings = {}
324
for [pluginName, commandText, shortCut] in mappingInfo
325
execute 'nnoremap <silent> <Plug>' . pluginName . ' :' . commandText . '<CR>'
326
if !hasmapto('<Plug>' . pluginName)
327
let s:sccsExtensionMappings[shortCut] = commandText
331
" Section: Menu items {{{1
334
" Section: Plugin Registration {{{1
335
" If the vcscommand.vim plugin hasn't loaded, delay registration until it
337
if exists('g:loaded_VCSCommand')
338
call VCSCommandRegisterModule('SCCS', expand('<sfile>'), s:sccsFunctions, s:sccsExtensionMappings)
341
au User VCSLoadExtensions call VCSCommandRegisterModule('SCCS', expand('<sfile>'), s:sccsFunctions, s:sccsExtensionMappings)