Skip to content

Commit 1391d30

Browse files
committed
Cache results from git ls-files
1 parent 59e4b75 commit 1391d30

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

autoload/fugitive.vim

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,12 +2069,23 @@ function! s:TreeInfo(dir, commit) abort
20692069
return [{}, -1]
20702070
endfunction
20712071

2072+
let s:index_info = {}
20722073
function! s:IndexInfo(dir, commit_stage, path) abort
2074+
let cache_key = a:dir . '/' . a:path
2075+
let index = get(s:index_info, cache_key, [])
2076+
let newftime = getftime(fugitive#Find('.git/index', a:dir))
2077+
2078+
if get(index, 0, -1) == newftime
2079+
return get(get(index, 1, {}), a:commit_stage, [])
2080+
endif
2081+
2082+
let indexes = {'0': [], '1': [], '2': [], '3': []}
2083+
let s:index_info[cache_key] = [newftime, indexes]
2084+
20732085
let result = fugitive#Execute(['--literal-pathspecs', 'ls-files', '--stage', '--', a:path])
20742086
if result.exit_status
20752087
return []
20762088
endif
2077-
let newftime = getftime(fugitive#Find('.git/index', a:dir))
20782089
for line in result.stdout[:2]
20792090
" Inspect up to the first three lines to find the correct stage
20802091
if empty(line)
@@ -2083,17 +2094,18 @@ function! s:IndexInfo(dir, commit_stage, path) abort
20832094
let [info, filename] = split(line, "\t")
20842095
let [mode, sha, stage] = split(info, '\s\+')
20852096
if filename ==# a:path
2086-
if stage != a:stage_number
2087-
continue
2088-
endif
2089-
return [newftime, mode, 'blob', sha, -2]
2097+
let indexes[stage] = [newftime, mode, 'blob', sha, -2]
20902098
else
20912099
" Not concerned about the stage of tree objects- a tree can contain
20922100
" blobs from many different stages simultaneously
2093-
return [newftime, '040000', 'tree', '', 0]
2101+
let entry = [newftime, '040000', 'tree', '', 0]
2102+
let indexes['0'] = entry
2103+
let indexes['1'] = entry
2104+
let indexes['2'] = entry
2105+
let indexes['3'] = entry
20942106
endif
20952107
endfor
2096-
return []
2108+
return indexes[a:commit_stage]
20972109
endfunction
20982110

20992111
function! s:PathInfo(url) abort

0 commit comments

Comments
 (0)