if exists('b:autoloaded_sy_repo') finish endif let b:autoloaded_sy_repo = 1 " Init: values {{{1 if !empty(get(g:, 'signify_difftool')) let s:difftool = g:signify_difftool else if has('win32') if $VIMRUNTIME =~ ' ' let s:difftool = (&sh =~ '\/dev/null') return v:shell_error ? '' : diff endif endfunction " Function: #get_diff_accurev {{{1 function! sy#repo#get_diff_accurev(path) abort if executable('accurev') let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0') return (v:shell_error != 1) ? '' : diff endif endfunction " Function: #process_diff {{{1 function! sy#repo#process_diff(path, diff) abort " Determine where we have to put our signs. for line in filter(split(a:diff, '\n'), 'v:val =~ "^@@ "') let tokens = matchlist(line, '^@@ -\v(\d+),?(\d*) \+(\d+),?(\d*)') let [ old_line, old_count, new_line, new_count ] = [ str2nr(tokens[1]), empty(tokens[2]) ? 1 : str2nr(tokens[2]), str2nr(tokens[3]), empty(tokens[4]) ? 1 : str2nr(tokens[4]) ] let signs = [] " 2 lines added: " @@ -5,0 +6,2 @@ this is line 5 " +this is line 5 " +this is line 5 if (old_count == 0) && (new_count >= 1) let offset = 0 while offset < new_count call add(signs, { 'type': 'SignifyAdd', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 endwhile " 2 lines removed: " @@ -6,2 +5,0 @@ this is line 5 " -this is line 6 " -this is line 7 elseif (old_count >= 1) && (new_count == 0) if new_line == 0 call add(signs, { 'type': 'SignifyDeleteFirstLine', 'lnum': 1, 'path': a:path }) else call add(signs, { 'type': (old_count > 9) ? 'SignifyDeleteMore' : 'SignifyDelete'. old_count, 'lnum': new_line, 'path': a:path }) endif " 2 lines changed: " @@ -5,2 +5,2 @@ this is line 4 " -this is line 5 " -this is line 6 " +this os line 5 " +this os line 6 elseif old_count == new_count let offset = 0 while offset < new_count call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 endwhile else " 2 lines changed; 2 lines deleted: " @@ -5,4 +5,2 @@ this is line 4 " -this is line 5 " -this is line 6 " -this is line 7 " -this is line 8 " +this os line 5 " +this os line 6 if old_count > new_count let offset = 0 while offset < (new_count - 1) call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 endwhile let deleted = old_count - new_count call add(signs, { 'type': (deleted > 9) ? 'SignifyChangeDeleteMore' : 'SignifyChangeDelete'. deleted, 'lnum': new_line, 'path': a:path }) " lines changed and added: " @@ -5 +5,3 @@ this is line 4 " -this is line 5 " +this os line 5 " +this is line 42 " +this is line 666 else let offset = 0 while offset < old_count call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 endwhile while offset < new_count call add(signs, { 'type': 'SignifyAdd', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 endwhile endif endif call sy#sign#set(signs) endfor endfunction " vim: et sw=2 sts=2