Encapsulate logic for extracting tree from config

This commit is contained in:
Tim Pope
2012-03-18 22:09:46 -04:00
parent 6fc37993fe
commit c5cd0c96f7

View File

@@ -202,28 +202,35 @@ function! s:repo_dir(...) dict abort
return join([self.git_dir]+a:000,'/') return join([self.git_dir]+a:000,'/')
endfunction endfunction
function! s:repo_configured_tree() dict abort
if filereadable(self.dir('config'))
let config = readfile(self.dir('config'),10)
call filter(config,'v:val =~# "^\\s*worktree *="')
if len(config) == 1
return matchstr(config[0], '= *\zs.*')
endif
endif
return ''
endfunction
function! s:repo_tree(...) dict abort function! s:repo_tree(...) dict abort
if self.dir() =~# '/\.git$' if self.dir() =~# '/\.git$'
let dir = self.dir()[0:-6] let dir = self.dir()[0:-6]
else else
let config = readfile(self.dir('config'),10) let dir = self.configured_tree()
call filter(config,'v:val =~# "^\\s*worktree *="') endif
if len(config) == 1 if dir ==# ''
let dir = matchstr(config[0], '= *\zs.*')
else
call s:throw('no work tree') call s:throw('no work tree')
endif else
endif
return join([dir]+a:000,'/') return join([dir]+a:000,'/')
endif
endfunction endfunction
function! s:repo_bare() dict abort function! s:repo_bare() dict abort
if self.dir() =~# '/\.git$' if self.dir() =~# '/\.git$'
return 0 return 0
else else
let config = readfile(self.dir('config'),10) return self.configured_tree() ==# ''
call filter(config,'v:val =~# "^\\s*worktree *="')
return (len(config) != 1)
endtry endtry
endfunction endfunction
@@ -268,7 +275,7 @@ function! s:repo_translate(spec) dict abort
endif endif
endfunction endfunction
call s:add_methods('repo',['dir','tree','bare','translate']) call s:add_methods('repo',['dir','configured_tree','tree','bare','translate'])
function! s:repo_git_command(...) dict abort function! s:repo_git_command(...) dict abort
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir) let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)