mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 12:33:46 -05:00
Extract function for getting current commit/ref
This commit is contained in:
@@ -419,6 +419,26 @@ function! s:DirRev(url) abort
|
|||||||
return [dir, (commit =~# '^.$' ? ':' : '') . commit . substitute(file, '^/', ':', '')]
|
return [dir, (commit =~# '^.$' ? ':' : '') . commit . substitute(file, '^/', ':', '')]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:Owner(path, ...) abort
|
||||||
|
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
||||||
|
if empty(dir)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let [pdir, commit, file] = s:DirCommitFile(a:path)
|
||||||
|
if s:cpath(dir, pdir) && commit =~# '^\x\{40\}$'
|
||||||
|
return commit
|
||||||
|
endif
|
||||||
|
let path = fnamemodify(a:path, ':p')
|
||||||
|
if s:cpath(dir . '/', path[0 : len(dir)]) && a:path =~# 'HEAD$'
|
||||||
|
return strpart(path, len(dir) + 1)
|
||||||
|
endif
|
||||||
|
let refs = fugitive#CommonDir(dir) . '/refs'
|
||||||
|
if s:cpath(refs . '/', path[0 : len(refs)]) && path !~# '[\/]$'
|
||||||
|
return strpart(path, len(refs) - 4)
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Real(url) abort
|
function! fugitive#Real(url) abort
|
||||||
if empty(a:url)
|
if empty(a:url)
|
||||||
return ''
|
return ''
|
||||||
@@ -502,7 +522,7 @@ function! fugitive#Route(object, ...) abort
|
|||||||
elseif rev =~# '^:/\@!'
|
elseif rev =~# '^:/\@!'
|
||||||
let f = 'fugitive://' . dir . '//0/' . rev[1:-1]
|
let f = 'fugitive://' . dir . '//0/' . rev[1:-1]
|
||||||
else
|
else
|
||||||
if rev =~# 'HEAD\|^refs/' && rev !~# ':'
|
if rev =~# 'HEAD$\|^refs/' && rev !~# ':'
|
||||||
let cdir = rev =~# '^refs/' ? fugitive#CommonDir(dir) : dir
|
let cdir = rev =~# '^refs/' ? fugitive#CommonDir(dir) : dir
|
||||||
if filereadable(cdir . '/' . rev)
|
if filereadable(cdir . '/' . rev)
|
||||||
let f = simplify(cdir . '/' . rev)
|
let f = simplify(cdir . '/' . rev)
|
||||||
@@ -1923,7 +1943,7 @@ call s:command("-nargs=? -bang -complete=custom,s:RemoteComplete Gpull " .
|
|||||||
|
|
||||||
function! s:RevisionComplete(A, L, P) abort
|
function! s:RevisionComplete(A, L, P) abort
|
||||||
return s:TreeChomp('rev-parse', '--symbolic', '--branches', '--tags', '--remotes')
|
return s:TreeChomp('rev-parse', '--symbolic', '--branches', '--tags', '--remotes')
|
||||||
\ . "\nHEAD\nFETCH_HEAD\nORIG_HEAD"
|
\ . "\nHEAD\nFETCH_HEAD\nMERGE_HEAD\nORIG_HEAD"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RemoteComplete(A, L, P) abort
|
function! s:RemoteComplete(A, L, P) abort
|
||||||
@@ -2106,11 +2126,9 @@ function! s:Log(cmd, bang, line1, line2, ...) abort
|
|||||||
endif
|
endif
|
||||||
let relative = s:Relative('')
|
let relative = s:Relative('')
|
||||||
if before !~# '\s[^[:space:]-]'
|
if before !~# '\s[^[:space:]-]'
|
||||||
let commit = matchstr(s:DirCommitFile(@%)[1], '^\x\x\+$')
|
let owner = s:Owner(@%)
|
||||||
if len(commit)
|
if len(owner)
|
||||||
let before .= ' ' . commit
|
let before .= ' ' . s:shellesc(owner)
|
||||||
elseif relative =~# '^\.git/refs/\|^\.git/.*HEAD$'
|
|
||||||
let before .= ' ' . relative[5:-1]
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if relative =~# '^\.git\%(/\|$\)'
|
if relative =~# '^\.git\%(/\|$\)'
|
||||||
@@ -3116,7 +3134,7 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
if type ==# 'tree' && !empty(path)
|
if type ==# 'tree' && !empty(path)
|
||||||
let path = s:sub(path, '/\=$', '/')
|
let path = s:sub(path, '/\=$', '/')
|
||||||
endif
|
endif
|
||||||
if path =~# '^\.git/.*HEAD' && filereadable(b:git_dir . '/' . path[5:-1])
|
if path =~# '^\.git/.*HEAD$' && filereadable(b:git_dir . '/' . path[5:-1])
|
||||||
let body = readfile(b:git_dir . '/' . path[5:-1])[0]
|
let body = readfile(b:git_dir . '/' . path[5:-1])[0]
|
||||||
if body =~# '^\x\{40\}$'
|
if body =~# '^\x\{40\}$'
|
||||||
let commit = body
|
let commit = body
|
||||||
@@ -3280,12 +3298,8 @@ function! fugitive#MapCfile(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ContainingCommit() abort
|
function! s:ContainingCommit() abort
|
||||||
let commit = s:DirCommitFile(@%)[1]
|
let commit = s:Owner(@%)
|
||||||
if commit =~# '^\d\=$'
|
return empty(commit) ? 'HEAD' : commit
|
||||||
return 'HEAD'
|
|
||||||
else
|
|
||||||
return commit
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:NavigateUp(count) abort
|
function! s:NavigateUp(count) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user