2 Commits

Author SHA1 Message Date
Jiacong Fang
d24cd24833 Merge 07de0b8d9f into b068eaf1e6 2025-02-05 09:26:14 +01:00
Jiacong Fang
07de0b8d9f Add completion for revision range 2022-05-08 22:44:29 +08:00

View File

@@ -4,6 +4,11 @@
" The functions contained within this file are for internal use only. For the
" official API, see the commented functions in plugin/fugitive.vim.
if exists('g:autoloaded_fugitive')
finish
endif
let g:autoloaded_fugitive = 1
" Section: Utility
function! s:function(name) abort
@@ -2066,8 +2071,6 @@ function! s:Expand(rev, ...) abort
endif
elseif s:Slash(a:rev) =~# '^\a\a\+://'
let file = substitute(a:rev, '\\\@<!\%(#\a\|%\x\x\)', '\\&', 'g')
elseif a:rev =~# '^:[!#%$]'
let file = ':0' . a:rev
else
let file = a:rev
endif
@@ -2468,6 +2471,17 @@ function! s:CompleteHeads(dir) abort
\ sort(s:LinesError([a:dir, 'rev-parse', '--symbolic', '--branches', '--tags', '--remotes'])[0])
endfunction
function! s:SplitRevRange(base, pat)
let index = matchend(a:base, a:pat)
if index == -1
return ['', a:base]
endif
let pre = a:base[:index - 1]
let base = a:base[index:]
return [pre, base]
endif
endfunction
function! fugitive#CompleteObject(base, ...) abort
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
let tree = s:Tree(dir)
@@ -2477,9 +2491,10 @@ function! fugitive#CompleteObject(base, ...) abort
let subdir = strpart(cwd, len(tree) + 1) . '/'
endif
let base = s:Expand(a:base)
let [pre, base] = s:SplitRevRange(base, '^[^:]*\/\@<!\.\.\.\=[\/\.]\@!')
if a:base =~# '^!\d*$' && base !~# '^!'
return [base]
return [pre . base]
elseif base =~# '^\.\=/\|^:(' || base !~# ':'
let results = []
if base =~# '^refs/'
@@ -2495,6 +2510,7 @@ function! fugitive#CompleteObject(base, ...) abort
let results += s:FilterEscape(heads, fnameescape(base))
endif
let results += a:0 == 1 || a:0 >= 3 ? fugitive#CompletePath(base, 0, '', dir, a:0 >= 4 ? a:4 : tree) : fugitive#CompletePath(base)
let results = map(results, 'pre . v:val')
return results
elseif base =~# '^:'
@@ -2514,7 +2530,7 @@ function! fugitive#CompleteObject(base, ...) abort
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
call map(entries,'parent.s:sub(v:val,".*\t","")')
endif
return s:FilterEscape(entries, fnameescape(base))
return map(s:FilterEscape(entries, fnameescape(base)), 'pre . v:val')
endfunction
function! s:CompleteSub(subcommand, A, L, P, ...) abort
@@ -2694,7 +2710,7 @@ function! s:MapStatus() abort
call s:MapMotion('gP', "exe <SID>StageJump(v:count, 'Unpulled')")
call s:MapMotion('gr', "exe <SID>StageJump(v:count, 'Rebasing')")
call s:Map('n', 'C', ":echoerr 'fugitive: C has been removed in favor of cc'<CR>", '<silent><unique>')
call s:Map('n', 'a', ":echoerr 'fugitive: a has been removed in favor of s'<CR>", '<silent><unique>')
call s:Map('n', 'a', ":<C-U>execute <SID>Do('Toggle',0)<CR>", '<silent>')
call s:Map('n', 'i', ":<C-U>execute <SID>NextExpandedHunk(v:count1)<CR>", '<silent>')
call s:Map('n', "=", ":<C-U>execute <SID>StageInline('toggle',line('.'),v:count)<CR>", '<silent>')
call s:Map('n', "<", ":<C-U>execute <SID>StageInline('hide', line('.'),v:count)<CR>", '<silent>')
@@ -2937,34 +2953,20 @@ function! s:StatusRender(stat) abort
endif
let sequencing = []
try
let sequencer_todo = reverse(readfile(fugitive#Find('.git/sequencer/todo', dir)))
catch
endtry
if exists('sequencer_todo')
for line in sequencer_todo
if filereadable(fugitive#Find('.git/sequencer/todo', dir))
for line in reverse(readfile(fugitive#Find('.git/sequencer/todo', dir)))
let match = matchlist(line, '^\(\l\+\)\s\+\(\x\{4,\}\)\s\+\(.*\)')
if len(match) && match[1] !~# 'exec\|merge\|label'
call add(sequencing, {'type': 'Rebase', 'status': get(s:rebase_abbrevs, match[1], match[1]), 'commit': match[2], 'subject': match[3]})
endif
endfor
else
try
let merge_msg = get(readfile(fugitive#Find('.git/MERGE_MSG', dir)), 0, '')
catch
endtry
endif
if exists('merge_msg')
elseif filereadable(fugitive#Find('.git/MERGE_MSG', dir))
if filereadable(fugitive#Find('.git/CHERRY_PICK_HEAD', dir))
let pick_head = fugitive#Execute(['rev-parse', '--short', 'CHERRY_PICK_HEAD', '--'], dir).stdout[0]
if !empty(pick_head)
call add(sequencing, {'type': 'Rebase', 'status': 'pick', 'commit': pick_head, 'subject': merge_msg})
endif
call add(sequencing, {'type': 'Rebase', 'status': 'pick', 'commit': pick_head, 'subject': get(readfile(fugitive#Find('.git/MERGE_MSG', dir)), 0, '')})
elseif filereadable(fugitive#Find('.git/REVERT_HEAD', dir))
let pick_head = fugitive#Execute(['rev-parse', '--short', 'REVERT_HEAD', '--'], dir).stdout[0]
if !empty(pick_head)
call add(sequencing, {'type': 'Rebase', 'status': 'revert', 'commit': pick_head, 'subject': merge_msg})
endif
call add(sequencing, {'type': 'Rebase', 'status': 'revert', 'commit': pick_head, 'subject': get(readfile(fugitive#Find('.git/MERGE_MSG', dir)), 0, '')})
endif
endif
@@ -2987,7 +2989,7 @@ function! s:StatusRender(stat) abort
endif
call s:AddSection(to, 'Rebasing ' . rebasing_head, rebasing)
call s:AddSection(to, get(get(sequencing, 0, {}), 'status', '') ==# 'revert' ? 'Reverting' : 'Cherry Picking', sequencing)
call s:AddSection(to, get(get(sequencing, 0, {}), 'tous', '') ==# 'revert' ? 'Reverting' : 'Cherry Picking', sequencing)
call s:AddSection(to, 'Untracked', untracked)
call s:AddDiffSection(to, stat, 'Unstaged', unstaged)
call s:AddDiffSection(to, stat, 'Staged', staged)
@@ -7446,12 +7448,9 @@ function! s:BrowserOpen(url, mods, echo_copy) abort
else
if !exists('g:loaded_netrw')
runtime! autoload/netrw.vim
runtime! autoload/netrw/os.vim
endif
if exists('*netrw#Open')
return 'echo '.string(url).'|' . mods . 'call netrw#Open('.string(url).')'
elseif exists('*netrw#os#Open')
return 'echo '.string(url).'|' . mods . 'call netrw#os#Open('.string(url).')'
elseif exists('*netrw#BrowseX')
return 'echo '.string(url).'|' . mods . 'call netrw#BrowseX('.string(url).', 0)'
elseif exists('*netrw#NetrwBrowseX')