11 Commits

Author SHA1 Message Date
Tim Pope
cd67d087df fugitive.vim 3.5
* Lazy initialization.
* Make status buffer diff retrieval asynchronous.
* Support jump to diff from :Git log --name-status.
* Use smudge filters when viewing blobs.
* Provide User FugitiveEditor event.
* Provide FugitiveRemote() API function.
2021-11-15 00:17:52 -05:00
Tim Pope
b736e457b3 Provide FugitiveRemote() 2021-11-13 16:25:36 -05:00
Tim Pope
2e4ee0b5d6 Don't scroll :Git! window for paginated commands
References: https://github.com/tpope/vim-fugitive/issues/1832
2021-11-11 00:44:14 -05:00
Tim Pope
a6b823b8d0 Fix race condition on nvim 0.4
I could have sworn this wasn't necessary on 0.4, which is why I added
the extra clause, but I can consistently reproduce E716 now.

Resolves: https://github.com/tpope/vim-fugitive/issues/1881
2021-11-02 14:07:58 -04:00
Tim Pope
174fd6a39b Revert "Use :redrawstatus rather than &ro = &ro"
Turns out :redrawstatus is a lot more aggressive and can prevent seeing
Fugitive output.

This reverts commit 6ad15506cc.

References: https://github.com/tpope/vim-fugitive/issues/1180
2021-10-27 03:17:44 -04:00
Tim Pope
6ad15506cc Use :redrawstatus rather than &ro = &ro
References: https://github.com/tpope/vim-fugitive/issues/1180
2021-10-26 09:22:33 -04:00
Tim Pope
30933405bb Support blame maps without filetype plugin on
References: https://github.com/tpope/vim-fugitive/issues/1745
2021-10-19 11:44:22 -04:00
Tim Pope
4d29c1d6a0 Provide for retrieving parsed remote URL
The plan is to expose this as FugitiveRemote(), but let's give it some
bake time before making it official.
2021-10-17 20:25:23 -04:00
Tim Pope
93f41ace7d Move to beginning of line in "(" map
Resolves: https://github.com/tpope/vim-fugitive/issues/1867
2021-10-17 11:22:10 -04:00
Tim Pope
d5a6419fcf Guard against parallel status reload
Resolves: https://github.com/tpope/vim-fugitive/issues/1863
2021-10-17 11:22:10 -04:00
Tim Pope
88c7f867cf Further decouple #BufReadStatus() from v:cmdbang 2021-10-16 12:58:13 -04:00
2 changed files with 135 additions and 83 deletions

View File

