diff --git a/README.md b/README.md index 0d36951861dc5e9c05eeb74c15a287873434d6a3..e759ba6c6d2dce60fce24a4c2452f88eef4d4ce8 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,16 @@ When set to 2, filenames and hunks are unfolded. Default value is 1. > let g:magit_default_fold_level=[012] +#### g:magit_warning_max_lines + +This variable is the maximum number of diff lines that vimagit will display +without warning the user. If the number of diff lines to display is greater than +this variable, vimagit will ask a confirmation to the user before refreshing the +buffer. If user answer is 'yes', vimagit will display diff lines as expected. +If user answer is 'no', vimagit will close all file diffs before refreshing. +Default value is 10000. +> let g:magit_warning_max_lines=val + ## Installation The plugin hierarchy tree respects the vim plugin standard. It is compatible diff --git a/autoload/magit/state.vim b/autoload/magit/state.vim index 76d3c2b38a0399a408547e9e422bff00a8557b39..74ed84878937817e2140cc4c6a9e9c8e2c1b8092 100644 --- a/autoload/magit/state.vim +++ b/autoload/magit/state.vim @@ -162,6 +162,9 @@ function! magit#state#add_file(mode, status, filename, depth) dict endif call add(hunk.lines, diff_line) endfor + if ( file.is_visible() ) + let self.nb_diff_lines += len(diff_list) + endif endif endfunction @@ -171,6 +174,7 @@ endfunction " else, its diff is discarded and regenrated " what is resilient is its 'visible' parameter function! magit#state#update() dict + let self.nb_diff_lines = 0 for diff_dict_mode in values(self.dict) for file in values(diff_dict_mode) let file.exists = 0 @@ -208,6 +212,14 @@ function! magit#state#update() dict endfor endfunction +function! magit#state#set_files_visible(is_visible) dict + for diff_dict_mode in values(self.dict) + for file in values(diff_dict_mode) + call file.set_visible(a:is_visible) + endfor + endfor +endfunction + " dict: structure containing all diffs " It is formatted as follow " { @@ -223,9 +235,11 @@ endfunction " }, " } let magit#state#state = { + \ 'nb_diff_lines': 0, \ 'get_file': function("magit#state#get_file"), \ 'get_files': function("magit#state#get_files"), \ 'add_file': function("magit#state#add_file"), + \ 'set_files_visible': function("magit#state#set_files_visible"), \ 'update': function("magit#state#update"), \ 'dict': { 'staged': {}, 'unstaged': {}}, \ } diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 78cbdfefd9119ac9bb4344dd3b360d14bdfe57a3..98d1c3ed73eeb4301fc50fb4de74bb85cdf007fa 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -276,6 +276,15 @@ When set to 2, filenames and hunks are unfolded. Default value is 1. let g:magit_default_fold_level=[012] + *vimagit-g:magit_warning_max_lines* +This variable is the maximum number of diff lines that vimagit will display +without warning the user. If the number of diff lines to display is greater than +this variable, vimagit will ask a confirmation to the user before refreshing the +buffer. If user answer is 'yes', vimagit will display diff lines as expected. +If user answer is 'no', vimagit will close all file diffs before refreshing. +Defaulty value is 10000. +let g:magit_warning_max_lines=val + =============================================================================== 6. FAQ *vimagit-FAQ* diff --git a/plugin/magit.vim b/plugin/magit.vim index ed66ec3456a7f2549de43fa988d21dd228fd582f..b17c83713b72971e5cb4ca753b03ace7cf643baa 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -62,6 +62,8 @@ call s:set('g:magit_show_help', 1) call s:set('g:magit_default_show_all_files', 0) call s:set('g:magit_default_fold_level', 1) +call s:set('g:magit_warning_max_lines', 10000) + execute "nnoremap <silent> " . g:magit_show_magit_mapping . " :call magit#show_magit('v')<cr>" " }}} @@ -591,6 +593,17 @@ function! magit#update_buffer() call <SID>mg_get_commit_section() endif call s:state.update() + + if ( s:state.nb_diff_lines > g:magit_warning_max_lines && b:magit_warning_answered_yes == 0 ) + let ret = input("There are " . s:state.nb_diff_lines . " diff lines to display. Do you want to display all diffs? y(es) / N(o) : ", "") + if ( ret !~? '^y\%(e\%(s\)\?\)\?$' ) + let b:magit_default_show_all_files = 0 + call s:state.set_files_visible(0) + else + let b:magit_warning_answered_yes = 1 + endif + endif + call <SID>mg_get_staged_section('staged') call <SID>mg_get_staged_section('unstaged') call <SID>mg_get_stashes() @@ -636,6 +649,7 @@ function! magit#show_magit(display, ...) let b:magit_default_show_all_files = g:magit_default_show_all_files let b:magit_default_fold_level = g:magit_default_fold_level + let b:magit_warning_answered_yes = 0 if ( a:0 > 0 ) let b:magit_default_show_all_files = a:1