@@ -329,29 +329,32 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
329329 return 0 ;
330330}
331331
332- static int chmod_path (int flip , const char * path )
332+ static void chmod_path (int flip , const char * path )
333333{
334334 int pos ;
335335 struct cache_entry * ce ;
336336 unsigned int mode ;
337337
338338 pos = cache_name_pos (path , strlen (path ));
339339 if (pos < 0 )
340- return -1 ;
340+ goto fail ;
341341 ce = active_cache [pos ];
342342 mode = ntohl (ce -> ce_mode );
343343 if (!S_ISREG (mode ))
344- return -1 ;
344+ goto fail ;
345345 switch (flip ) {
346346 case '+' :
347347 ce -> ce_mode |= htonl (0111 ); break ;
348348 case '-' :
349349 ce -> ce_mode &= htonl (~0111 ); break ;
350350 default :
351- return -1 ;
351+ goto fail ;
352352 }
353353 active_cache_changed = 1 ;
354- return 0 ;
354+ report ("chmod %cx '%s'" , flip , path );
355+ return ;
356+ fail :
357+ die ("git-update-index: cannot chmod %cx '%s'" , flip , path );
355358}
356359
357360static struct cache_file cache_file ;
@@ -597,6 +600,7 @@ int main(int argc, const char **argv)
597600 int read_from_stdin = 0 ;
598601 const char * prefix = setup_git_directory ();
599602 int prefix_length = prefix ? strlen (prefix ) : 0 ;
603+ char set_executable_bit = 0 ;
600604
601605 git_config (git_default_config );
602606
@@ -663,8 +667,7 @@ int main(int argc, const char **argv)
663667 !strcmp (path , "--chmod=+x" )) {
664668 if (argc <= i + 1 )
665669 die ("git-update-index: %s <path>" , path );
666- if (chmod_path (path [8 ], argv [++ i ]))
667- die ("git-update-index: %s cannot chmod %s" , path , argv [i ]);
670+ set_executable_bit = path [8 ];
668671 continue ;
669672 }
670673 if (!strcmp (path , "--assume-unchanged" )) {
@@ -719,6 +722,8 @@ int main(int argc, const char **argv)
719722 die ("unknown option %s" , path );
720723 }
721724 update_one (path , prefix , prefix_length );
725+ if (set_executable_bit )
726+ chmod_path (set_executable_bit , path );
722727 }
723728 if (read_from_stdin ) {
724729 struct strbuf buf ;
@@ -733,6 +738,10 @@ int main(int argc, const char **argv)
733738 else
734739 path_name = buf .buf ;
735740 update_one (path_name , prefix , prefix_length );
741+ if (set_executable_bit ) {
742+ const char * p = prefix_path (prefix , prefix_length , path_name );
743+ chmod_path (set_executable_bit , p );
744+ }
736745 if (path_name != buf .buf )
737746 free (path_name );
738747 }
0 commit comments