From 9dc86c9bf66494a27d176b910fd65ccbd39136e9 Mon Sep 17 00:00:00 2001 From: killphi Date: Tue, 20 Aug 2013 12:50:36 +0200 Subject: [PATCH] Add stats property to g:sy --- autoload/sy.vim | 6 +++--- autoload/sy/repo.vim | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/autoload/sy.vim b/autoload/sy.vim index ae091d8..34b693c 100644 --- a/autoload/sy.vim +++ b/autoload/sy.vim @@ -23,19 +23,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') - let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top } + let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } 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 - let g:sy[a:path] = { 'active': 1, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top } + 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 - let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top } + let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } " inactive buffer.. bail out elseif !g:sy[a:path].active diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index ca7cdaa..b7ce2aa 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -133,6 +133,10 @@ endfunction " Function: #process_diff {{{1 function! sy#repo#process_diff(path, diff) abort + let added = 0 + let deleted = 0 + let modified = 0 + " 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*)') @@ -148,6 +152,8 @@ function! sy#repo#process_diff(path, diff) abort " +this is line 5 if (old_count == 0) && (new_count >= 1) + let added += new_count + let offset = 0 while offset < new_count call add(signs, { 'type': 'SignifyAdd', 'lnum': new_line + offset, 'path': a:path }) @@ -161,6 +167,8 @@ function! sy#repo#process_diff(path, diff) abort " -this is line 7 elseif (old_count >= 1) && (new_count == 0) + let deleted += old_count + if new_line == 0 call add(signs, { 'type': 'SignifyDeleteFirstLine', 'lnum': 1, 'path': a:path }) else @@ -176,6 +184,8 @@ function! sy#repo#process_diff(path, diff) abort " +this os line 6 elseif old_count == new_count + let modified += old_count + let offset = 0 while offset < new_count call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path }) @@ -194,12 +204,15 @@ function! sy#repo#process_diff(path, diff) abort " +this os line 6 if old_count > new_count + let modified += new_count + let deleted += (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 + 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: @@ -211,7 +224,9 @@ function! sy#repo#process_diff(path, diff) abort " +this is line 666 else - let offset = 0 + let modified += old_count + let added += (new_count - old_count) + let offset = 0 while offset < old_count call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path }) let offset += 1 @@ -225,6 +240,8 @@ function! sy#repo#process_diff(path, diff) abort call sy#sign#set(signs) endfor + + let g:sy[g:sy_path].stats = [added, modified, deleted] endfunction " vim: et sw=2 sts=2