2013-09-30 04:19:31 -04:00
|
|
|
" vim: et sw=2 sts=2
|
|
|
|
|
2013-08-19 11:36:16 -04:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-07-17 06:44:21 -04:00
|
|
|
" Init: values {{{1
|
2013-10-30 07:15:33 -04:00
|
|
|
let g:signify_sign_overwrite = get(g:, 'signify_sign_overwrite')
|
2013-09-30 03:40:46 -04:00
|
|
|
if g:signify_sign_overwrite && (v:version < 703 || (v:version == 703 && !has('patch596')))
|
|
|
|
echohl WarningMsg
|
2013-10-30 07:12:54 -04:00
|
|
|
echomsg 'signify: Sign overwriting was disabled. See :help signify-option-sign_overwrite'
|
2013-09-30 03:40:46 -04:00
|
|
|
echohl NONE
|
|
|
|
let g:signify_sign_overwrite = 0
|
|
|
|
endif
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
let g:id_top = 0x100
|
2013-09-12 19:23:05 -04:00
|
|
|
let g:sy_cache = {}
|
2013-07-17 06:30:58 -04:00
|
|
|
|
2013-07-29 09:09:00 -04:00
|
|
|
sign define SignifyPlaceholder text=. texthl=SignifySignChange linehl=
|
2013-07-17 06:30:58 -04:00
|
|
|
|
|
|
|
" Function: #start {{{1
|
|
|
|
function! sy#start(path) abort
|
2013-07-17 07:45:06 -04:00
|
|
|
if &diff
|
|
|
|
\ || !filereadable(a:path)
|
2013-07-17 06:30:58 -04:00
|
|
|
\ || (exists('g:signify_skip_filetype') && has_key(g:signify_skip_filetype, &ft))
|
|
|
|
\ || (exists('g:signify_skip_filename') && has_key(g:signify_skip_filename, a:path))
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-07-29 10:14:49 -04:00
|
|
|
" new buffer.. add to list of registered files
|
2013-08-01 05:40:41 -04:00
|
|
|
if !has_key(g:sy, a:path)
|
2013-07-29 10:14:49 -04:00
|
|
|
if get(g:, 'signify_disable_by_default')
|
2013-11-03 12:50:42 -05:00
|
|
|
" register file as inactive
|
2013-08-22 13:06:02 -04:00
|
|
|
let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [-1, -1, -1] }
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-07-29 10:14:49 -04:00
|
|
|
|
|
|
|
let [ diff, type ] = sy#repo#detect(a:path)
|
2013-11-03 12:50:42 -05:00
|
|
|
if type == 'unknown'
|
|
|
|
" register file as active with no found VCS
|
2013-08-20 06:50:36 -04:00
|
|
|
let g:sy[a:path] = { 'active': 1, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] }
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-07-29 10:14:49 -04:00
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
" register file as active with found VCS
|
2013-08-20 06:50:36 -04:00
|
|
|
let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] }
|
2013-08-01 05:40:41 -04:00
|
|
|
|
2013-09-12 19:23:05 -04:00
|
|
|
let dir = fnamemodify(a:path, ':h')
|
|
|
|
if !has_key(g:sy_cache, dir)
|
|
|
|
let g:sy_cache[dir] = type
|
|
|
|
endif
|
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
if empty(diff)
|
|
|
|
" no changes found
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" inactive buffer.. bail out
|
|
|
|
elseif !g:sy[a:path].active
|
|
|
|
return
|
2013-08-01 05:40:41 -04:00
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
" retry detecting VCS
|
2013-08-01 05:40:41 -04:00
|
|
|
elseif g:sy[a:path].type == 'unknown'
|
|
|
|
let [ diff, type ] = sy#repo#detect(a:path)
|
2013-11-03 12:50:42 -05:00
|
|
|
if type == 'unknown'
|
|
|
|
" no VCS found
|
2013-08-01 05:40:41 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
let g:sy[a:path].type = type
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" update signs
|
|
|
|
else
|
2013-11-03 12:50:42 -05:00
|
|
|
let [ _, diff ] = sy#repo#get_diff_{g:sy[a:path].type}(a:path)
|
2013-07-17 06:30:58 -04:00
|
|
|
if empty(diff)
|
|
|
|
call sy#sign#remove_all(a:path)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let g:sy[a:path].id_top = g:id_top
|
|
|
|
endif
|
|
|
|
|
|
|
|
if get(g:, 'signify_line_highlight')
|
|
|
|
call sy#highlight#line_enable()
|
|
|
|
else
|
|
|
|
call sy#highlight#line_disable()
|
|
|
|
endif
|
|
|
|
|
2013-09-06 11:10:57 -04:00
|
|
|
execute 'sign place 99999 line=1 name=SignifyPlaceholder file='. a:path
|
|
|
|
call sy#sign#remove_all(a:path)
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
if !g:signify_sign_overwrite
|
|
|
|
call sy#sign#get_others(a:path)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call sy#repo#process_diff(a:path, diff)
|
|
|
|
sign unplace 99999
|
|
|
|
|
|
|
|
let g:sy[a:path].id_top = (g:id_top - 1)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: #stop {{{1
|
|
|
|
function! sy#stop(path) abort
|
|
|
|
if !has_key(g:sy, a:path)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call sy#sign#remove_all(a:path)
|
|
|
|
|
|
|
|
silent! nunmap <buffer> ]c
|
|
|
|
silent! nunmap <buffer> [c
|
|
|
|
|
|
|
|
augroup signify
|
|
|
|
autocmd! * <buffer>
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: #toggle {{{1
|
|
|
|
function! sy#toggle() abort
|
|
|
|
if empty(g:sy_path)
|
|
|
|
echomsg 'signify: I cannot sy empty buffers!'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(g:sy, g:sy_path)
|
|
|
|
if g:sy[g:sy_path].active
|
|
|
|
call sy#stop(g:sy_path)
|
|
|
|
let g:sy[g:sy_path].active = 0
|
2013-08-22 12:58:37 -04:00
|
|
|
let g:sy[g:sy_path].stats = [-1, -1, -1]
|
2013-07-17 06:30:58 -04:00
|
|
|
else
|
|
|
|
let g:sy[g:sy_path].active = 1
|
|
|
|
call sy#start(g:sy_path)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call sy#start(g:sy_path)
|
|
|
|
endif
|
|
|
|
endfunction
|