1
0
mirror of https://github.com/amix/vimrc synced 2025-06-30 11: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

@ -4,14 +4,6 @@ let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ?
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error
endfunction
let s:c_flag = s:git_supports_command_line_config_override()
let s:temp_from = tempname()
let s:temp_buffer = tempname()
let s:counter = 0
@ -81,20 +73,6 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter assume unchanged'
endif
" If we are diffing against a specific branch/commit, handle the case
" where a file exists on the current branch but not in/at the diff base.
" We have to handle it here because the approach below (using git-show)
" doesn't work for this case.
if !empty(g:gitgutter_diff_base)
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd)
if v:shell_error
throw 'gitgutter file unknown in base'
endif
endif
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('
@ -137,8 +115,8 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
endif
" Write file from index to temporary file.
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' && '
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#base_path(a:bufnr)
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' || exit 0) && ('
elseif a:from ==# 'working_tree'
let from_file = gitgutter#utility#repo_path(a:bufnr, 1)
@ -146,7 +124,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Call git-diff.
let cmd .= gitgutter#git().' --no-pager'
if s:c_flag
if gitgutter#utility#git_supports_command_line_config_override()
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'
let cmd .= ' -c "core.safecrlf=false"'
@ -176,9 +154,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
return 'async'
else
let diff = gitgutter#utility#system(cmd)
let [diff, error_code] = gitgutter#utility#system(cmd)
if v:shell_error
if error_code
call gitgutter#debug#log(diff)
throw 'gitgutter diff failed'
endif
@ -390,12 +368,6 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...)
endfunction
function! gitgutter#diff#hunk_header_showing_every_line_added(bufnr)
let buf_line_count = getbufinfo(a:bufnr)[0].linecount
return '@@ -0,0 +1,'.buf_line_count.' @@'
endfunction
function! s:write_buffer(bufnr, file)
let bufcontents = getbufline(a:bufnr, 1, '$')

View File

@ -309,7 +309,7 @@ function! s:stage(hunk_diff)
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd)
let [_, error_code] = gitgutter#utility#system(cmd)
else
return
endif
@ -317,12 +317,12 @@ function! s:stage(hunk_diff)
else
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
let [_, error_code] = gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff)
endif
if v:shell_error
if error_code
call gitgutter#utility#warn('Patch does not apply')
else
if exists('#User#GitGutterStage')

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'))