From 99cd0012b10a40fb22b7b4e29d11a70b1296536f Mon Sep 17 00:00:00 2001
From: Jerome Reybert <jreybert@gmail.com>
Date: Tue, 10 Nov 2015 14:06:53 +0100
Subject: [PATCH] autoload/magit/state.vim: get submodule changes with git
 submodule summary instead of git diff

---
 autoload/magit/git.vim   | 20 ++++++++++++++++++++
 autoload/magit/state.vim |  4 ++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim
index 6ec578e..0f54775 100644
--- a/autoload/magit/git.vim
+++ b/autoload/magit/git.vim
@@ -75,6 +75,26 @@ function! magit#git#git_diff(filename, status, mode)
 	endif
 	return diff_list
 endfunction
+
+" magit#git#git_sub_summary: helper function to get diff of a submodule
+" nota: when git fail (due to misformated patch for example), an error
+" message is raised.
+" param[in] filemane: it must be quoted if it contains spaces
+" param[in] mode: can be staged or unstaged
+function! magit#git#git_sub_summary(filename, mode)
+	let staged_flag = ( a:mode == 'staged' ) ? " --cached " : " --files "
+	let git_cmd="git submodule summary " . staged_flag . " HEAD "
+				\ .a:filename
+	silent let diff_list=magit#utils#systemlist(git_cmd)
+	if ( empty(diff_list) )
+		echohl WarningMsg
+		echom "diff command \"" . diff_cmd . "\" returned nothing"
+		echohl None
+		throw 'diff error'
+	endif
+	return diff_list
+endfunction
+
 " magit#git#git_add: helper function to add a whole file
 " nota: when git fail (due to misformated patch for example), an error
 " message is raised.
diff --git a/autoload/magit/state.vim b/autoload/magit/state.vim
index 65bc021..b65276a 100644
--- a/autoload/magit/state.vim
+++ b/autoload/magit/state.vim
@@ -164,8 +164,8 @@ function! magit#state#add_file(mode, status, filename, depth) dict
 		if ( !file.is_visible() )
 			return
 		endif
-		let diff_list=magit#git#git_diff(magit#utils#add_quotes(a:filename),
-					\ a:status, a:mode)
+		let diff_list=magit#git#git_sub_summary(magit#utils#add_quotes(a:filename),
+					\ a:mode)
 		let file.diff.hunks[0].header = ''
 		let file.diff.hunks[0].lines = diff_list
 		let self.nb_diff_lines += len(diff_list)
-- 
GitLab