Decouple Head() from repo object
This commit is contained in:
parent
40e2dcba05
commit
f91c34069e
@ -202,6 +202,22 @@ function! fugitive#Prepare(cmd, ...) abort
|
|||||||
return pre . g:fugitive_git_executable . ' ' . args
|
return pre . g:fugitive_git_executable . ' ' . args
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#Head(...) abort
|
||||||
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
||||||
|
if empty(dir) || !filereadable(dir . '/HEAD')
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let head = readfile(dir . '/HEAD')[0]
|
||||||
|
if head =~# '^ref: '
|
||||||
|
return substitute(head, '\C^ref: \%(refs/\%(heads/\|remotes/\|tags/\)\=\)\=', '', '')
|
||||||
|
elseif head =~# '^\x\{40\}$'
|
||||||
|
let len = a:0 ? a:1 : 0
|
||||||
|
return len < 0 ? head : len ? head[0:len-1] : ''
|
||||||
|
else
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RevParse(rev, ...) abort
|
function! fugitive#RevParse(rev, ...) abort
|
||||||
let hash = system(s:Prepare(a:0 ? a:1 : b:git_dir, 'rev-parse', '--verify', a:rev))[0:-2]
|
let hash = system(s:Prepare(a:0 ? a:1 : b:git_dir, 'rev-parse', '--verify', a:rev))[0:-2]
|
||||||
if !v:shell_error && hash =~# '^\x\{40\}$'
|
if !v:shell_error && hash =~# '^\x\{40\}$'
|
||||||
@ -408,22 +424,7 @@ function! s:Generate(rev, ...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_head(...) dict abort
|
function! s:repo_head(...) dict abort
|
||||||
if !filereadable(self.dir('HEAD'))
|
return fugitive#Head(a:0 ? a:1 : 0, self.git_dir)
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
let head = readfile(self.dir('HEAD'))[0]
|
|
||||||
|
|
||||||
if head =~# '^ref: '
|
|
||||||
let branch = s:sub(head,'^ref: %(refs/%(heads/|remotes/|tags/)=)=','')
|
|
||||||
elseif head =~# '^\x\{40\}$'
|
|
||||||
" truncate hash to a:1 characters if we're in detached head mode
|
|
||||||
let len = a:0 ? a:1 : 0
|
|
||||||
let branch = len < 0 ? head : len ? head[0:len-1] : ''
|
|
||||||
else
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
|
|
||||||
return branch
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call s:add_methods('repo',['dir','tree','bare','translate','head'])
|
call s:add_methods('repo',['dir','tree','bare','translate','head'])
|
||||||
@ -3543,7 +3544,7 @@ function! fugitive#head(...) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return fugitive#repo().head(a:0 ? a:1 : 0)
|
return fugitive#Head(a:0 ? a:1 : 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: Folding
|
" Section: Folding
|
||||||
|
@ -85,7 +85,7 @@ function! FugitiveHead(...) abort
|
|||||||
if empty(dir)
|
if empty(dir)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
return fugitive#repo(dir).head(a:0 ? a:1 : 0)
|
return fugitive#Head(a:0 ? a:1 : 0, dir)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! FugitiveStatusline(...) abort
|
function! FugitiveStatusline(...) abort
|
||||||
|
Loading…
x
Reference in New Issue
Block a user