mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-16 23:33:43 -05:00
Cache results from git ls-files
Only support stage '0' for tree objects
This commit is contained in:
@@ -2069,12 +2069,23 @@ function! s:TreeInfo(dir, commit) abort
|
|||||||
return [{}, -1]
|
return [{}, -1]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let s:index_info = {}
|
||||||
function! s:IndexInfo(dir, commit_stage, path) abort
|
function! s:IndexInfo(dir, commit_stage, path) abort
|
||||||
|
let cache_key = 'cache://' . 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])
|
let result = fugitive#Execute(['--literal-pathspecs', 'ls-files', '--stage', '--', a:path])
|
||||||
if result.exit_status
|
if result.exit_status
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
let newftime = getftime(fugitive#Find('.git/index', a:dir))
|
|
||||||
for line in result.stdout[:2]
|
for line in result.stdout[:2]
|
||||||
" Inspect up to the first three lines to find the correct stage
|
" Inspect up to the first three lines to find the correct stage
|
||||||
if empty(line)
|
if empty(line)
|
||||||
@@ -2083,17 +2094,13 @@ function! s:IndexInfo(dir, commit_stage, path) abort
|
|||||||
let [info, filename] = split(line, "\t")
|
let [info, filename] = split(line, "\t")
|
||||||
let [mode, sha, stage] = split(info, '\s\+')
|
let [mode, sha, stage] = split(info, '\s\+')
|
||||||
if filename ==# a:path
|
if filename ==# a:path
|
||||||
if stage != a:commit_stage
|
let indexes[stage] = [newftime, mode, 'blob', sha, -2]
|
||||||
continue
|
|
||||||
endif
|
|
||||||
return [newftime, mode, 'blob', sha, -2]
|
|
||||||
else
|
else
|
||||||
" Not concerned about the stage of tree objects- a tree can contain
|
" Only support stage '0' for tree objects
|
||||||
" blobs from many different stages simultaneously
|
let indexes['0'] = [newftime, '040000', 'tree', '', 0]
|
||||||
return [newftime, '040000', 'tree', '', 0]
|
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return []
|
return get(indexes, a:commit_stage, [])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:PathInfo(url) abort
|
function! s:PathInfo(url) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user