Refactor repo.translate for future extraction

This commit is contained in:
Tim Pope 2018-07-21 18:29:35 -04:00
parent 445a8160d2
commit 9e7b67e9b0

View File

@ -294,45 +294,56 @@ function! s:repo_bare() dict abort
endfunction endfunction
function! s:repo_translate(spec) dict abort function! s:repo_translate(spec) dict abort
if a:spec ==# '.' || a:spec ==# '/.' let rev = a:spec
return self.bare() ? self.dir() : self.tree() let dir = self.git_dir
elseif a:spec =~# '^/\=\.git$' && self.bare() let tree = FugitiveTreeForGitDir(dir)
return self.dir() if rev ==# '.' || rev ==# '/.'
elseif a:spec =~# '^/\=\.git/' let f = empty(tree) ? dir : tree
return self.dir(s:sub(a:spec, '^/=\.git/', '')) elseif rev =~# '^/\=\.git$' && empty(tree)
elseif a:spec =~# '^/' let f = dir
return self.tree().a:spec elseif rev =~# '^/\=\.git/'
elseif a:spec =~# '^:[0-3]:' let f = dir . s:sub(rev, '^/=\.git', '')
return 'fugitive://'.self.dir().'//'.a:spec[1].'/'.a:spec[3:-1] elseif empty(rev)
elseif a:spec ==# ':' return self.tree()
if $GIT_INDEX_FILE =~# '/[^/]*index[^/]*\.lock$' && fnamemodify($GIT_INDEX_FILE,':p')[0:strlen(self.dir())] ==# self.dir('') && filereadable($GIT_INDEX_FILE) elseif rev =~# '^/'
return fnamemodify($GIT_INDEX_FILE,':p') let f = self.tree(rev)
elseif rev =~# '^:[0-3]:/\@!'
let f = 'fugitive://' . dir . '//' . rev[1] . '/' . rev[3:-1]
elseif rev ==# ':'
if $GIT_INDEX_FILE =~# '/[^/]*index[^/]*\.lock$' && s:cpath(fnamemodify($GIT_INDEX_FILE,':p')[0:strlen(dir)]) ==# s:cpath(dir . '/') && filereadable($GIT_INDEX_FILE)
let f = fnamemodify($GIT_INDEX_FILE, ':p')
else else
return self.dir('index') let f = dir . '/index'
endif endif
elseif a:spec =~# '^:/' elseif rev =~# '^:/\@!'
let ref = self.rev_parse(matchstr(a:spec,'.[^:]*')) let f = 'fugitive://' . dir . '//0/' . rev[1:-1]
return 'fugitive://'.self.dir().'//'.ref
elseif a:spec =~# '^:'
return 'fugitive://'.self.dir().'//0/'.a:spec[1:-1]
else else
let refs = self.dir('refs/') if rev =~# 'HEAD\|^refs/' && rev !~# ':'
if filereadable(self.dir('commondir')) let refs = dir . '/refs/'
let refs = simplify(self.dir(get(readfile(self.dir('commondir'), 1), 0, ''))) . '/refs/' if filereadable(dir . '/commondir')
let refs = simplify(dir . '/' . get(readfile(dir . '/commondir', 1), 0, '')) . '/refs/'
endif
if filereadable(refs . '../' . rev)
let f = simplify(refs . '../' . rev)
elseif filereadable(refs . rev)
let f = refs . rev
endif
endif endif
if a:spec =~# 'HEAD\|^refs/' && a:spec !~ ':' && filereadable(refs . '../' . a:spec) if !exists('f')
return simplify(refs . '../' . a:spec) let commit = substitute(matchstr(rev,'^[^:]\+\|^:.*'), '^@\%($|[^~]\)\@=', 'HEAD', '')
elseif filereadable(refs.a:spec) let file = substitute(matchstr(rev, '^[^:]\+:.*'), '^:', '/', '')
return refs.a:spec if commit !~# '^[0-9a-f]\{40\}$'
let commit = system(fugitive#Prepare(dir, 'rev-parse', '--verify', commit))[0:-2]
let commit = v:shell_error ? '' : commit
endif
if len(commit)
let f = 'fugitive://' . dir . '//' . commit . file
else
let f = self.tree(rev)
endif
endif endif
try
let ref = self.rev_parse(s:sub(matchstr(a:spec,'[^:]*'), '^\@%($|[^~])@=', 'HEAD'))
let path = s:sub(matchstr(a:spec,':.*'),'^:','/')
return 'fugitive://'.self.dir().'//'.ref.path
catch /^fugitive:/
return self.tree(a:spec)
endtry
endif endif
return f
endfunction endfunction
function! s:repo_head(...) dict abort function! s:repo_head(...) dict abort