Skip to content

Commit 32e2cd9

Browse files
committed
Cache results from git ls-files
Only support stage '0' for tree objects
1 parent d5edbd7 commit 32e2cd9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

autoload/fugitive.vim

Lines changed: 16 additions & 9 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 = 'cache://' . 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,13 @@ 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:commit_stage
2087-
continue
2088-
endif
2089-
return [newftime, mode, 'blob', sha, -2]
2097+
let indexes[stage] = [newftime, mode, 'blob', sha, -2]
20902098
else
2091-
" Not concerned about the stage of tree objects- a tree can contain
2092-
" blobs from many different stages simultaneously
2093-
return [newftime, '040000', 'tree', '', 0]
2099+
" Only support stage '0' for tree objects
2100+
let indexes['0'] = [newftime, '040000', 'tree', '', 0]
20942101
endif
20952102
endfor
2096-
return []
2103+
return get(indexes, a:commit_stage, [])
20972104
endfunction
20982105

20992106
function! s:PathInfo(url) abort

0 commit comments

Comments
 (0)