@@ -228,7 +228,7 @@ function! s:Map(mode, lhs, rhs, ...) abort
endwhile
if !skip && (flags !~# '<unique>' || empty(mapcheck(head.tail, mode)))
call add(maps, mode.'map <buffer>' . s:nowait . substitute(flags, '<unique>', '', '') . ' ' . head.tail . ' ' . a:rhs)
if a:0 > 1
if a:0 > 1 && a:2
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') .
\ '|sil! exe "' . mode . 'unmap <buffer> ' . head.tail . '"'
endif
@@ -263,7 +263,7 @@ function! fugitive#Wait(job_or_jobs, ...) abort
if exists('*jobwait')
call map(copy(jobs), 'chanclose(v:val, "stdin")')
call jobwait(jobs, timeout_ms)
if len(jobs) && has('nvim-0.5')
if len(jobs)
sleep 1m
endif
else
@@ -1272,15 +1272,15 @@ function! s:UrlParse(url) abort
return url
endfunction
function! s:ResolveRemote(url) abort
function! s:RemoteResolve(url, flags) abort
let remote = s:UrlParse(a:url)
if remote.scheme =~# '^https\=$'
if remote.scheme =~# '^https\=$' && index(a:flags, ':nohttp') < 0
let headers = fugitive#RemoteHttpHeaders(remote.scheme . '://' . remote.authority . remote.path)
let loc = matchstr(get(headers, 'location', ''), '^https\=://.\{-\}\ze/info/refs?')
if len(loc)
let remote = s:UrlParse(loc)
else
let remote.http_headers = headers
let remote.headers = headers
endif
elseif remote.scheme ==# 'ssh'
let remote.authority = fugitive#SshHostAlias(remote.authority)
@@ -1288,23 +1288,66 @@ function! s:ResolveRemote(url) abort
return remote
endfunction
function! fugitive#ResolveRemote(url) abort
let remote = s:ResolveRemote(a:url)
if remote.scheme ==# 'file' || remote.scheme ==# ''
return remote.path
elseif remote.path =~# '^/'
return remote.scheme . '://' . remote.authority . remote.path
elseif remote.path =~# '^\~'
return remote.scheme . '://' . remote.authority . '/' . remote.path
elseif remote.scheme ==# 'ssh' && remote.authority !~# ':'
return remote.authority . ':' . remote.path
function! s:ConfigLengthSort(i1, i2) abort
return len(a:i2[0]) - len(a:i1[0])
endfunction
function! s:RemoteCallback(config, into, flags, cb) abort
if a:into.remote_name =~# '^\.\=$'
let a:into.remote_name = s:RemoteDefault(a:config)
endif
let url = a:into.remote_name
if url ==# '.git'
let url = s:GitDir(a:config)
elseif url !~# ':\|^/\|^\a:[\/]\|^\.\.\=/'
let url = FugitiveConfigGet('remote.' . url . '.url', a:config)
endif
let instead_of = []
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', a:config))
for v in vs
call add(instead_of, [v, k])
endfor
endfor
call sort(instead_of, 's:ConfigLengthSort')
for [orig, replacement] in instead_of
if strpart(url, 0, len(orig)) ==# orig
let url = replacement . strpart(url, len(orig))
break
endif
endfor
if index(a:flags, ':noresolve') < 0
call extend(a:into, s:RemoteResolve(url, a:flags))
else
return a:url
call extend(a:into, s:UrlParse(url))
endif
let a:into.user = matchstr(a:into.authority, '.\{-\}\ze@', '', '')
let a:into.host = substitute(a:into.authority, '.\{-\}@', '', '')
let a:into.hostname = substitute(a:into.host, ':\d\+$', '', '')
let a:into.port = matchstr(a:into.host, ':\zs\d\+$', '', '')
if a:into.path =~# '^/'
let a:into.url = a:into.scheme . '://' . a:into.authority . a:into.path
elseif a:into.path =~# '^\~'
let a:into.url = a:into.scheme . '://' . a:into.authority . '/' . a:into.path
elseif a:into.scheme ==# 'ssh' && a:into.authority !~# ':'
let a:into.url = a:into.authority . ':' . a:into.path
else
let a:into.url = url
endif
if len(a:cb)
call call(a:cb[0], [a:into] + a:cb[1:-1])
endif
endfunction
function! s:ConfigLengthSort(i1, i2) abort
return len(a:i2[0]) - len(a:i1[0])
function! s:Remote(dir, remote, flags, cb) abort
let into = {'remote_name': a:remote, 'git_dir': s:GitDir(a:dir)}
let config = fugitive#Config(a:dir, function('s:RemoteCallback'), into, a:flags, a:cb)
if len(a:cb)
return config
else
call fugitive#Wait(config)
return into
endif
endfunction
function! s:RemoteParseArgs(args) abort
@@ -1344,34 +1387,22 @@ function! s:RemoteParseArgs(args) abort
return [dir_or_config, remote, flags, cb]
endfunction
function! fugitive#Remote(...) abort
let [dir_or_config, remote, flags, cb] = s:RemoteParseArgs(a:000)
return s:Remote(dir_or_config, remote, flags, cb)
endfunction
function! s:RemoteUrlCallback(remote, callback) abort
return call(a:callback[0], [a:remote.url] + a:callback[1:-1])
endfunction
function! fugitive#RemoteUrl(...) abort
let [dir_or_config, url, flags, cb] = s:RemoteParseArgs(a:000)
let config = fugitive#Config(dir_or_config)
if url =~# '^\.\=$'
let url = s:RemoteDefault(config)
let [dir_or_config, remote, flags, cb] = s:RemoteParseArgs(a:000)
if len(cb)
let cb = [function('s:RemoteUrlCallback'), cb]
endif
if url ==# '.git'
let url = s:GitDir(config)
elseif url !~# ':\|^/\|^\.\.\=/'
let url = FugitiveConfigGet('remote.' . url . '.url', config)
endif
let instead_of = []
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config))
for v in vs
call add(instead_of, [v, k])
endfor
endfor
call sort(instead_of, 's:ConfigLengthSort')
for [orig, replacement] in instead_of
if strpart(url, 0, len(orig)) ==# orig
let url = replacement . strpart(url, len(orig))
break
endif
endfor
if index(flags, 1) < 0 && index(flags, get(v:, 'true', 1)) < 0 && index(flags, ':noresolve') < 0
let url = fugitive#ResolveRemote(url)
endif
return url
let remote = s:Remote(dir_or_config, remote, flags, cb)
return get(remote, 'url', remote)
endfunction
" Section: Quickfix
@@ -2553,18 +2584,13 @@ let s:rebase_abbrevs = {
function! fugitive#BufReadStatus(...) abort
let amatch = s:Slash(expand('%:p'))
let b:fugitive_type = 'index'
unlet! b:fugitive_reltime
unlet! b:fugitive_reltime b:fugitive_type
try
if exists('b:fugitive_reloading')
throw 'double status reload???'
endif
let b:fugitive_reloading = 1
silent doautocmd BufReadPre
let config = fugitive#Config()
let cmd = [fnamemodify(amatch, ':h')]
setlocal noro ma nomodeline buftype=nowrite
setlocal noreadonly modifiable nomodeline buftype=nowrite
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? FugitiveVimPath($GIT_INDEX_FILE) : fugitive#Find('.git/index'), ':p')) !=# s:cpath(amatch)
let cmd += [{'env': {'GIT_INDEX_FILE': FugitiveGitPath(amatch)}}]
endif
@@ -2764,7 +2790,7 @@ function! fugitive#BufReadStatus(...) abort
endif
let b:fugitive_diff = diff
if !a:0 && v:cmdbang
if get(a:, 1, v:cmdbang)
unlet! b:fugitive_expanded
endif
let expanded = get(b:, 'fugitive_expanded', {'Staged': {}, 'Unstaged': {}})
@@ -2883,7 +2909,7 @@ function! fugitive#BufReadStatus(...) abort
catch /^fugitive:/
return 'echoerr ' . string(v:exception)
finally
unlet! b:fugitive_reloading
let b:fugitive_type = 'index'
endtry
endfunction
@@ -3168,6 +3194,9 @@ function! s:TempReadPost(file) abort
if dict.filetype ==# 'man' && has('nvim')
let b:man_sect = matchstr(getline(1), '^\w\+(\zs\d\+\ze)')
endif
if !get(g:, 'did_load_ftplugin') && dict.filetype ==# 'fugitiveblame'
call s:BlameMaps(0)
endif
let &l:filetype = dict.filetype
endif
setlocal foldmarker=<<<<<<<<,>>>>>>>>
@@ -3304,7 +3333,7 @@ function! s:RunReceive(state, tmp, type, job, data, ...) abort
call setbufline(a:state.capture_bufnr, line_count + 1, lines)
endif
call setbufvar(a:state.capture_bufnr, '&modifiable', 0)
if getwinvar(bufwinid(a:state.capture_bufnr), '&previewwindow')
if !a:state.pager && getwinvar(bufwinid(a:state.capture_bufnr), '&previewwindow')
let winnr = bufwinnr(a:state.capture_bufnr)
if winnr > 0
let old_winnr = winnr()
@@ -3683,6 +3712,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
let after_edit = ''
let stream = 0
if a:bang && pager isnot# 2
let state.pager = pager
let pager = 1
let stream = exists('*setbufline')
let do_edit = substitute(s:Mods(a:mods, 'Edge'), '\<tab\>', '-tab', 'g') . 'pedit!'
@@ -4094,7 +4124,7 @@ function! s:DoAutocmdChanged(dir) abort
finally
unlet! g:fugitive_event g:fugitive_result
" Force statusline reload with the buffer's Git dir
let &ro = &ro
let &l:ro = &l:ro
endtry
return ''
endfunction
@@ -4105,7 +4135,7 @@ function! s:ReloadStatusBuffer(...) abort
endif
let original_lnum = a:0 ? a:1 : line('.')
let info = s:StageInfo(original_lnum)
call fugitive#BufReadStatus(1)
call fugitive#BufReadStatus(0)
call setpos('.', [0, s:StageSeek(info, original_lnum), 1, 0])
return ''
endfunction
@@ -4545,8 +4575,8 @@ endfunction
function! s:PreviousItem(count) abort
for i in range(a:count)
if !search(s:item_pattern, 'Wbe') && getline('.') !~# s:item_pattern
call search('^commit ', 'Wbe')
if !search(s:item_pattern, 'Wb') && getline('.') !~# s:item_pattern
call search('^commit ', 'Wb')
endif
endfor
call s:StageReveal()
@@ -7068,6 +7098,33 @@ function! s:BlameRehighlight() abort
endfor
endfunction
function! s:BlameMaps(is_ftplugin) abort
let ft = a:is_ftplugin
call s:Map('n', '<F1>', ':help :Git_blame<CR>', '<silent>', ft)
call s:Map('n', 'g?', ':help :Git_blame<CR>', '<silent>', ft)
if empty(mapcheck('q', 'n'))
nnoremap <buffer> <silent> q :<C-U>echoerr "fugitive: q removed in favor of gq (or :q)"<CR>
endif
call s:Map('n', 'gq', ':exe <SID>BlameQuit()<CR>', '<silent>', ft)
call s:Map('n', '<2-LeftMouse>', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>', ft)
call s:Map('n', '<CR>', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>', ft)
call s:Map('n', '-', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 's', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 'u', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>', ft)
call s:Map('n', 'P', ':<C-U>exe <SID>BlameJump("^".v:count1)<CR>', '<silent>', ft)
call s:Map('n', '~', ':<C-U>exe <SID>BlameJump("~".v:count1)<CR>', '<silent>', ft)
call s:Map('n', 'i', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>', ft)
call s:Map('n', 'o', ':<C-U>exe <SID>BlameCommit("split")<CR>', '<silent>', ft)
call s:Map('n', 'O', ':<C-U>exe <SID>BlameCommit("tabedit")<CR>', '<silent>', ft)
call s:Map('n', 'p', ':<C-U>exe <SID>BlameCommit("pedit")<CR>', '<silent>', ft)
call s:Map('n', '.', ":<C-U> <C-R>=substitute(<SID>BlameCommitFileLnum()[0],'^$','@','')<CR><Home>", ft)
call s:Map('n', '(', "-", ft)
call s:Map('n', ')', "+", ft)
call s:Map('n', 'A', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze [0-9:/+-][0-9:/+ -]* \\d\\+)')+1+v:count)<CR>", '<silent>', ft)
call s:Map('n', 'C', ":<C-u>exe 'vertical resize '.(<SID>linechars('^\\S\\+')+1+v:count)<CR>", '<silent>', ft)
call s:Map('n', 'D', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze\\d\\ze\\s\\+\\d\\+)')+1-v:count)<CR>", '<silent>', ft)
endfunction
function! fugitive#BlameFileType() abort
setlocal nomodeline
setlocal foldmethod=manual
@@ -7082,29 +7139,7 @@ function! fugitive#BlameFileType() abort
if &modifiable
return ''
endif
call s:Map('n', '<F1>', ':help :Git_blame<CR>', '<silent>')
call s:Map('n', 'g?', ':help :Git_blame<CR>', '<silent>')
if empty(mapcheck('q', 'n'))
nnoremap <buffer> <silent> q :<C-U>echoerr "fugitive: q removed in favor of gq (or :q)"<CR>
endif
call s:Map('n', 'gq', ':exe <SID>BlameQuit()<CR>', '<silent>')
call s:Map('n', '<2-LeftMouse>', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>')
call s:Map('n', '<CR>', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>')
call s:Map('n', '-', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>')
call s:Map('n', 's', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>')
call s:Map('n', 'u', ':<C-U>exe <SID>BlameJump("")<CR>', '<silent>')
call s:Map('n', 'P', ':<C-U>exe <SID>BlameJump("^".v:count1)<CR>', '<silent>')
call s:Map('n', '~', ':<C-U>exe <SID>BlameJump("~".v:count1)<CR>', '<silent>')
call s:Map('n', 'i', ':<C-U>exe <SID>BlameCommit("exe <SID>BlameLeave()<Bar>edit")<CR>', '<silent>')
call s:Map('n', 'o', ':<C-U>exe <SID>BlameCommit("split")<CR>', '<silent>')
call s:Map('n', 'O', ':<C-U>exe <SID>BlameCommit("tabedit")<CR>', '<silent>')
call s:Map('n', 'p', ':<C-U>exe <SID>BlameCommit("pedit")<CR>', '<silent>')
call s:Map('n', '.', ":<C-U> <C-R>=substitute(<SID>BlameCommitFileLnum()[0],'^$','@','')<CR><Home>")
call s:Map('n', '(', "-")
call s:Map('n', ')', "+")
call s:Map('n', 'A', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze [0-9:/+-][0-9:/+ -]* \\d\\+)')+1+v:count)<CR>", '<silent>')
call s:Map('n', 'C', ":<C-u>exe 'vertical resize '.(<SID>linechars('^\\S\\+')+1+v:count)<CR>", '<silent>')
call s:Map('n', 'D', ":<C-u>exe 'vertical resize '.(<SID>linechars('.\\{-\\}\\ze\\d\\ze\\s\\+\\d\\+)')+1-v:count)<CR>", '<silent>')
call s:BlameMaps(1)
endfunction
augroup fugitive_blame

View File

@@ -1,6 +1,6 @@
" fugitive.vim - A Git wrapper so awesome, it should be illegal
" Maintainer: Tim Pope <http://tpo.pe/>
" Version: 3.4
" Version: 3.5
" GetLatestVimScripts: 2975 1 :AutoInstall: fugitive.vim
if exists('g:loaded_fugitive')
@@ -210,6 +210,23 @@ function! FugitiveRemoteUrl(...) abort
return call('fugitive#RemoteUrl', a:000)
endfunction
" FugitiveRemote() returns a data structure parsed from the remote URL.
" For example, for remote URL is "https://me@example.com:1234/repo.git",
" the returned dictionary will contain the following:
"
" * "scheme": "https"
" * "authority": "user@example.com:1234"
" * "path": "/repo.git" (for SSH URLs this may be a relative path)
" * "host": "example.com:1234"
" * "hostname": "example.com"
" * "port": "1234"
" * "user": "me"
" * "path": "/repo.git"
" * "url": "https://me@example.com:1234/repo.git"
function! FugitiveRemote(...) abort
return call('fugitive#Remote', a:000)
endfunction
" FugitiveDidChange() triggers a FugitiveChanged event and reloads the summary
" buffer for the current or given buffer number's repository. You can also
" give the result of a FugitiveExecute() and that context will be made
@@ -628,7 +645,7 @@ augroup fugitive
autocmd BufReadCmd index{,.lock}
\ if FugitiveIsGitDir(expand('<amatch>:p:h')) |
\ let b:git_dir = s:Slash(expand('<amatch>:p:h')) |
\ exe fugitive#BufReadStatus() |
\ exe fugitive#BufReadStatus(v:cmdbang) |
\ elseif filereadable(expand('<amatch>')) |
\ silent doautocmd BufReadPre |
\ keepalt read <amatch> |