From 5ba918ea7b1dff196c64872bd72cdcf5bc052dff Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 16 Jul 2018 18:00:00 -0400 Subject: [PATCH] Support :Gread commit to read commit message --- autoload/fugitive.vim | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index f838332..32e916d 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -444,7 +444,7 @@ call s:add_methods('repo',['keywordprg']) " Section: Buffer 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) return ['', '', ''] endif @@ -2785,21 +2785,16 @@ function! fugitive#BufReadStatus() abort endfunction function! fugitive#FileRead() abort - try - let [dir, commit, file] = s:DirCommitFile(expand('')) - let repo = s:repo(dir) - let path = commit . substitute(file, '^/', ':', '') - let hash = repo.rev_parse(path) - if path =~ '^:' - let type = 'blob' - else - let type = repo.git_chomp('cat-file','-t',hash) - endif - " TODO: use count, if possible - return "read !".escape(repo.git_command('cat-file',type,hash),'%#\') - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry + let [dir, rev] = s:DirRev(expand('')) + if empty(dir) + return "noautocmd '[read " + endif + if rev !~# ':' + let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev) + else + let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev) + endif + return "'[read !" . escape(cmd, '!#%') endfunction function! fugitive#BufReadIndex() abort @@ -2940,10 +2935,6 @@ function! fugitive#BufReadObject() abort endtry endfunction -augroup fugitive_files - autocmd! -augroup END - " Section: Temp files if !exists('s:temp_files')