~spacexplorer/+junk/myenv

« back to all changes in this revision

Viewing changes to vim/vim/plugin/vcssccs.vim

  • Committer: Kim Allamandola
  • Date: 2011-05-02 05:39:17 UTC
  • Revision ID: spacexplorer@gmail.com-20110502053917-x0yl2lr9ri4yskr2
InitĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
" vim600: set foldmethod=marker:
 
2
"
 
3
" Mercurial extension for VCSCommand. This extension is based on svn extension
 
4
" to VCSCommand made by Bob Hiestand <bob.hiestand@gmail.com>
 
5
"
 
6
" Version:       1
 
7
" Maintainer:    Vladimir Marek <vlmarek@volny.cz>
 
8
" License:
 
9
" Copyright (c) 2007 Vladimir Marek
 
10
"
 
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:
 
17
"
 
18
" The above copyright notice and this permission notice shall be included in
 
19
" all copies or substantial portions of the Software.
 
20
"
 
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
 
27
" IN THE SOFTWARE.
 
28
"
 
29
" Section: Documentation {{{1
 
30
"
 
31
" Command documentation {{{2
 
32
"
 
33
" The following command only applies to files under SCCS source control.
 
34
"
 
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
 
38
"
 
39
" Add
 
40
" Delete
 
41
" Lock
 
42
" Revert
 
43
" Unlock
 
44
" Update
 
45
"
 
46
" Mapping documentation: {{{2
 
47
"
 
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:
 
50
"
 
51
" None currently
 
52
"
 
53
" The default mappings are as follow:
 
54
"
 
55
" None currently
 
56
"
 
57
" Options documentation: {{{2
 
58
"
 
59
" VCSCommandSCCSPath
 
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
 
62
 
 
63
if v:version < 700
 
64
  finish
 
65
endif
 
66
 
 
67
" Section: Variable initialization {{{1
 
68
 
 
69
let s:sccsFunctions = {}
 
70
let s:pushdList = []
 
71
 
 
72
" Section: Mercurial help functions {{{1
 
73
 
 
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))
 
79
endfunction
 
80
 
 
81
" Function: s:Popd()
 
82
" Does reverse of s:Pushd, similar to shell popd
 
83
function! s:Popd()
 
84
  execute 'cd' escape(remove(s:pushdList,0), ' ')
 
85
endfunction
 
86
 
 
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
 
99
  endif
 
100
  let realFileName = fnamemodify(resolve(fileName), ':t')
 
101
  call s:Pushd(fileName)
 
102
  return [originalBuffer, fileName, realFileName]
 
103
endfunction
 
104
 
 
105
" Section: Utility functions {{{1
 
106
 
 
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)
 
110
  try
 
111
    if VCSCommandGetVCSType(expand('%')) == 'SCCS'
 
112
      let fullCmd = VCSCommandGetOption('VCSCommandSCCSPath', '') . a:binary . ' ' . a:cmd
 
113
      return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText)
 
114
    else
 
115
      throw 'No suitable plugin'
 
116
    endif
 
117
  catch /No suitable plugin/
 
118
    echohl WarningMsg|echomsg 'Cannot apply SCCS commands to this file.'|echohl None
 
119
  endtry
 
120
endfunction
 
121
 
 
122
" Section: VCS function implementations {{{1
 
123
 
 
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
 
129
  else
 
130
    let directoryName = fnamemodify(fileName, ':h')
 
131
  endif
 
132
  if strlen(directoryName) > 0
 
133
    let sccsDir = directoryName . '/SCCS'
 
134
  else
 
135
    let sccsDir = 'SCCS'
 
136
  endif
 
137
  if isdirectory(sccsDir)
 
138
    return 1
 
139
  else
 
140
    return 0
 
141
  endif
 
142
endfunction
 
143
 
 
144
" Function: s:sccsFunctions.Add() {{{2
 
145
function! s:sccsFunctions.Add(argList)
 
146
  echoerr "vcssccs: VCSAdd not implemented"
 
147
endfunction
 
148
 
 
149
" Function: s:sccsFunctions.Annotate(argList) {{{2
 
150
function! s:sccsFunctions.Annotate(argList)
 
151
  let [originalBuffer, fileName, realFileName] = s:getToMyBuffer()
 
152
  try
 
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+')
 
157
      else
 
158
        let revision=VCSCommandGetRevision()
 
159
        if revision == ''
 
160
          throw 'vcssccs: Unable to obtain version information.'
 
161
        endif
 
162
      endif
 
163
    else
 
164
      let revision=a:argList[0]
 
165
    endif
 
166
 
 
167
    let resultBuffer=s:DoCommand('sccs', 'get -p -m -s -r' . revision . ' "'. realFileName . '"', 'annotate', revision) 
 
168
    if resultBuffer > 0
 
169
      set filetype=SCCSAnnotate
 
170
    endif
 
171
    return resultBuffer
 
172
  finally
 
173
    call s:Popd()
 
174
  endtry
 
175
endfunction
 
176
 
 
177
" Function: s:sccsFunctions.Commit(argList) {{{2
 
178
function! s:sccsFunctions.Commit(argList)
 
179
"  g/^VCS:/d
 
