Support :Gread commit to read commit message

This commit is contained in:
Tim Pope 2018-07-16 18:00:00 -04:00
parent 27475a5d08
commit 5ba918ea7b

View File

@ -444,7 +444,7 @@ call s:add_methods('repo',['keywordprg'])
" Section: Buffer " Section: Buffer
function! s:DirCommitFile(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:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\x\{40\}\|[0-3]\)\(/.*\)\=$')
if empty(vals) if empty(vals)
return ['', '', ''] return ['', '', '']
endif endif
@ -2785,21 +2785,16 @@ function! fugitive#BufReadStatus() abort
endfunction endfunction
function! fugitive#FileRead() abort function! fugitive#FileRead() abort
try let [dir, rev] = s:DirRev(expand('<amatch>'))
let [dir, commit, file] = s:DirCommitFile(expand('<amatch>')) if empty(dir)
let repo = s:repo(dir) return "noautocmd '[read <amatch>"
let path = commit . substitute(file, '^/', ':', '') endif
let hash = repo.rev_parse(path) if rev !~# ':'
if path =~ '^:' let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev)
let type = 'blob' else
else let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev)
let type = repo.git_chomp('cat-file','-t',hash) endif
endif return "'[read !" . escape(cmd, '!#%')
" TODO: use count, if possible
return "read !".escape(repo.git_command('cat-file',type,hash),'%#\')
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry
endfunction endfunction
function! fugitive#BufReadIndex() abort function! fugitive#BufReadIndex() abort
@ -2940,10 +2935,6 @@ function! fugitive#BufReadObject() abort
endtry endtry
endfunction endfunction
augroup fugitive_files
autocmd!
augroup END
" Section: Temp files " Section: Temp files
if !exists('s:temp_files') if !exists('s:temp_files')