diff --git a/autoload/sy.vim b/autoload/sy.vim index 41bbf4a..53b9e4a 100644 --- a/autoload/sy.vim +++ b/autoload/sy.vim @@ -28,18 +28,19 @@ function! sy#start(path) abort " new buffer.. add to list of registered files if !has_key(g:sy, a:path) if get(g:, 'signify_disable_by_default') + " register file as inactive let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [-1, -1, -1] } return endif let [ diff, type ] = sy#repo#detect(a:path) - if empty(diff) - " register file as active with either no changes or no found VCS + if type == 'unknown' + " register file as active with no found VCS let g:sy[a:path] = { 'active': 1, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } return endif - " register file as active and containing changes + " register file as active with found VCS let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } let dir = fnamemodify(a:path, ':h') @@ -47,22 +48,27 @@ function! sy#start(path) abort let g:sy_cache[dir] = type endif + if empty(diff) + " no changes found + return + endif + " inactive buffer.. bail out elseif !g:sy[a:path].active return - " retry detecting changes or VCS + " retry detecting VCS elseif g:sy[a:path].type == 'unknown' let [ diff, type ] = sy#repo#detect(a:path) - if empty(diff) - " no changes or VCS found + if type == 'unknown' + " no VCS found return endif let g:sy[a:path].type = type " update signs else - let diff = sy#repo#get_diff_{g:sy[a:path].type}(a:path) + let [ _, diff ] = sy#repo#get_diff_{g:sy[a:path].type}(a:path) if empty(diff) call sy#sign#remove_all(a:path) return diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 26c3471..227e246 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -53,20 +53,21 @@ function! sy#repo#detect(path) abort endif for type in s:vcs_list - let diff = sy#repo#get_diff_{type}(a:path) - if !empty(diff) + let [istype, diff] = sy#repo#get_diff_{type}(a:path) + if istype return [ diff, type ] endif endfor - return [ '', '' ] + return [ '', 'unknown' ] endfunction " Function: #get_diff_git {{{1 function! sy#repo#get_diff_git(path) abort let diffoptions = has_key(s:diffoptions, 'git') ? s:diffoptions.git : '' let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-color --no-ext-diff -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_stat_git {{{1 @@ -104,63 +105,66 @@ endfunction function! sy#repo#get_diff_hg(path) abort let diffoptions = has_key(s:diffoptions, 'hg') ? s:diffoptions.hg : '' let diff = system('hg diff --nodates -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_diff_svn {{{1 function! sy#repo#get_diff_svn(path) abort let diffoptions = has_key(s:diffoptions, 'svn') ? s:diffoptions.svn : '' let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_diff_bzr {{{1 function! sy#repo#get_diff_bzr(path) abort let diffoptions = has_key(s:diffoptions, 'bzr') ? s:diffoptions.bzr : '' let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return ((v:shell_error == 0) || (v:shell_error == 1) || (v:shell_error == 2)) ? diff : '' + + return (v:shell_error =~ '[012]') ? [1, diff] : [0, ''] endfunction " Function: #get_diff_darcs {{{1 function! sy#repo#get_diff_darcs(path) abort let diffoptions = has_key(s:diffoptions, 'darcs') ? s:diffoptions.darcs : '' let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2 '. diffoptions .'" -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_diff_fossil {{{1 function! sy#repo#get_diff_fossil(path) abort let diffoptions = has_key(s:diffoptions, 'fossil') ? s:diffoptions.fossil : '' let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_diff_cvs {{{1 function! sy#repo#get_diff_cvs(path) abort let diffoptions = has_key(s:diffoptions, 'cvs') ? s:diffoptions.cvs : '' let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) - return ((v:shell_error == 1) && (diff =~ '+++')) ? diff : '' + return ((v:shell_error == 1) && (diff =~ '+++')) ? [1, diff] : [0, ''] endfunction " Function: #get_diff_rcs {{{1 function! sy#repo#get_diff_rcs(path) abort let diffoptions = has_key(s:diffoptions, 'rcs') ? s:diffoptions.rcs : '' let diff = system('rcsdiff -U0 '. diffoptions .' '. sy#util#escape(a:path) .' 2>/dev/null') - return v:shell_error ? '' : diff + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #get_diff_accurev {{{1 function! sy#repo#get_diff_accurev(path) abort let diffoptions = has_key(s:diffoptions, 'accurev') ? s:diffoptions.accurev : '' let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0 '. diffoptions) - return (v:shell_error != 1) ? '' : diff + return (v:shell_error != 1) ? [0, ''] : [1, diff] endfunction " Function: #get_diff_perforce {{{1 function! sy#repo#get_diff_perforce(path) abort let diffoptions = has_key(s:diffoptions, 'perforce') ? s:diffoptions.perforce : '' let diff = system('env P4DIFF=diff p4 diff -dU0 '. diffoptions .' -- '. sy#util#escape(a:path)) - return v:shell_error ? '' : diff + return v:shell_error ? [0, ''] : [1, diff] endfunction " Function: #process_diff {{{1