@@ -206,7 +206,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
206206 if (silent_on_removed )
207207 continue ;
208208 diff_addremove (& revs -> diffopt , '-' , ce -> ce_mode ,
209- ce -> sha1 , ce -> name , 0 );
209+ ce -> sha1 , !is_null_sha1 (ce -> sha1 ),
210+ ce -> name , 0 );
210211 continue ;
211212 }
212213 changed = match_stat_with_submodule (& revs -> diffopt , ce , & st ,
@@ -220,6 +221,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
220221 newmode = ce_mode_from_stat (ce , st .st_mode );
221222 diff_change (& revs -> diffopt , oldmode , newmode ,
222223 ce -> sha1 , (changed ? null_sha1 : ce -> sha1 ),
224+ !is_null_sha1 (ce -> sha1 ), (changed ? 0 : !is_null_sha1 (ce -> sha1 )),
223225 ce -> name , 0 , dirty_submodule );
224226
225227 }
@@ -236,11 +238,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
236238static void diff_index_show_file (struct rev_info * revs ,
237239 const char * prefix ,
238240 struct cache_entry * ce ,
239- const unsigned char * sha1 , unsigned int mode ,
241+ const unsigned char * sha1 , int sha1_valid ,
242+ unsigned int mode ,
240243 unsigned dirty_submodule )
241244{
242245 diff_addremove (& revs -> diffopt , prefix [0 ], mode ,
243- sha1 , ce -> name , dirty_submodule );
246+ sha1 , sha1_valid , ce -> name , dirty_submodule );
244247}
245248
246249static int get_stat_data (struct cache_entry * ce ,
@@ -295,7 +298,7 @@ static void show_new_file(struct rev_info *revs,
295298 & dirty_submodule , & revs -> diffopt ) < 0 )
296299 return ;
297300
298- diff_index_show_file (revs , "+" , new , sha1 , mode , dirty_submodule );
301+ diff_index_show_file (revs , "+" , new , sha1 , ! is_null_sha1 ( sha1 ), mode , dirty_submodule );
299302}
300303
301304static int show_modified (struct rev_info * revs ,
@@ -312,7 +315,7 @@ static int show_modified(struct rev_info *revs,
312315 & dirty_submodule , & revs -> diffopt ) < 0 ) {
313316 if (report_missing )
314317 diff_index_show_file (revs , "-" , old ,
315- old -> sha1 , old -> ce_mode , 0 );
318+ old -> sha1 , 1 , old -> ce_mode , 0 );
316319 return -1 ;
317320 }
318321
@@ -347,7 +350,8 @@ static int show_modified(struct rev_info *revs,
347350 return 0 ;
348351
349352 diff_change (& revs -> diffopt , oldmode , mode ,
350- old -> sha1 , sha1 , old -> name , 0 , dirty_submodule );
353+ old -> sha1 , sha1 , 1 , !is_null_sha1 (sha1 ),
354+ old -> name , 0 , dirty_submodule );
351355 return 0 ;
352356}
353357
@@ -380,7 +384,7 @@ static void do_oneway_diff(struct unpack_trees_options *o,
380384 struct diff_filepair * pair ;
381385 pair = diff_unmerge (& revs -> diffopt , idx -> name );
382386 if (tree )
383- fill_filespec (pair -> one , tree -> sha1 , tree -> ce_mode );
387+ fill_filespec (pair -> one , tree -> sha1 , 1 , tree -> ce_mode );
384388 return ;
385389 }
386390
@@ -396,7 +400,7 @@ static void do_oneway_diff(struct unpack_trees_options *o,
396400 * Something removed from the tree?
397401 */
398402 if (!idx ) {
399- diff_index_show_file (revs , "-" , tree , tree -> sha1 , tree -> ce_mode , 0 );
403+ diff_index_show_file (revs , "-" , tree , tree -> sha1 , 1 , tree -> ce_mode , 0 );
400404 return ;
401405 }
402406
0 commit comments