@@ -328,29 +328,32 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
328328 return 0 ;
329329}
330330
331- static int chmod_path (int flip , const char * path )
331+ static void chmod_path (int flip , const char * path )
332332{
333333 int pos ;
334334 struct cache_entry * ce ;
335335 unsigned int mode ;
336336
337337 pos = cache_name_pos (path , strlen (path ));
338338 if (pos < 0 )
339- return -1 ;
339+ goto fail ;
340340 ce = active_cache [pos ];
341341 mode = ntohl (ce -> ce_mode );
342342 if (!S_ISREG (mode ))
343- return -1 ;
343+ goto fail ;
344344 switch (flip ) {
345345 case '+' :
346346 ce -> ce_mode |= htonl (0111 ); break ;
347347 case '-' :
348348 ce -> ce_mode &= htonl (~0111 ); break ;
349349 default :
350- return -1 ;
350+ goto fail ;
351351 }
352352 active_cache_changed = 1 ;
353- return 0 ;
353+ report ("chmod %cx '%s'" , flip , path );
354+ return ;
355+ fail :
356+ die ("git-update-index: cannot chmod %cx '%s'" , flip , path );
354357}
355358
356359static struct cache_file cache_file ;
@@ -478,6 +481,7 @@ int main(int argc, const char **argv)
478481 int read_from_stdin = 0 ;
479482 const char * prefix = setup_git_directory ();
480483 int prefix_length = prefix ? strlen (prefix ) : 0 ;
484+ char set_executable_bit = 0 ;
481485
482486 git_config (git_default_config );
483487
@@ -544,8 +548,7 @@ int main(int argc, const char **argv)
544548 !strcmp (path , "--chmod=+x" )) {
545549 if (argc <= i + 1 )
546550 die ("git-update-index: %s <path>" , path );
547- if (chmod_path (path [8 ], argv [++ i ]))
548- die ("git-update-index: %s cannot chmod %s" , path , argv [i ]);
551+ set_executable_bit = path [8 ];
549552 continue ;
550553 }
551554 if (!strcmp (path , "--assume-unchanged" )) {
@@ -594,6 +597,8 @@ int main(int argc, const char **argv)
594597 die ("unknown option %s" , path );
595598 }
596599 update_one (path , prefix , prefix_length );
600+ if (set_executable_bit )
601+ chmod_path (set_executable_bit , path );
597602 }
598603 if (read_from_stdin ) {
599604 struct strbuf buf ;
@@ -608,6 +613,10 @@ int main(int argc, const char **argv)
608613 else
609614 path_name = buf .buf ;
610615 update_one (path_name , prefix , prefix_length );
616+ if (set_executable_bit ) {
617+ const char * p = prefix_path (prefix , prefix_length , path_name );
618+ chmod_path (set_executable_bit , p );
619+ }
611620 if (path_name != buf .buf )
612621 free (path_name );
613622 }
0 commit comments