diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index c0c2673eded3b64257d5cdd32809e01270775929..9c48939d01cc5eec16b03d3b5c1253ff103a30db 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -102,6 +102,9 @@ endfunction " param[in] filemane: it must be quoted if it contains spaces " param[in] status: status of the file (see g:magit_git_status_code) " param[in] mode: can be staged or unstaged +" return: two values +" [0]: boolean, if true current file is binary +" [1]: string array containing diff output function! magit#git#git_diff(filename, status, mode) let dev_null = ( a:status == '?' ) ? "/dev/null " : "" let staged_flag = ( a:mode == 'staged' ) ? "--staged" : "" @@ -122,7 +125,9 @@ function! magit#git#git_diff(filename, status, mode) echohl None throw 'diff error' endif - return diff_list + return [ + \ ( diff_list[-1] =~ "^Binary files .* differ$" && len(diff_list) <= 4 ) + \, diff_list ] endfunction " magit#git#sub_check: this function checks if given submodule has modified or diff --git a/autoload/magit/state.vim b/autoload/magit/state.vim index 4f2cbb4dbe981d7d1bdee14964efdf6bcb60dbce..fc225f2368f5632a370dc9c3cc8872d99dd7f632 100644 --- a/autoload/magit/state.vim +++ b/autoload/magit/state.vim @@ -206,17 +206,25 @@ function! magit#state#add_file(mode, status, filename, depth) dict let file.status = 'E' let file.empty = 1 let file.diff.hunks[0].header = 'New empty file' - elseif ( magit#utils#is_binary(magit#utils#add_quotes(a:filename))) - let file.binary = 1 - let file.diff.hunks[0].header = 'Binary file' else if ( !file.init_visible() ) return endif let line = 0 " match( - let diff_list=magit#git#git_diff(magit#utils#add_quotes(a:filename), + let [ is_bin, diff_list ] = + \ magit#git#git_diff(magit#utils#add_quotes(a:filename), \ a:status, a:mode) + + if ( is_bin ) + let file.binary = 1 + let file.diff.hunks[0].header = 'Binary file' + if ( file.new ) + call file.set_visible(0) + endif + return + endif + let file.diff.len = len(diff_list) if ( self.check_max_lines(file) != 0 ) diff --git a/autoload/magit/utils.vim b/autoload/magit/utils.vim index 3b5dd5ba028f41fc2af54d778ec84b08c48bef47..9bcf6791ca4362e45c663dae57241ea6aac92ac5 100644 --- a/autoload/magit/utils.vim +++ b/autoload/magit/utils.vim @@ -1,11 +1,4 @@ -" s:magit#utils#is_binary: check if file is a binary file -" param[in] filename: the file path. it must quoted if it contains spaces -function! magit#utils#is_binary(filename) - return ( match(system("file --mime " . a:filename ), - \ ".*charset=binary") != -1 ) -endfunction - " magit#utils#ls_all: list all files (including hidden ones) in a given path " return : list of filenames function! magit#utils#ls_all(path)