diff --git a/autoload/magit/state.vim b/autoload/magit/state.vim index 39f2c209ddfd8539ef62efec6b6b68b1d3595183..c7b7d03a432feb25349145921701be6361107889 100644 --- a/autoload/magit/state.vim +++ b/autoload/magit/state.vim @@ -25,6 +25,23 @@ function! magit#state#must_be_added() dict \ self.binary == 1 ) endfunction +" magit#state#file_get_hunks: function accessor for hunks objects +" return: List of List of hunks lines +function! magit#state#file_get_hunks() dict + return self.diff.hunks +endfunction + +" magit#state#file_get_flat_hunks: function accessor for hunks lines +" return: all hunks lines of a file, including hunk headers +function! magit#state#file_get_flat_hunks() dict + let hunks = self.diff.hunks + let lines = [] + for hunk in hunks + call add(lines, hunk.header) + call add(lines, hunk.lines) + endfor + return lines +endfunction " s:hunk_template: template for hunk object (nested in s:diff_template) " WARNING: this variable must be deepcopy()'ied @@ -56,6 +73,8 @@ let s:file_template = { \ 'set_visible': function("magit#state#set_file_visible"), \ 'toggle_visible': function("magit#state#toggle_file_visible"), \ 'must_be_added': function("magit#state#must_be_added"), +\ 'get_hunks' : function("magit#state#file_get_hunks"), +\ 'get_flat_hunks' : function("magit#state#file_get_flat_hunks"), \} " magit#state#get_file: function accessor for file @@ -85,29 +104,6 @@ function! magit#state#get_header(mode, filename) dict return diff_dict_file.diff.header endfunction -" magit#state#get_hunks: function accessor for hunks objects -" param[in] mode: can be staged or unstaged -" param[in] filename: hunks of filename to access -" return: List of List of hunks lines -function! magit#state#get_hunks(mode, filename) dict - let diff_dict_file = self.get_file(a:mode, a:filename, 0) - return diff_dict_file.diff.hunks -endfunction - -" magit#state#get_hunks: function accessor for hunks lines -" param[in] mode: can be staged or unstaged -" param[in] filename: hunks of filename to access -" return: all hunks lines of a file, including hunk headers -function! magit#state#get_flat_hunks(mode, filename) dict - let hunks = self.get_hunks(a:mode, a:filename) - let lines = [] - for hunk in hunks - call add(lines, hunk.header) - call add(lines, hunk.lines) - endfor - return lines -endfunction - " magit#state#add_file: method to add a file with all its " properties (filename, exists, status, header and hunks) " param[in] mode: can be staged or unstaged @@ -230,8 +226,6 @@ let magit#state#state = { \ 'get_file': function("magit#state#get_file"), \ 'get_files': function("magit#state#get_files"), \ 'get_header': function("magit#state#get_header"), - \ 'get_hunks': function("magit#state#get_hunks"), - \ 'get_flat_hunks': function("magit#state#get_flat_hunks"), \ 'add_file': function("magit#state#add_file"), \ 'update': function("magit#state#update"), \ 'dict': { 'staged': {}, 'unstaged': {}}, diff --git a/plugin/magit.vim b/plugin/magit.vim index 192dc27d9ae6f01e6deae96de09006f9abef50a2..77daf24308cb0200cad9cf13169deb7e4c016102 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -144,31 +144,31 @@ function! s:mg_display_files(mode, curdir, depth) " FIXME: ouch, must store subdirs in more efficient way for filename in sort(keys(s:state.get_files(a:mode))) - let file_props = s:state.get_file(a:mode, filename, 0) - if ( file_props.depth != a:depth || filename !~ a:curdir . '.*' ) + let file = s:state.get_file(a:mode, filename, 0) + if ( file.depth != a:depth || filename !~ a:curdir . '.*' ) continue endif - if ( file_props.empty == 1 ) + if ( file.empty == 1 ) put =g:magit_git_status_code.E . ': ' . filename - elseif ( file_props.symlink != '' ) - put =g:magit_git_status_code.L . ': ' . filename . ' -> ' . file_props.symlink - elseif ( file_props.dir != 0 ) + elseif ( file.symlink != '' ) + put =g:magit_git_status_code.L . ': ' . filename . ' -> ' . file.symlink + elseif ( file.dir != 0 ) put =g:magit_git_status_code.N . ': ' . filename - if ( file_props.visible == 1 ) + if ( file.visible == 1 ) call s:mg_display_files(a:mode, filename, a:depth + 1) continue endif else - put =g:magit_git_status_code[file_props.status] . ': ' . filename + put =g:magit_git_status_code[file.status] . ': ' . filename endif - if ( file_props.visible == 0 ) + if ( file.visible == 0 ) put ='' continue endif - if ( file_props.exists == 0 ) + if ( file.exists == 0 ) echoerr "Error, " . filename . " should not exists" endif - let hunks=s:state.get_hunks(a:mode, filename) + let hunks = file.get_hunks() for hunk in hunks silent put =hunk.header silent put =hunk.lines @@ -451,7 +451,7 @@ function! s:mg_create_diff_from_select(select_lines) endif let section=<SID>mg_get_section() let filename=<SID>mg_get_filename() - let hunks = s:state.get_hunks(section, filename) + let hunks = s:state.get_file(section, filename).get_hunks() for hunk in hunks if ( hunk.header == getline(starthunk) ) let current_hunk = hunk @@ -683,7 +683,7 @@ function! s:mg_select_closed_file() let file = s:state.get_file(section, filename) if ( file.is_visible() == 0 || \ file.is_dir() == 1 ) - let selection = s:state.get_flat_hunks(section, filename) + let selection = s:state.get_file(section, filename).get_flat_hunks() return selection endif endif