180
"  %s/\n/\\\\/g
 
181
 
 
182
"  This commits only first line :(
 
183
"  return s:DoCommand("sccs", "deledit <" . a:argList[0] , 'commit', '')
 
184
 
 
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', '')
 
187
endfunction
 
188
 
 
189
" Function: s:sccsFunctions.Delete() {{{2
 
190
function! s:sccsFunctions.Delete(argList)
 
191
  echoerr "vcssccs: VCSDelete not implemented"
 
192
endfunction
 
193
 
 
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
 
200
    let command = 'sccs'
 
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] . ')'
 
207
  else
 
208
    let command = 'sccs'
 
209
    let revOptions = 'diffs -u'
 
210
    let caption = ''
 
211
  endif
 
212
 
 
213
  let resultBuffer = s:DoCommand(command, revOptions , 'diff', caption)
 
214
  if resultBuffer > 0
 
215
    set filetype=diff
 
216
  else
 
217
    echomsg 'No differences found'
 
218
  endif
 
219
  return resultBuffer
 
220
endfunction
 
221
 
 
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]
 
227
 
 
228
function! s:sccsFunctions.GetBufferInfo()
 
229
  let [originalBuffer, fileName, realFileName] = s:getToMyBuffer()
 
230
  try
 
231
    let statusText=system(VCSCommandGetOption('VCSCommandSCCSPath', '') . 'sccs prt -y "' . realFileName . '"')
 
232
    if(v:shell_error)
 
233
      return []
 
234
    endif
 
235
 
 
236
    " Error is returned above anyway
 
237
    if statusText =~ ' nonexistent (ut4)'
 
238
      return ['Unknown']
 
239
    endif
 
240
 
 
241
    " We can't have 'new', sccs create already commits the file
 
242
"   if statusText =~ '^A'
 
243
"     return ['New']
 
244
"   endif
 
245
 
 
246
    let statusText=substitute(statusText, '^[^\t]*...', "", "")
 
247
    let statusText=substitute(statusText, "\t.*", "", "")
 
248
 
 
249
    return [statusText]
 
250
  finally
 
251
    call s:Popd()
 
252
  endtry
 
253
endfunction
 
254
 
 
255
" Function: s:sccsFunctions.Lock(argList) {{{2
 
256
function! s:sccsFunctions.Lock(argList)
 
257
  echoerr "vcssccs: VCSLock not implemented"
 
258
endfunction
 
259
 
 
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 = ''
 
266
    let caption = ''
 
267
  else
 
268
    let versionOption=' -y' . a:argList[0]
 
269
    let caption = a:argList[0]
 
270
  endif
 
271
 
 
272
  let resultBuffer=s:DoCommand('sccs', 'prt ' . versionOption, 'log', caption)
 
273
  return resultBuffer
 
274
endfunction
 
275
 
 
276
" Function: s:sccsFunctions.Revert(argList) {{{2
 
277
function! s:sccsFunctions.Revert(argList)
 
278
  echoerr "vcssccs: VCSRevert not implemented"
 
279
endfunction
 
280
 
 
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 = ''
 
286
  else
 
287
    let versiontag = a:argList[0]
 
288
    let versionOption = ' -r ' . versiontag . ' '
 
289
  endif
 
290
 
 
291
  let resultBuffer = s:DoCommand('sccs', 'get -p -s -k' . versionOption, 'review', versiontag)
 
292
  if resultBuffer > 0
 
293
    let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
 
294
  endif
 
295
  return resultBuffer
 
296
endfunction
 
297
 
 
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, ' '))
 
301
endfunction
 
302
 
 
303
" Function: s:sccsFunctions.Unlock(argList) {{{2
 
304
function! s:sccsFunctions.Unlock(argList)
 
305
  echoerr "vcssccs: VCSUnlock not implemented"
 
306
endfunction
 
307
 
 
308
" Function: s:sccsFunctions.Update(argList) {{{2
 
309
function! s:sccsFunctions.Update(argList)
 
310
  echoerr "vcssccs: VCSUpdate not implemented"
 
311
endfunction
 
312
 
 
313
" Section: SCCS-specific functions {{{1
 
314
 
 
315
" Section: Command definitions {{{1
 
316
" Section: Primary commands {{{2
 
317
 
 
318
" None currently
 
319
 
 
320
" Section: Plugin command mappings {{{1
 
321
 
 
322
let s:sccsExtensionMappings = {}
 
323
let mappingInfo = []
 
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
 
328
  endif
 
329
endfor
 
330
 
 
331
" Section: Menu items {{{1
 
332
" None currently
 
333
 
 
334
" Section: Plugin Registration {{{1
 
335
" If the vcscommand.vim plugin hasn't loaded, delay registration until it
 
336
" loads.
 
337
if exists('g:loaded_VCSCommand')
 
338
  call VCSCommandRegisterModule('SCCS', expand('<sfile>'), s:sccsFunctions, s:sccsExtensionMappings)
 
339
else
 
340
  augroup VCSCommand
 
341
    au User VCSLoadExtensions call VCSCommandRegisterModule('SCCS', expand('<sfile>'), s:sccsFunctions, s:sccsExtensionMappings)
 
342
  augroup END
 
343
endif