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
|
|
|
" Function: #detect {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#detect() abort
|
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.
|
2015-05-20 08:00:39 -04:00
|
|
|
if has_key(g:sy_cache, b:sy_info.dir)
|
|
|
|
let vcs_list = [g:sy_cache[b:sy_info.dir]] +
|
|
|
|
\ filter(copy(s:vcs_list), 'v:val != "'.
|
|
|
|
\ g:sy_cache[b:sy_info.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
|
2015-05-19 09:07:25 -04:00
|
|
|
return [diff, type]
|
2013-07-17 04:14:43 -04:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2015-05-19 09:07:25 -04: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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.git, b:sy_info.file, 1)
|
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_hg {{{1
|
2013-11-21 20:57:43 -05:00
|
|
|
function! sy#repo#get_diff_hg() abort
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.hg, b:sy_info.path, 1)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.svn, b:sy_info.path, 0)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.bzr, b:sy_info.path, 0)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.darcs, b:sy_info.path, 1)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.fossil, b:sy_info.path, 1)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.cvs, b:sy_info.file, 1)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.rcs, b:sy_info.path, 0)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.accurev, b:sy_info.file, 1)
|
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
|
2015-05-26 04:59:29 -04:00
|
|
|
let diff = s:run(s:vcs_cmds.perforce, b:sy_info.path, 0)
|
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
|
2015-05-19 08:01:26 -04:00
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
" Function: #debug_detection {{{1
|
|
|
|
function! sy#repo#debug_detection()
|
|
|
|
if !exists('b:sy')
|
|
|
|
echomsg 'signify: I cannot detect any changes!'
|
|
|
|
return
|
|
|
|
endif
|
2015-05-24 04:40:18 -04:00
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
let vcs_args = {
|
|
|
|
\ 'git': [s:vcs_cmds.git, b:sy_info.file, 1],
|
|
|
|
\ 'hg': [s:vcs_cmds.hg, b:sy_info.path, 1],
|
|
|
|
\ 'svn': [s:vcs_cmds.svn, b:sy_info.path, 0],
|
|
|
|
\ 'darcs': [s:vcs_cmds.darcs, b:sy_info.path, 1],
|
|
|
|
\ 'bzr': [s:vcs_cmds.bzr, b:sy_info.path, 0],
|
|
|
|
\ 'fossil': [s:vcs_cmds.fossil, b:sy_info.path, 1],
|
|
|
|
\ 'cvs': [s:vcs_cmds.cvs, b:sy_info.file, 1],
|
|
|
|
\ 'rcs': [s:vcs_cmds.rcs, b:sy_info.path, 0],
|
|
|
|
\ 'accurev': [s:vcs_cmds.accurev, b:sy_info.file, 1],
|
|
|
|
\ 'perforce': [s:vcs_cmds.perforce, b:sy_info.path, 0],
|
|
|
|
\ }
|
|
|
|
|
|
|
|
for vcs in s:vcs_list
|
|
|
|
let cmd = s:expand_cmd(vcs_args[vcs][0], vcs_args[vcs][1])
|
|
|
|
echohl Statement
|
|
|
|
echo cmd
|
|
|
|
echo repeat('=', len(cmd))
|
|
|
|
echohl NONE
|
|
|
|
|
|
|
|
let diff = call('s:run', vcs_args[vcs])
|
|
|
|
if v:shell_error
|
|
|
|
echohl ErrorMsg
|
|
|
|
echo diff
|
|
|
|
echohl NONE
|
|
|
|
else
|
|
|
|
echo empty(diff) ? "<none>" : diff
|
|
|
|
endif
|
|
|
|
echo "\n"
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:expand_cmd {{{1
|
|
|
|
function! s:expand_cmd(cmd, path) abort
|
2015-05-20 07:11:26 -04:00
|
|
|
let cmd = substitute(a:cmd, '%f', a:path, '')
|
|
|
|
let cmd = substitute(cmd, '%d', s:difftool, '')
|
|
|
|
let cmd = substitute(cmd, '%n', s:devnull, '')
|
2015-05-24 04:40:18 -04:00
|
|
|
let b:sy_info.cmd = cmd
|
2015-05-26 04:59:29 -04:00
|
|
|
return cmd
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:run {{{1
|
|
|
|
function! s:run(cmd, path, do_switch_dir)
|
|
|
|
let cmd = s:expand_cmd(a:cmd, a:path)
|
2015-05-19 08:01:26 -04:00
|
|
|
|
|
|
|
if a:do_switch_dir
|
|
|
|
try
|
2015-05-20 08:00:39 -04:00
|
|
|
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
2015-05-19 08:01:26 -04:00
|
|
|
let ret = system(cmd)
|
|
|
|
finally
|
2015-06-01 05:13:28 -04:00
|
|
|
execute b:sy_info.chdir b:sy_info.cwd
|
2015-05-19 08:01:26 -04:00
|
|
|
endtry
|
|
|
|
return ret
|
|
|
|
endif
|
|
|
|
|
2015-05-19 08:48:33 -04:00
|
|
|
return system(cmd)
|
2015-05-19 08:01:26 -04:00
|
|
|
endfunction
|
2015-05-19 08:57:40 -04:00
|
|
|
|
2015-05-20 08:00:39 -04:00
|
|
|
" Variables {{{1
|
2015-05-20 07:11:26 -04:00
|
|
|
let s:difftool = get(g:, 'signify_difftool', 'diff')
|
|
|
|
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
|
|
|
|
|
|
|
|
let s:vcs_list = get(g:, 'signify_vcs_list', [])
|
|
|
|
if empty(s:vcs_list)
|
|
|
|
let s:vcs_list = keys(filter(s:vcs_dict, 'executable(v:val)'))
|
|
|
|
endif
|
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
let s:vcs_cmds = {
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
|
|
|
|
\ 'hg': 'hg diff --config extensions.color=! --config defaults.diff= --nodates -U0 -- %f',
|
|
|
|
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
|
|
|
|
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
|
|
|
|
\ 'darcs': 'darcs diff --no-pause-for-gui --diff-command="%d -U0 %1 %2" -- %f',
|
|
|
|
\ 'fossil': 'fossil set diff-command "%d -U 0" && fossil diff --unified -c 0 -- %f',
|
|
|
|
\ 'cvs': 'cvs diff -U0 -- %f',
|
2015-05-20 08:22:52 -04:00
|
|
|
\ 'rcs': 'rcsdiff -U0 %f 2>%n',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'accurev': 'accurev diff %f -- -U0',
|
2015-05-25 03:25:23 -04:00
|
|
|
\ 'perforce': 'p4 info >%n 2>&1 && env P4DIFF=%d p4 diff -dU0 %f',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ }
|
|
|
|
|
|
|
|
if exists('g:signify_vcs_cmds')
|
2015-05-26 04:59:29 -04:00
|
|
|
call extend(s:vcs_cmds, g:signify_vcs_cmds)
|
2015-05-20 07:11:26 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-20 08:00:39 -04:00
|
|
|
let s:difftool = sy#util#escape(s:difftool)
|
2015-05-20 07:11:26 -04:00
|
|
|
let s:devnull = has('win32') || has ('win64') ? 'NUL' : '/dev/null'
|