@@ -40,42 +40,29 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
40
40
dir -> nr = dst - dir -> entries ;
41
41
42
42
for (i = 0 ; i < specs ; i ++ ) {
43
- struct stat st ;
44
- const char * match ;
45
- if (seen [i ])
46
- continue ;
47
-
48
- match = pathspec [i ];
49
- if (!match [0 ])
50
- continue ;
51
-
52
- /* Existing file? We must have ignored it */
53
- if (!lstat (match , & st )) {
54
- struct dir_entry * ent ;
55
-
56
- ent = dir_add_name (dir , match , strlen (match ));
57
- ent -> ignored = 1 ;
58
- if (S_ISDIR (st .st_mode ))
59
- ent -> ignored_dir = 1 ;
60
- continue ;
61
- }
62
- die ("pathspec '%s' did not match any files" , match );
43
+ if (!seen [i ] && !file_exists (pathspec [i ]))
44
+ die ("pathspec '%s' did not match any files" ,
45
+ pathspec [i ]);
63
46
}
64
47
}
65
48
66
- static void fill_directory (struct dir_struct * dir , const char * * pathspec )
49
+ static void fill_directory (struct dir_struct * dir , const char * * pathspec ,
50
+ int ignored_too )
67
51
{
68
52
const char * path , * base ;
69
53
int baselen ;
70
54
71
55
/* Set up the default git porcelain excludes */
72
56
memset (dir , 0 , sizeof (* dir ));
73
- dir -> exclude_per_dir = ".gitignore" ;
74
- path = git_path ("info/exclude" );
75
- if (!access (path , R_OK ))
76
- add_excludes_from_file (dir , path );
77
- if (!access (excludes_file , R_OK ))
78
- add_excludes_from_file (dir , excludes_file );
57
+ if (!ignored_too ) {
58
+ dir -> collect_ignored = 1 ;
59
+ dir -> exclude_per_dir = ".gitignore" ;
60
+ path = git_path ("info/exclude" );
61
+ if (!access (path , R_OK ))
62
+ add_excludes_from_file (dir , path );
63
+ if (!access (excludes_file , R_OK ))
64
+ add_excludes_from_file (dir , excludes_file );
65
+ }
79
66
80
67
/*
81
68
* Calculate common prefix for the pathspec, and
@@ -219,13 +206,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
219
206
}
220
207
pathspec = get_pathspec (prefix , argv + i );
221
208
222
- fill_directory (& dir , pathspec );
209
+ fill_directory (& dir , pathspec , ignored_too );
223
210
224
211
if (show_only ) {
225
212
const char * sep = "" , * eof = "" ;
226
213
for (i = 0 ; i < dir .nr ; i ++ ) {
227
- if (!ignored_too && dir .entries [i ]-> ignored )
228
- continue ;
229
214
printf ("%s%s" , sep , dir .entries [i ]-> name );
230
215
sep = " " ;
231
216
eof = "\n" ;
@@ -237,25 +222,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
237
222
if (read_cache () < 0 )
238
223
die ("index file corrupt" );
239
224
240
- if (!ignored_too ) {
241
- int has_ignored = 0 ;
242
- for (i = 0 ; i < dir .nr ; i ++ )
243
- if (dir .entries [i ]-> ignored )
244
- has_ignored = 1 ;
245
- if (has_ignored ) {
246
- fprintf (stderr , ignore_warning );
247
- for (i = 0 ; i < dir .nr ; i ++ ) {
248
- if (!dir .entries [i ]-> ignored )
249
- continue ;
250
- fprintf (stderr , "%s" , dir .entries [i ]-> name );
251
- if (dir .entries [i ]-> ignored_dir )
252
- fprintf (stderr , " (directory)" );
253
- fputc ('\n' , stderr );
254
- }
255
- fprintf (stderr ,
256
- "Use -f if you really want to add them.\n" );
257
- exit (1 );
225
+ if (dir .ignored_nr ) {
226
+ fprintf (stderr , ignore_warning );
227
+ for (i = 0 ; i < dir .ignored_nr ; i ++ ) {
228
+ fprintf (stderr , "%s\n" , dir .ignored [i ]-> name );
258
229
}
230
+ fprintf (stderr , "Use -f if you really want to add them.\n" );
231
+ exit (1 );
259
232
}
260
233
261
234
for (i = 0 ; i < dir .nr ; i ++ )
0 commit comments