@@ -26,10 +26,25 @@ static int patch_interactive, add_interactive, edit_interactive;
2626static int take_worktree_changes ;
2727
2828struct update_callback_data {
29- int flags , force_mode ;
29+ int flags ;
3030 int add_errors ;
3131};
3232
33+ static void chmod_pathspec (struct pathspec * pathspec , int force_mode )
34+ {
35+ int i ;
36+
37+ for (i = 0 ; i < active_nr ; i ++ ) {
38+ struct cache_entry * ce = active_cache [i ];
39+
40+ if (pathspec && !ce_path_match (ce , pathspec , NULL ))
41+ continue ;
42+
43+ if (chmod_cache_entry (ce , force_mode ) < 0 )
44+ fprintf (stderr , "cannot chmod '%s'" , ce -> name );
45+ }
46+ }
47+
3348static int fix_unmerged_status (struct diff_filepair * p ,
3449 struct update_callback_data * data )
3550{
@@ -65,8 +80,7 @@ static void update_callback(struct diff_queue_struct *q,
6580 die (_ ("unexpected diff status %c" ), p -> status );
6681 case DIFF_STATUS_MODIFIED :
6782 case DIFF_STATUS_TYPE_CHANGED :
68- if (add_file_to_index (& the_index , path ,
69- data -> flags , data -> force_mode )) {
83+ if (add_file_to_index (& the_index , path , data -> flags )) {
7084 if (!(data -> flags & ADD_CACHE_IGNORE_ERRORS ))
7185 die (_ ("updating files failed" ));
7286 data -> add_errors ++ ;
@@ -84,15 +98,14 @@ static void update_callback(struct diff_queue_struct *q,
8498 }
8599}
86100
87- int add_files_to_cache (const char * prefix , const struct pathspec * pathspec ,
88- int flags , int force_mode )
101+ int add_files_to_cache (const char * prefix ,
102+ const struct pathspec * pathspec , int flags )
89103{
90104 struct update_callback_data data ;
91105 struct rev_info rev ;
92106
93107 memset (& data , 0 , sizeof (data ));
94108 data .flags = flags ;
95- data .force_mode = force_mode ;
96109
97110 init_revisions (& rev , prefix );
98111 setup_revisions (0 , NULL , & rev , NULL );
@@ -281,7 +294,7 @@ static int add_config(const char *var, const char *value, void *cb)
281294 return git_default_config (var , value , cb );
282295}
283296
284- static int add_files (struct dir_struct * dir , int flags , int force_mode )
297+ static int add_files (struct dir_struct * dir , int flags )
285298{
286299 int i , exit_status = 0 ;
287300
@@ -294,8 +307,7 @@ static int add_files(struct dir_struct *dir, int flags, int force_mode)
294307 }
295308
296309 for (i = 0 ; i < dir -> nr ; i ++ )
297- if (add_file_to_index (& the_index , dir -> entries [i ]-> name ,
298- flags , force_mode )) {
310+ if (add_file_to_index (& the_index , dir -> entries [i ]-> name , flags )) {
299311 if (!ignore_add_errors )
300312 die (_ ("adding files failed" ));
301313 exit_status = 1 ;
@@ -308,7 +320,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
308320 int exit_status = 0 ;
309321 struct pathspec pathspec ;
310322 struct dir_struct dir ;
311- int flags , force_mode ;
323+ int flags ;
312324 int add_new_files ;
313325 int require_pathspec ;
314326 char * seen = NULL ;
@@ -342,13 +354,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
342354 if (!show_only && ignore_missing )
343355 die (_ ("Option --ignore-missing can only be used together with --dry-run" ));
344356
345- if (!chmod_arg )
346- force_mode = 0 ;
347- else if (!strcmp (chmod_arg , "-x" ))
348- force_mode = 0666 ;
349- else if (!strcmp (chmod_arg , "+x" ))
350- force_mode = 0777 ;
351- else
357+ if (chmod_arg && ((chmod_arg [0 ] != '-' && chmod_arg [0 ] != '+' ) ||
358+ chmod_arg [1 ] != 'x' || chmod_arg [2 ]))
352359 die (_ ("--chmod param '%s' must be either -x or +x" ), chmod_arg );
353360
354361 add_new_files = !take_worktree_changes && !refresh_only ;
@@ -441,11 +448,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
441448
442449 plug_bulk_checkin ();
443450
444- exit_status |= add_files_to_cache (prefix , & pathspec , flags , force_mode );
451+ exit_status |= add_files_to_cache (prefix , & pathspec , flags );
445452
446453 if (add_new_files )
447- exit_status |= add_files (& dir , flags , force_mode );
454+ exit_status |= add_files (& dir , flags );
448455
456+ if (chmod_arg && pathspec .nr )
457+ chmod_pathspec (& pathspec , chmod_arg [0 ]);
449458 unplug_bulk_checkin ();
450459
451460finish :
0 commit comments