1
0
mirror of https://github.com/amix/vimrc synced 2025-08-03 19:54:59 +08:00

Updated plugins

This commit is contained in:
Amir
2024-01-07 16:14:20 +01:00
parent 86762cf230
commit f676f799e7
172 changed files with 3227 additions and 1204 deletions

View File

@ -6,6 +6,15 @@ function! gitgutter#utility#supports_overscore_sign()
endif
endfunction
" True for git v1.7.2+.
function! gitgutter#utility#git_supports_command_line_config_override() abort
if !exists('s:c_flag')
let [_, error_code] = gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
let s:c_flag = !error_code
endif
return s:c_flag
endfunction
function! gitgutter#utility#setbufvar(buffer, varname, val)
let buffer = +a:buffer
" Default value for getbufvar() was introduced in Vim 7.3.831.
@ -93,10 +102,13 @@ function! gitgutter#utility#system(cmd, ...) abort
call gitgutter#debug#log(a:cmd, a:000)
call s:use_known_shell()
let prev_error_code = v:shell_error
silent let output = (a:0 == 0) ? system(a:cmd) : system(a:cmd, a:1)
let error_code = v:shell_error
silent call system('exit ' . prev_error_code)
call s:restore_shell()
return output
return [output, error_code]
endfunction
function! gitgutter#utility#has_repo_path(bufnr)
@ -161,9 +173,9 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
return 'async'
endif
let listing = gitgutter#utility#system(cmd)
let [listing, error_code] = gitgutter#utility#system(cmd)
if v:shell_error
if error_code
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
return
endif
@ -184,7 +196,7 @@ function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let [out, _] = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
@ -233,6 +245,87 @@ function! gitgutter#utility#get_diff_base(bufnr)
return g:gitgutter_diff_base
endfunction
" Returns the original path (shellescaped) at the buffer's diff base.
function! gitgutter#utility#base_path(bufnr)
let diffbase = gitgutter#utility#get_diff_base(a:bufnr)
" If we already know the original path at this diff base, return it.
let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '')
if !empty(basepath)
" basepath is diffbase:path
" Note that path can also contain colons.
" List destructuring / unpacking where the remaining items are assigned
" to a single variable (:help let-unpack) is only available in v8.2.0540.
let parts = split(basepath, ':', 1)
let base = parts[0]
let bpath = join(parts[1:], ':')
if base == diffbase
return gitgutter#utility#shellescape(bpath)
endif
endif
" Obtain buffers' paths.
let current_paths = {}
for bufnr in range(1, bufnr('$') + 1)
if gitgutter#utility#has_repo_path(bufnr)
let current_paths[gitgutter#utility#repo_path(bufnr, 0)] = bufnr
endif
endfor
" Get a list of file renames at the buffer's diff base.
" Store the original paths on any corresponding buffers.
" If the buffer's file was one of them, return its original path.
let op = ''
let renames = s:obtain_file_renames(a:bufnr, diffbase)
for [current, original] in items(renames)
if has_key(current_paths, current)
let bufnr = current_paths[current]
let basepath = diffbase.':'.original
call gitgutter#utility#setbufvar(bufnr, 'basepath', basepath)
if bufnr == a:bufnr
let op = original
endif
endif
endfor
if !empty(op)
return gitgutter#utility#shellescape(op)
endif
" Buffer's file was not renamed, so store current path and return it.
let current_path = gitgutter#utility#repo_path(a:bufnr, 0)
let basepath = diffbase.':'.current_path
call gitgutter#utility#setbufvar(a:bufnr, 'basepath', basepath)
return gitgutter#utility#shellescape(current_path)
endfunction
" Returns a dict of current path to original path at the given base.
function! s:obtain_file_renames(bufnr, base)
let renames = {}
let cmd = gitgutter#git()
if gitgutter#utility#git_supports_command_line_config_override()
let cmd .= ' -c "core.safecrlf=false"'
endif
let cmd .= ' diff --diff-filter=R --name-status '.a:base
let [out, error_code] = gitgutter#utility#system(gitgutter#utility#cd_cmd(a:bufnr, cmd))
if error_code
" Assume the problem is the diff base.
call gitgutter#utility#warn('g:gitgutter_diff_base ('.a:base.') is invalid')
return {}
endif
for line in split(out, '\n')
let fields = split(line)
if len(fields) != 3
call gitgutter#utility#warn('gitgutter: unable to list renamed files: '.line)
return {}
endif
let [original, current] = fields[1:]
let renames[current] = original
endfor
return renames
endfunction
function! s:abs_path(bufnr, shellesc)
let p = resolve(expand('#'.a:bufnr.':p'))