Skip to content

Commit

Permalink
Cache results from git ls-files
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanderkamp committed Oct 31, 2021
1 parent 59e4b75 commit 1391d30
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions autoload/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2069,12 +2069,23 @@ function! s:TreeInfo(dir, commit) abort
return [{}, -1]
endfunction

let s:index_info = {}
function! s:IndexInfo(dir, commit_stage, path) abort
let cache_key = a:dir . '/' . a:path
let index = get(s:index_info, cache_key, [])
let newftime = getftime(fugitive#Find('.git/index', a:dir))

if get(index, 0, -1) == newftime
return get(get(index, 1, {}), a:commit_stage, [])
endif

let indexes = {'0': [], '1': [], '2': [], '3': []}
let s:index_info[cache_key] = [newftime, indexes]

let result = fugitive#Execute(['--literal-pathspecs', 'ls-files', '--stage', '--', a:path])
if result.exit_status
return []
endif
let newftime = getftime(fugitive#Find('.git/index', a:dir))
for line in result.stdout[:2]
" Inspect up to the first three lines to find the correct stage
if empty(line)
Expand All @@ -2083,17 +2094,18 @@ function! s:IndexInfo(dir, commit_stage, path) abort
let [info, filename] = split(line, "\t")
let [mode, sha, stage] = split(info, '\s\+')
if filename ==# a:path
if stage != a:stage_number
continue
endif
return [newftime, mode, 'blob', sha, -2]
let indexes[stage] = [newftime, mode, 'blob', sha, -2]
else
" Not concerned about the stage of tree objects- a tree can contain
" blobs from many different stages simultaneously
return [newftime, '040000', 'tree', '', 0]
let entry = [newftime, '040000', 'tree', '', 0]
let indexes['0'] = entry
let indexes['1'] = entry
let indexes['2'] = entry
let indexes['3'] = entry
endif
endfor
return []
return indexes[a:commit_stage]
endfunction

function! s:PathInfo(url) abort
Expand Down

0 comments on commit 1391d30

Please sign in to comment.