Eliminate repeated $GIT_DIR check

This commit is contained in:
Tim Pope 2019-06-02 19:32:57 -04:00
parent 078ffa6197
commit 8bbc4d8816

View File

@ -103,7 +103,7 @@ endfunction
function! FugitiveIsGitDir(path) abort function! FugitiveIsGitDir(path) abort
let path = substitute(a:path, '[\/]$', '', '') . '/' let path = substitute(a:path, '[\/]$', '', '') . '/'
return getfsize(path.'HEAD') > 10 && ( return len(a:path) && getfsize(path.'HEAD') > 10 && (
\ isdirectory(path.'objects') && isdirectory(path.'refs') || \ isdirectory(path.'objects') && isdirectory(path.'refs') ||
\ getftype(path.'commondir') ==# 'file') \ getftype(path.'commondir') ==# 'file')
endfunction endfunction
@ -162,6 +162,8 @@ function! FugitiveExtractGitDir(path) abort
silent! exe haslocaldir() ? 'lcd .' : 'cd .' silent! exe haslocaldir() ? 'lcd .' : 'cd .'
endif endif
let previous = "" let previous = ""
let env_git_dir = len($GIT_DIR) ? s:Slash(simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??'))) : ''
call s:Tree(env_git_dir)
while root !=# previous while root !=# previous
if root =~# '\v^//%([^/]+/?)?$' if root =~# '\v^//%([^/]+/?)?$'
break break
@ -169,15 +171,11 @@ function! FugitiveExtractGitDir(path) abort
if index(split($GIT_CEILING_DIRECTORIES, ':'), root) >= 0 if index(split($GIT_CEILING_DIRECTORIES, ':'), root) >= 0
break break
endif endif
if root ==# $GIT_WORK_TREE && FugitiveIsGitDir($GIT_DIR) if root ==# $GIT_WORK_TREE && FugitiveIsGitDir(env_git_dir)
return simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??')) return env_git_dir
endif elseif has_key(s:dir_for_worktree, root)
if FugitiveIsGitDir($GIT_DIR)
call s:Tree(simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??')))
if has_key(s:dir_for_worktree, root)
return s:dir_for_worktree[root] return s:dir_for_worktree[root]
endif endif
endif
let dir = substitute(root, '[\/]$', '', '') . '/.git' let dir = substitute(root, '[\/]$', '', '') . '/.git'
let type = getftype(dir) let type = getftype(dir)
if type ==# 'dir' && FugitiveIsGitDir(dir) if type ==# 'dir' && FugitiveIsGitDir(dir)