Clean up repetition in URL parsing
This commit is contained in:
parent
8fa5cad8d7
commit
cbf96cc01a
@ -427,7 +427,7 @@ call s:add_methods('repo',['keywordprg'])
|
|||||||
|
|
||||||
" Section: Buffer
|
" Section: Buffer
|
||||||
|
|
||||||
function! s:UrlSplit(path) abort
|
function! s:DirCommitFile(path) abort
|
||||||
let vals = matchlist(s:shellslash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\w\+\)\(/.*\)\=$')
|
let vals = matchlist(s:shellslash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\w\+\)\(/.*\)\=$')
|
||||||
if empty(vals)
|
if empty(vals)
|
||||||
return ['', '', '']
|
return ['', '', '']
|
||||||
@ -436,7 +436,7 @@ function! s:UrlSplit(path) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Filename(url) abort
|
function! fugitive#Filename(url) abort
|
||||||
let [dir, rev, file] = s:UrlSplit(a:url)
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
||||||
if len(dir)
|
if len(dir)
|
||||||
return s:PlatformSlash(FugitiveTreeForGitDir(dir) . file)
|
return s:PlatformSlash(FugitiveTreeForGitDir(dir) . file)
|
||||||
elseif a:url =~# '^[\\/]\|^\a:[\\/]'
|
elseif a:url =~# '^[\\/]\|^\a:[\\/]'
|
||||||
@ -1729,8 +1729,8 @@ endfunction
|
|||||||
|
|
||||||
function! s:buffer_compare_age(commit) dict abort
|
function! s:buffer_compare_age(commit) dict abort
|
||||||
let scores = {':0': 1, ':1': 2, ':2': 3, ':': 4, ':3': 5}
|
let scores = {':0': 1, ':1': 2, ':2': 3, ':': 4, ':3': 5}
|
||||||
let my_score = get(scores,':'.self.commit(),0)
|
let my_score = get(scores, ':'.self.commit(), 0)
|
||||||
let their_score = get(scores,':'.a:commit,0)
|
let their_score = get(scores, ':'.substitute(a:commit, '^:', '', ''), 0)
|
||||||
if my_score || their_score
|
if my_score || their_score
|
||||||
return my_score < their_score ? -1 : my_score != their_score
|
return my_score < their_score ? -1 : my_score != their_score
|
||||||
elseif self.commit() ==# a:commit
|
elseif self.commit() ==# a:commit
|
||||||
@ -1800,13 +1800,12 @@ function! s:Diff(vert,keepfocus,...) abort
|
|||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
let spec = s:repo().translate(file)
|
let spec = s:repo().translate(file)
|
||||||
let commit = matchstr(spec,'\C[^:/]\%(//\|::\)\zs\x\+')
|
|
||||||
let restore = s:diff_restore()
|
let restore = s:diff_restore()
|
||||||
if exists('+cursorbind')
|
if exists('+cursorbind')
|
||||||
setlocal cursorbind
|
setlocal cursorbind
|
||||||
endif
|
endif
|
||||||
let w:fugitive_diff_restore = restore
|
let w:fugitive_diff_restore = restore
|
||||||
if s:buffer().compare_age(commit) < 0
|
if s:buffer().compare_age(s:DirCommitFile(spec)[1]) < 0
|
||||||
execute 'rightbelow '.vert.'diffsplit '.s:fnameescape(spec)
|
execute 'rightbelow '.vert.'diffsplit '.s:fnameescape(spec)
|
||||||
else
|
else
|
||||||
execute 'leftabove '.vert.'diffsplit '.s:fnameescape(spec)
|
execute 'leftabove '.vert.'diffsplit '.s:fnameescape(spec)
|
||||||
@ -2220,8 +2219,10 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
let full = s:repo().translate(expanded)
|
let full = s:repo().translate(expanded)
|
||||||
let commit = ''
|
let commit = ''
|
||||||
if full =~? '^fugitive:'
|
if full =~? '^fugitive:'
|
||||||
let commit = matchstr(full,':\%(//\)\=.*\%(//\|::\)\zs\w\w\+')
|
let [dir, commit, path] = s:DirCommitFile(full)
|
||||||
let path = matchstr(full,':\%(//\)\=.*\%(//\|::\)\w\+\zs/.*')
|
if commit =~# '^:\=\d$'
|
||||||
|
let commit = ''
|
||||||
|
endif
|
||||||
if commit =~ '..'
|
if commit =~ '..'
|
||||||
let type = s:repo().git_chomp('cat-file','-t',commit.s:sub(path,'^/',':'))
|
let type = s:repo().git_chomp('cat-file','-t',commit.s:sub(path,'^/',':'))
|
||||||
let branch = matchstr(expanded, '^[^:]*')
|
let branch = matchstr(expanded, '^[^:]*')
|
||||||
@ -2566,8 +2567,9 @@ endfunction
|
|||||||
|
|
||||||
function! fugitive#FileRead() abort
|
function! fugitive#FileRead() abort
|
||||||
try
|
try
|
||||||
let repo = s:repo(FugitiveExtractGitDir(expand('<amatch>')))
|
let [dir, commit, file] = s:DirCommitFile(expand('<amatch>'))
|
||||||
let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs.*'),'/',':'),'^\d:',':&')
|
let repo = s:repo(dir)
|
||||||
|
let path = commit . substitute(file, '^/', ':', '')
|
||||||
let hash = repo.rev_parse(path)
|
let hash = repo.rev_parse(path)
|
||||||
if path =~ '^:'
|
if path =~ '^:'
|
||||||
let type = 'blob'
|
let type = 'blob'
|
||||||
@ -2605,15 +2607,15 @@ endfunction
|
|||||||
function! fugitive#BufWriteIndex() abort
|
function! fugitive#BufWriteIndex() abort
|
||||||
let tmp = tempname()
|
let tmp = tempname()
|
||||||
try
|
try
|
||||||
let path = matchstr(expand('<amatch>'),'//\d/\zs.*')
|
let [dir, commit, file] = s:DirCommitFile(expand('<amatch>'))
|
||||||
let stage = matchstr(expand('<amatch>'),'//\zs\d')
|
let path = file[1:-1]
|
||||||
silent execute 'write !'.s:repo().git_command('hash-object','-w','--stdin').' > '.tmp
|
silent execute 'write !'.s:repo().git_command('hash-object','-w','--stdin').' > '.tmp
|
||||||
let sha1 = readfile(tmp)[0]
|
let sha1 = readfile(tmp)[0]
|
||||||
let old_mode = matchstr(s:repo().git_chomp('ls-files','--stage',path),'^\d\+')
|
let old_mode = matchstr(s:repo().git_chomp('ls-files','--stage',path),'^\d\+')
|
||||||
if old_mode == ''
|
if old_mode == ''
|
||||||
let old_mode = executable(s:repo().tree(path)) ? '100755' : '100644'
|
let old_mode = executable(s:repo().tree(path)) ? '100755' : '100644'
|
||||||
endif
|
endif
|
||||||
let info = old_mode.' '.sha1.' '.stage."\t".path
|
let info = old_mode.' '.sha1.' '.commit[-1:-1]."\t".path
|
||||||
call writefile([info],tmp)
|
call writefile([info],tmp)
|
||||||
if s:winshell()
|
if s:winshell()
|
||||||
let error = system('type '.s:gsub(tmp,'/','\\').'|'.s:repo().git_command('update-index','--index-info'))
|
let error = system('type '.s:gsub(tmp,'/','\\').'|'.s:repo().git_command('update-index','--index-info'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user