mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Avoid unnecessary diff when adding/staging/reverting hunks.
This commit is contained in:
@@ -183,13 +183,14 @@ function! gitgutter#stage_hunk()
|
||||
if gitgutter#utility#is_active()
|
||||
" Ensure the working copy of the file is up to date.
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
" This also updates the signs and hunks.
|
||||
silent write
|
||||
noautocmd silent write
|
||||
let diff = gitgutter#diff#run_diff(0, 1)
|
||||
call gitgutter#handle_diff(diff)
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('stage')
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'stage')
|
||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --cached --unidiff-zero - '), diff_for_hunk)
|
||||
|
||||
" refresh gitgutter's view of buffer
|
||||
@@ -204,13 +205,14 @@ function! gitgutter#revert_hunk()
|
||||
if gitgutter#utility#is_active()
|
||||
" Ensure the working copy of the file is up to date.
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
" This also updates the signs and hunks.
|
||||
silent write
|
||||
noautocmd silent write
|
||||
let diff = gitgutter#diff#run_diff(0, 1)
|
||||
call gitgutter#handle_diff(diff)
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('revert')
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'revert')
|
||||
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --reverse --unidiff-zero - '), diff_for_hunk)
|
||||
|
||||
" reload file
|
||||
@@ -225,13 +227,14 @@ function! gitgutter#preview_hunk()
|
||||
if gitgutter#utility#is_active()
|
||||
" Ensure the working copy of the file is up to date.
|
||||
" It doesn't make sense to stage a hunk otherwise.
|
||||
" This also updates the signs and hunks.
|
||||
silent write
|
||||
noautocmd silent write
|
||||
let diff = gitgutter#diff#run_diff(0, 1)
|
||||
call gitgutter#handle_diff(diff)
|
||||
|
||||
if empty(gitgutter#hunk#current_hunk())
|
||||
call gitgutter#utility#warn('cursor is not in a hunk')
|
||||
else
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk('preview')
|
||||
let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'preview')
|
||||
|
||||
silent! wincmd P
|
||||
if !&previewwindow
|
||||
|
||||
@@ -286,11 +286,10 @@ endfunction
|
||||
|
||||
" Generates a zero-context diff for the current hunk.
|
||||
"
|
||||
" diff - the full diff for the buffer
|
||||
" type - stage | revert | preview
|
||||
function! gitgutter#diff#generate_diff_for_hunk(type)
|
||||
" Run a fresh diff.
|
||||
let diff = gitgutter#diff#run_diff(0, 1)
|
||||
let diff_for_hunk = gitgutter#diff#discard_hunks(diff, a:type == 'stage' || a:type == 'revert')
|
||||
function! gitgutter#diff#generate_diff_for_hunk(diff, type)
|
||||
let diff_for_hunk = gitgutter#diff#discard_hunks(a:diff, a:type == 'stage' || a:type == 'revert')
|
||||
|
||||
if a:type == 'stage' || a:type == 'revert'
|
||||
let diff_for_hunk = gitgutter#diff#adjust_hunk_summary(diff_for_hunk, a:type == 'stage')
|
||||
|
||||
Reference in New Issue
Block a user