Skip to content

Commit

Permalink
vcsdiff: Rename b:cached_* to b:qfs_vcsdiff_*; quickfixsigns#vcsdiff#…
Browse files Browse the repository at this point in the history
…GetHunkSummaryAsString(); support for the tstatus plugin
  • Loading branch information
tomtom committed May 3, 2015
1 parent 9e0df7e commit 2223bc2
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions autoload/quickfixsigns/vcsdiff.vim
Expand Up @@ -192,18 +192,18 @@ function! quickfixsigns#vcsdiff#GetList(filename) "{{{3
if !(type(list_type) == 0 && list_type >= 0 && list_type <= 1)
throw "Quickfixsigns: g:quickfixsigns#vcsdiff#list_type must be 0 or 1 but was ". list_type
endif
unlet! b:cached_hunkstat
let b:cached_list_{list_type} = quickfixsigns#vcsdiff#GetList{list_type}(a:filename)
return b:cached_list_{list_type}
unlet! b:qfs_vcsdiff_hunkstat
let b:qfs_vcsdiff_list_{list_type} = quickfixsigns#vcsdiff#GetList{list_type}(a:filename)
return b:qfs_vcsdiff_list_{list_type}
endf


" Get the list of vcsdiff signs (cached).
" The cache is invalidated wthen quickfixsigns#vcsdiff#GetList is called.
function! quickfixsigns#vcsdiff#GetListCached(filename) "{{{3
let list_type = g:quickfixsigns#vcsdiff#list_type
if exists('b:cached_list_'.list_type)
return b:cached_list_{list_type}
if exists('b:qfs_vcsdiff_list_'.list_type)
return b:qfs_vcsdiff_list_{list_type}
endif
return quickfixsigns#vcsdiff#GetList(a:filename)
endf
Expand All @@ -215,7 +215,7 @@ function! quickfixsigns#vcsdiff#GetHunkSummary(...) "{{{3
if filename == ""
return [0, 0, 0]
endif
if !exists('b:cached_hunkstat')
if !exists('b:qfs_vcsdiff_hunkstat')
let list = quickfixsigns#vcsdiff#GetListCached(filename)
let r = [0, 0, 0] " added, modified, removed.
for item in list
Expand All @@ -227,10 +227,22 @@ function! quickfixsigns#vcsdiff#GetHunkSummary(...) "{{{3
let r[2] += 1
endif
endfor
let b:cached_hunkstat = r
let b:qfs_vcsdiff_hunkstat = r
endif
return b:cached_hunkstat
endfunction
return b:qfs_vcsdiff_hunkstat
endf


" Get status of VCS changes as string.
function! quickfixsigns#vcsdiff#GetHunkSummaryAsString(...) "{{{3
let r = call('quickfixsigns#vcsdiff#GetHunkSummary', a:000)
if r[0] + r[1] + r[2] == 0
let b:qfs_vcsdiff_hunkstat_str = ''
else
let b:qfs_vcsdiff_hunkstat_str = printf('+%s,=%s,-%s', r[0], r[1], r[2])
endif
return b:qfs_vcsdiff_hunkstat_str
endf


" quickfixsigns#vcsdiff#GuessType() must return the name of a supported
Expand Down Expand Up @@ -483,3 +495,8 @@ function! s:BalloonJoin(...) "{{{3
endif
endf


if exists('g:tstatus_exprs')
call add(g:tstatus_exprs, 'quickfixsigns#vcsdiff#GetHunkSummaryAsString()')
endif

0 comments on commit 2223bc2

Please sign in to comment.