@@ -26,10 +26,25 @@ static int patch_interactive, add_interactive, edit_interactive;
26
26
static int take_worktree_changes ;
27
27
28
28
struct update_callback_data {
29
- int flags , force_mode ;
29
+ int flags ;
30
30
int add_errors ;
31
31
};
32
32
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
+
33
48
static int fix_unmerged_status (struct diff_filepair * p ,
34
49
struct update_callback_data * data )
35
50
{
@@ -65,8 +80,7 @@ static void update_callback(struct diff_queue_struct *q,
65
80
die (_ ("unexpected diff status %c" ), p -> status );
66
81
case DIFF_STATUS_MODIFIED :
67
82
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 )) {
70
84
if (!(data -> flags & ADD_CACHE_IGNORE_ERRORS ))
71
85
die (_ ("updating files failed" ));
72
86
data -> add_errors ++ ;
@@ -84,15 +98,14 @@ static void update_callback(struct diff_queue_struct *q,
84
98
}
85
99
}
86
100
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 )
89
103
{
90
104
struct update_callback_data data ;
91
105
struct rev_info rev ;
92
106
93
107
memset (& data , 0 , sizeof (data ));
94
108
data .flags = flags ;
95
- data .force_mode = force_mode ;
96
109
97
110
init_revisions (& rev , prefix );
98
111
setup_revisions (0 , NULL , & rev , NULL );
@@ -281,7 +294,7 @@ static int add_config(const char *var, const char *value, void *cb)
281
294
return git_default_config (var , value , cb );
282
295
}
283
296
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 )
285
298
{
286
299
int i , exit_status = 0 ;
287
300
@@ -294,8 +307,7 @@ static int add_files(struct dir_struct *dir, int flags, int force_mode)
294
307
}
295
308
296
309
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 )) {
299
311
if (!ignore_add_errors )
300
312
die (_ ("adding files failed" ));
301
313
exit_status = 1 ;
@@ -308,7 +320,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
308
320
int exit_status = 0 ;
309
321
struct pathspec pathspec ;
310
322
struct dir_struct dir ;
311
- int flags , force_mode ;
323
+ int flags ;
312
324
int add_new_files ;
313
325
int require_pathspec ;
314
326
char * seen = NULL ;
@@ -342,13 +354,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
342
354
if (!show_only && ignore_missing )
343
355
die (_ ("Option --ignore-missing can only be used together with --dry-run" ));
344
356
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 ]))
352
359
die (_ ("--chmod param '%s' must be either -x or +x" ), chmod_arg );
353
360
354
361
add_new_files = !take_worktree_changes && !refresh_only ;
@@ -441,11 +448,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
441
448
442
449
plug_bulk_checkin ();
443
450
444
- exit_status |= add_files_to_cache (prefix , & pathspec , flags , force_mode );
451
+ exit_status |= add_files_to_cache (prefix , & pathspec , flags );
445
452
446
453
if (add_new_files )
447
- exit_status |= add_files (& dir , flags , force_mode );
454
+ exit_status |= add_files (& dir , flags );
448
455
456
+ if (chmod_arg && pathspec .nr )
457
+ chmod_pathspec (& pathspec , chmod_arg [0 ]);
449
458
unplug_bulk_checkin ();
450
459
451
460
finish :
0 commit comments