diff --git a/plugin/magit.vim b/plugin/magit.vim
index aa81dbb776b0c27fe821e49d26d1651e85d8457b..65a5d81f5fc9b21961993bfe229f8491f90a31c8 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -143,7 +143,8 @@ endfunction
 function! s:mg_display_files(mode, curdir, depth)
 
 	" FIXME: ouch, must store subdirs in more efficient way
-	for [ filename, file_props ] in items(s:state.get_files(a:mode))
+	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 . '.*' )
 			continue
 		endif