commit 5bc125d1d52a6d9a2d7ce1fbbef184651682c3e0 (tree)
parent 5be0c6850e5507edebe36f2114753122bf57f9f8
Author: Tim Pope <code@tpope.net>
Date: Mon, 5 Mar 2012 07:19:31 -0500
Try harder not to choke on broken modeline
Partially addresses #162.
Diffstat:
| M | plugin/fugitive.vim | | | 100 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------- |
1 file changed, 53 insertions(+), 47 deletions(-)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -1283,7 +1283,7 @@ endfunction
call s:add_methods('buffer',['compare_age'])
-function! s:Diff(bang,...) abort
+function! s:Diff(bang,...)
let split = a:bang ? 'split' : 'vsplit'
if exists(':DiffGitCached')
return 'DiffGitCached'
@@ -1930,10 +1930,13 @@ function! s:BufReadIndexFile()
try
let b:fugitive_type = 'blob'
let b:git_dir = s:repo().dir()
- call s:ReplaceCmd(s:repo().git_command('cat-file','blob',s:buffer().sha1()))
- if &bufhidden ==# ''
- setlocal bufhidden=delete
- endif
+ try
+ call s:ReplaceCmd(s:repo().git_command('cat-file','blob',s:buffer().sha1()))
+ finally
+ if &bufhidden ==# ''
+ setlocal bufhidden=delete
+ endif
+ endtry
return ''
catch /^fugitive: rev-parse/
silent exe 'doau BufNewFile '.s:fnameescape(bufname(''))
@@ -1998,52 +2001,55 @@ function! s:BufReadObject()
silent %delete
setlocal endofline
- if b:fugitive_type == 'tree'
- let b:fugitive_display_format = b:fugitive_display_format % 2
- if b:fugitive_display_format
- call s:ReplaceCmd(s:repo().git_command('ls-tree',hash))
- else
- call s:ReplaceCmd(s:repo().git_command('show','--no-color',hash))
- endif
- elseif b:fugitive_type == 'tag'
- let b:fugitive_display_format = b:fugitive_display_format % 2
- if b:fugitive_display_format
+ try
+ if b:fugitive_type == 'tree'
+ let b:fugitive_display_format = b:fugitive_display_format % 2
+ if b:fugitive_display_format
+ call s:ReplaceCmd(s:repo().git_command('ls-tree',hash))
+ else
+ call s:ReplaceCmd(s:repo().git_command('show','--no-color',hash))
+ endif
+ elseif b:fugitive_type == 'tag'
+ let b:fugitive_display_format = b:fugitive_display_format % 2
+ if b:fugitive_display_format
+ call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
+ else
+ call s:ReplaceCmd(s:repo().git_command('cat-file','-p',hash))
+ endif
+ elseif b:fugitive_type == 'commit'
+ let b:fugitive_display_format = b:fugitive_display_format % 2
+ if b:fugitive_display_format
+ call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
+ else
+ call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash))
+ call search('^parent ')
+ if getline('.') ==# 'parent '
+ silent delete_
+ else
+ silent s/\%(^parent\)\@<! /\rparent /ge
+ endif
+ if search('^encoding \%(<unknown>\)\=$','W',line('.')+3)
+ silent delete_
+ end
+ 1
+ endif
+ elseif b:fugitive_type ==# 'blob'
call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
- else
- call s:ReplaceCmd(s:repo().git_command('cat-file','-p',hash))
endif
- elseif b:fugitive_type == 'commit'
- let b:fugitive_display_format = b:fugitive_display_format % 2
- if b:fugitive_display_format
- call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
+ finally
+ call setpos('.',pos)
+ setlocal ro noma nomod
+ if &bufhidden ==# ''
+ setlocal bufhidden=delete
+ endif
+ if b:fugitive_type !=# 'blob'
+ set filetype=git
+ nnoremap <buffer> <silent> a :<C-U>let b:fugitive_display_format += v:count1<Bar>exe <SID>BufReadObject()<CR>
+ nnoremap <buffer> <silent> i :<C-U>let b:fugitive_display_format -= v:count1<Bar>exe <SID>BufReadObject()<CR>
else
- call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash))
- call search('^parent ')
- if getline('.') ==# 'parent '
- silent delete_
- else
- silent s/\%(^parent\)\@<! /\rparent /ge
- endif
- if search('^encoding \%(<unknown>\)\=$','W',line('.')+3)
- silent delete_
- end
- 1
+ call s:JumpInit()
endif
- elseif b:fugitive_type ==# 'blob'
- call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
- endif
- call setpos('.',pos)
- setlocal ro noma nomod
- if &bufhidden ==# ''
- setlocal bufhidden=delete
- endif
- if b:fugitive_type !=# 'blob'
- set filetype=git
- nnoremap <buffer> <silent> a :<C-U>let b:fugitive_display_format += v:count1<Bar>exe <SID>BufReadObject()<CR>
- nnoremap <buffer> <silent> i :<C-U>let b:fugitive_display_format -= v:count1<Bar>exe <SID>BufReadObject()<CR>
- else
- call s:JumpInit()
- endif
+ endtry
return ''
catch /^fugitive:/