Skip to content

Commit

Permalink
autoload/magit/state.vim: remove is_binary function, replaced by git …
Browse files Browse the repository at this point in the history
…diff parsing (fix #60, #61)

for the moment, git diff output is not localized in case of binary detection
  • Loading branch information
jreybert committed Feb 9, 2016
1 parent 9a87dec commit 826432e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion autoload/magit/git.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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" : ""
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions autoload/magit/state.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
7 changes: 0 additions & 7 deletions autoload/magit/utils.vim
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 826432e

Please sign in to comment.