Skip to content

Commit

Permalink
Loosen regexps to accept alternate comment chars
Browse files Browse the repository at this point in the history
References #1025
  • Loading branch information
tpope committed May 30, 2018
1 parent cde670e commit d7c377f
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions plugin/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ endfunction
function! s:recall() abort
let rev = s:sub(s:buffer().rev(), '^/', '')
if rev ==# ':'
return matchstr(getline('.'),'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$\|^\d\{6} \x\{40\} \d\t\zs.*')
return matchstr(getline('.'),'^.\=\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$\|^\d\{6} \x\{40\} \d\t\zs.*')
elseif s:buffer().type('tree')
let file = matchstr(getline('.'), '\t\zs.*')
if empty(file) && line('.') > 2
Expand Down Expand Up @@ -867,7 +867,7 @@ function! fugitive#ReloadStatus() abort
endfunction

function! s:stage_info(lnum) abort
let filename = matchstr(getline(a:lnum),'^#\t\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
let filename = matchstr(getline(a:lnum),'^.\=\t\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
let lnum = a:lnum
if has('multi_byte_encoding')
let colon = '\%(:\|\%uff1a\)'
Expand All @@ -879,13 +879,13 @@ function! s:stage_info(lnum) abort
endwhile
if !lnum
return ['', '']
elseif (getline(lnum+1) =~# '^# .*\<git \%(reset\|rm --cached\) ' && getline(lnum+2) ==# '#') || getline(lnum) ==# '# Changes to be committed:'
elseif (getline(lnum+1) =~# '^.\= .*\<git \%(reset\|rm --cached\) ' && getline(lnum+2) ==# '#') || getline(lnum) =~# '^\%(. \)\=Changes to be committed:$'
return [matchstr(filename, colon.' *\zs.*'), 'staged']
elseif (getline(lnum+1) =~# '^# .*\<git add ' && getline(lnum+2) ==# '#' && getline(lnum+3) !~# colon.' ') || getline(lnum) ==# '# Untracked files:'
elseif (getline(lnum+1) =~# '^.\= .*\<git add ' && getline(lnum+2) ==# '#' && getline(lnum+3) !~# colon.' ') || getline(lnum) =~# '^\(. \)\=Untracked files:$'
return [filename, 'untracked']
elseif getline(lnum+2) =~# '^# .*\<git checkout ' || getline(lnum) ==# '# Changes not staged for commit:'
elseif getline(lnum+2) =~# '^.\= .*\<git checkout ' || getline(lnum) =~# '\%(. \)\=Changes not staged for commit:$'
return [matchstr(filename, colon.' *\zs.*'), 'unstaged']
elseif getline(lnum+2) =~# '^# .*\<git \%(add\|rm\)' || getline(lnum) ==# '# Unmerged paths:'
elseif getline(lnum+2) =~# '^.\= .*\<git \%(add\|rm\)' || getline(lnum) =~# '\%(. \)\=Unmerged paths:$'
return [matchstr(filename, colon.' *\zs.*'), 'unmerged']
else
return ['', 'unknown']
Expand All @@ -894,7 +894,7 @@ endfunction

function! s:StageNext(count) abort
for i in range(a:count)
call search('^#\t.*','W')
call search('^.\=\t.*','W')
endfor
return '.'
endfunction
Expand All @@ -904,22 +904,22 @@ function! s:StagePrevious(count) abort
return 'CtrlP '.fnameescape(s:repo().tree())
else
for i in range(a:count)
call search('^#\t.*','Wbe')
call search('^.\=\t.*','Wbe')
endfor
return '.'
endif
endfunction

function! s:StageReloadSeek(target,lnum1,lnum2) abort
let jump = a:target
let f = matchstr(getline(a:lnum1-1),'^#\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
let f = matchstr(getline(a:lnum1-1),'^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
if f !=# '' | let jump = f | endif
let f = matchstr(getline(a:lnum2+1),'^#\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
let f = matchstr(getline(a:lnum2+1),'^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
if f !=# '' | let jump = f | endif
silent! edit!
1
redraw
call search('^#\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\V'.jump.'\%( ([^()[:digit:]]\+)\)\=\$','W')
call search('^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\V'.jump.'\%( ([^()[:digit:]]\+)\)\=\$','W')
endfunction

function! s:StageUndo() abort
Expand Down Expand Up @@ -976,8 +976,8 @@ function! s:StageDiffEdit() abort
if arg ==# '.'
silent! edit!
1
if !search('^# .*:\n#.*\n# .*"git checkout \|^# Changes not staged for commit:$','W')
call search('^# .*:$','W')
if !search('^.*:\n.*\n.\= .*"git checkout \|^\%(# \)=Changes not staged for commit:$','W')
call search(':$','W')
endif
else
call s:StageReloadSeek(arg,line('.'),line('.'))
Expand All @@ -997,28 +997,28 @@ function! s:StageToggle(lnum1,lnum2) abort
for lnum in range(a:lnum1,a:lnum2)
let [filename, section] = s:stage_info(lnum)
let repo = s:repo()
if getline('.') =~# '^# .*:$'
if getline('.') =~# ':$'
if section ==# 'staged'
call repo.git_chomp_in_tree('reset','-q')
silent! edit!
1
if !search('^# .*:\n# .*"git add .*\n#\n\|^# Untracked files:$','W')
call search('^# .*:$','W')
if !search('^.*:\n.\= .*"git add .*\n#\n\|^\%(. \)\=Untracked files:$','W')
call search(':$','W')
endif
return ''
elseif section ==# 'unstaged'
call repo.git_chomp_in_tree('add','-u')
silent! edit!
1
if !search('^# .*:\n# .*"git add .*\n#\n\|^# Untracked files:$','W')
call search('^# .*:$','W')
if !search('^.*:\n\.\= .*"git add .*\n#\n\|^\%( \)=Untracked files:$','W')
call search(':$','W')
endif
return ''
else
call repo.git_chomp_in_tree('add','.')
silent! edit!
1
call search('^# .*:$','W')
call search(':$','W')
return ''
endif
endif
Expand All @@ -1034,9 +1034,9 @@ function! s:StageToggle(lnum1,lnum2) abort
endif
let filename = files_to_unstage[-1]
let cmd = ['reset','-q','--'] + files_to_unstage
elseif getline(lnum) =~# '^#\tdeleted:'
elseif getline(lnum) =~# '^.\=\tdeleted:'
let cmd = ['rm','--',filename]
elseif getline(lnum) =~# '^#\tmodified:'
elseif getline(lnum) =~# '^.\=\tmodified:'
let cmd = ['add','--',filename]
else
let cmd = ['add','-A','--',filename]
Expand All @@ -1062,11 +1062,11 @@ function! s:StagePatch(lnum1,lnum2) abort

for lnum in range(a:lnum1,a:lnum2)
let [filename, section] = s:stage_info(lnum)
if getline('.') =~# '^# .*:$' && section ==# 'staged'
if getline('.') =~# ':$' && section ==# 'staged'
return 'Git reset --patch'
elseif getline('.') =~# '^# .*:$' && section ==# 'unstaged'
elseif getline('.') =~# ':$' && section ==# 'unstaged'
return 'Git add --patch'
elseif getline('.') =~# '^# .*:$' && section ==# 'untracked'
elseif getline('.') =~# ':$' && section ==# 'untracked'
return 'Git add -N .'
elseif filename ==# ''
continue
Expand All @@ -1079,7 +1079,7 @@ function! s:StagePatch(lnum1,lnum2) abort
let reset += [split(filename,' -> ')[1]]
elseif section ==# 'staged'
let reset += [filename]
elseif getline(lnum) !~# '^#\tdeleted:'
elseif getline(lnum) !~# '^.\=\tdeleted:'
let add += [filename]
endif
endfor
Expand All @@ -1094,7 +1094,7 @@ function! s:StagePatch(lnum1,lnum2) abort
silent! edit!
1
redraw
call search('^#\t\%([[:alpha:] ]\+: *\)\=\V'.first_filename.'\%( ([^()[:digit:]]\+)\)\=\$','W')
call search('^.\=\t\%([[:alpha:] ]\+: *\)\=\V'.first_filename.'\%( ([^()[:digit:]]\+)\)\=\$','W')
endif
catch /^fugitive:/
return 'echoerr v:errmsg'
Expand Down Expand Up @@ -2931,25 +2931,25 @@ function! s:cfile() abort
let file = ':'.s:sub(matchstr(getline('.'),'\d\t.*'),'\t',':')
return [file]

elseif getline('.') =~# '^#\trenamed:.* -> '
elseif getline('.') =~# '^.\=\trenamed:.* -> '
let file = '/'.matchstr(getline('.'),' -> \zs.*')
return [file]
elseif getline('.') =~# '^#\t\(\k\| \)\+\p\?: *.'
elseif getline('.') =~# '^.\=\t\(\k\| \)\+\p\?: *.'
let file = '/'.matchstr(getline('.'),': *\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
return [file]
elseif getline('.') =~# '^#\t.'
let file = '/'.matchstr(getline('.'),'#\t\zs.*')
elseif getline('.') =~# '^.\=\t.'
let file = '/'.matchstr(getline('.'),'\t\zs.*')
return [file]
elseif getline('.') =~# ': needs merge$'
let file = '/'.matchstr(getline('.'),'.*\ze: needs merge$')
return [file, 'Gdiff!']

elseif getline('.') ==# '# Not currently on any branch.'
elseif getline('.') =~# '^\%(. \)\=Not currently on any branch.$'
return ['HEAD']
elseif getline('.') =~# '^# On branch '
elseif getline('.') =~# '^\%(. \)\=On branch '
let file = 'refs/heads/'.getline('.')[12:]
return [file]
elseif getline('.') =~# "^# Your branch .*'"
elseif getline('.') =~# "^\\%(. \\)\=Your branch .*'"
let file = matchstr(getline('.'),"'\\zs\\S\\+\\ze'")
return [file]
endif
Expand Down

0 comments on commit d7c377f

Please sign in to comment.