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:30:58 -04:00
|
|
|
" Init: values {{{1
|
2013-11-14 21:55:22 -05:00
|
|
|
if !exists('g:signify_diffoptions')
|
|
|
|
let g:signify_diffoptions = {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:difftool = get(g:, 'signify_difftool', 'diff')
|
2013-11-03 09:48:50 -05:00
|
|
|
|
|
|
|
if executable(s:difftool)
|
|
|
|
let s:vcs_dict = {
|
|
|
|
\ 'git': 'git',
|
|
|
|
\ 'hg': 'hg',
|
|
|
|
\ 'svn': 'svn',
|
|
|
|
\ 'darcs': 'darcs',
|
|
|
|
\ 'bzr': 'bzr',
|
|
|
|
\ 'fossil': 'fossil',
|
|
|
|
\ 'cvs': 'cvs',
|
|
|
|
\ 'rcs': 'rcsdiff',
|
|
|
|
\ 'accurev': 'accurev',
|
|
|
|
\ 'perforce': 'p4'
|
|
|
|
\ }
|
|
|
|
else
|
|
|
|
echomsg 'signify: No diff tool found -> no support for svn, darcs, bzr, fossil.'
|
|
|
|
let s:vcs_dict = {
|
|
|
|
\ 'git': 'git',
|
|
|
|
\ 'hg': 'hg',
|
|
|
|
\ 'cvs': 'cvs',
|
|
|
|
\ 'rcs': 'rcsdiff',
|
|
|
|
\ 'accurev': 'accurev',
|
|
|
|
\ 'perforce': 'p4'
|
|
|
|
\ }
|
|
|
|
endif
|
2013-09-11 17:13:51 -04:00
|
|
|
|
2013-09-15 19:29:11 -04:00
|
|
|
let s:vcs_list = get(g:, 'signify_vcs_list', [])
|
2013-09-15 13:45:24 -04:00
|
|
|
if empty(s:vcs_list)
|
|
|
|
let s:vcs_list = keys(filter(s:vcs_dict, 'executable(v:val)'))
|
|
|
|
endif
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #detect {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#detect() abort
|
|
|
|
let dir = fnamemodify(b:sy.path, ':h')
|
2013-09-12 19:23:05 -04:00
|
|
|
|
2014-10-23 17:44:32 -04:00
|
|
|
let vcs_list = s:vcs_list
|
2013-09-12 19:23:05 -04:00
|
|
|
" Simple cache. If there is a registered VCS-controlled file in this
|
|
|
|
" directory already, assume that this file is probably controlled by
|
2014-10-23 17:44:32 -04:00
|
|
|
" the same VCS. Thus we shuffle that VCS to the top of our copy of
|
|
|
|
" s:vcs_list, so we don't affect the preference order of s:vcs_list.
|
2013-09-12 19:23:05 -04:00
|
|
|
if has_key(g:sy_cache, dir)
|
2014-10-23 17:44:32 -04:00
|
|
|
let vcs_list = [g:sy_cache[dir]] + filter(copy(s:vcs_list), 'v:val != "'. g:sy_cache[dir] .'"')
|
2013-09-12 19:23:05 -04:00
|
|
|
endif
|
|
|
|
|
2014-10-23 17:44:32 -04:00
|
|
|
for type in vcs_list
|
2013-11-21 20:57:43 -05:00
|
|
|
let [istype, diff] = sy#repo#get_diff_{type}()
|
2013-11-03 12:50:42 -05:00
|
|
|
if istype
|
2013-07-17 04:14:43 -04:00
|
|
|
return [ diff, type ]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
return [ '', 'unknown' ]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_git {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_git() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'git') ? g:signify_diffoptions.git : ''
|
2014-10-09 16:35:17 -04:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'git diff --no-color --no-ext-diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(b:sy.path, ':t')))
|
2013-11-03 12:50:42 -05:00
|
|
|
|
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_stat_git {{{1
|
2013-07-17 04:14:43 -04:00
|
|
|
function! sy#repo#get_stat_git() abort
|
|
|
|
let s:stats = []
|
2013-11-21 20:57:43 -05:00
|
|
|
let root = finddir('.git', fnamemodify(b:sy.path, ':h') .';')
|
2013-07-17 04:14:43 -04:00
|
|
|
if empty(root)
|
2013-11-21 20:57:43 -05:00
|
|
|
echohl ErrorMsg | echomsg 'Cannot find the git root directory: '. b:sy.path | echohl None
|
2013-07-17 04:14:43 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
let root = fnamemodify(root, ':h')
|
2014-01-30 23:04:39 -05:00
|
|
|
let output = sy#util#run_in_dir(root, 'git diff --numstat')
|
2013-07-17 04:14:43 -04:00
|
|
|
if v:shell_error
|
|
|
|
echohl ErrorMsg | echomsg "'git diff --numstat' failed" | echohl None
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
for stat in split(output, '\n')
|
|
|
|
let tokens = matchlist(stat, '\v([0-9-]+)\t([0-9-]+)\t(.*)')
|
|
|
|
if empty(tokens)
|
|
|
|
echohl ErrorMsg | echomsg 'Cannot parse this line: '. stat | echohl None
|
|
|
|
elseif tokens[1] == '-'
|
|
|
|
continue
|
|
|
|
else
|
2013-07-17 06:30:58 -04:00
|
|
|
let path = root . sy#util#separator() . tokens[3]
|
2013-07-17 04:14:43 -04:00
|
|
|
if !bufexists(path)
|
|
|
|
execute 'argadd '. path
|
|
|
|
endif
|
|
|
|
call add(s:stats, { 'bufnr': bufnr(path), 'text': tokens[1] .' additions, '. tokens[2] .' deletions', 'lnum': 1, 'col': 1 })
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
"call setqflist(stats)
|
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_hg {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_hg() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'hg') ? g:signify_diffoptions.hg : ''
|
2014-11-23 01:23:08 -05:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'hg diff --config extensions.color=! --config defaults.diff= --nodates -U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
|
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_svn {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_svn() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'svn') ? g:signify_diffoptions.svn : ''
|
2013-11-21 20:57:43 -05:00
|
|
|
let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
|
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_bzr {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_bzr() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'bzr') ? g:signify_diffoptions.bzr : ''
|
2013-11-21 20:57:43 -05:00
|
|
|
let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
|
|
|
|
return (v:shell_error =~ '[012]') ? [1, diff] : [0, '']
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_darcs {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_darcs() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'darcs') ? g:signify_diffoptions.darcs : ''
|
2014-01-30 23:04:39 -05:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2 '. diffoptions .'" -- '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_fossil {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_fossil() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'fossil') ? g:signify_diffoptions.fossil : ''
|
2014-01-30 23:04:39 -05:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_cvs {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_cvs() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'cvs') ? g:signify_diffoptions.cvs : ''
|
2014-01-30 23:04:39 -05:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'cvs diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(b:sy.path, ':t')))
|
2013-11-03 12:50:42 -05:00
|
|
|
return ((v:shell_error == 1) && (diff =~ '+++')) ? [1, diff] : [0, '']
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_rcs {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_rcs() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'rcs') ? g:signify_diffoptions.rcs : ''
|
2013-11-21 20:57:43 -05:00
|
|
|
let diff = system('rcsdiff -U0 '. diffoptions .' '. sy#util#escape(b:sy.path) .' 2>/dev/null')
|
2013-11-03 12:50:42 -05:00
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #get_diff_accurev {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_accurev() abort
|
2013-11-14 21:55:22 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'accurev') ? g:signify_diffoptions.accurev : ''
|
2014-01-30 23:04:39 -05:00
|
|
|
let diff = sy#util#run_in_dir(fnamemodify(b:sy.path, ':h'), 'accurev diff '. sy#util#escape(fnamemodify(b:sy.path, ':t')) . ' -- -U0 '. diffoptions)
|
2013-11-03 12:50:42 -05:00
|
|
|
return (v:shell_error != 1) ? [0, ''] : [1, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-07-29 15:15:07 -04:00
|
|
|
" Function: #get_diff_perforce {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_perforce() abort
|
2013-11-22 13:50:49 -05:00
|
|
|
let diffoptions = has_key(g:signify_diffoptions, 'perforce') ? g:signify_diffoptions.perforce : ''
|
2014-09-07 10:11:07 -04:00
|
|
|
let diff = system('p4 monitor show 2>&1 >/dev/null && env P4DIFF=diff p4 diff -dU0 '. diffoptions .' '. sy#util#escape(b:sy.path))
|
2013-11-03 12:50:42 -05:00
|
|
|
return v:shell_error ? [0, ''] : [1, diff]
|
2013-07-29 15:15:07 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-08-20 10:27:46 -04:00
|
|
|
" Function: #get_stats {{{1
|
|
|
|
function! sy#repo#get_stats() abort
|
2013-11-21 20:57:43 -05:00
|
|
|
if !exists('b:sy') || !has_key(b:sy, 'stats')
|
2013-08-20 10:27:46 -04:00
|
|
|
return [-1, -1, -1]
|
|
|
|
endif
|
|
|
|
|
2013-11-21 20:57:43 -05:00
|
|
|
return b:sy.stats
|
2013-08-20 10:27:46 -04:00
|
|
|
endfunction
|