File tree Expand file tree Collapse file tree 3 files changed +39
-36
lines changed Expand file tree Collapse file tree 3 files changed +39
-36
lines changed Original file line number Diff line number Diff line change @@ -71,42 +71,6 @@ static int dir_file_stats(struct object_directory *object_dir, void *data)
71
71
return 0 ;
72
72
}
73
73
74
- /*
75
- * Get the d_type of a dirent. If the d_type is unknown, derive it from
76
- * stat.st_mode.
77
- *
78
- * Note that 'path' is assumed to have a trailing slash. It is also modified
79
- * in-place during the execution of the function, but is then reverted to its
80
- * original value before returning.
81
- */
82
- static unsigned char get_dtype (struct dirent * e , struct strbuf * path )
83
- {
84
- struct stat st ;
85
- unsigned char dtype = DTYPE (e );
86
- size_t base_path_len ;
87
-
88
- if (dtype != DT_UNKNOWN )
89
- return dtype ;
90
-
91
- /* d_type unknown in dirent, try to fall back on lstat results */
92
- base_path_len = path -> len ;
93
- strbuf_addstr (path , e -> d_name );
94
- if (lstat (path -> buf , & st ))
95
- goto cleanup ;
96
-
97
- /* determine d_type from st_mode */
98
- if (S_ISREG (st .st_mode ))
99
- dtype = DT_REG ;
100
- else if (S_ISDIR (st .st_mode ))
101
- dtype = DT_DIR ;
102
- else if (S_ISLNK (st .st_mode ))
103
- dtype = DT_LNK ;
104
-
105
- cleanup :
106
- strbuf_setlen (path , base_path_len );
107
- return dtype ;
108
- }
109
-
110
74
static int count_files (struct strbuf * path )
111
75
{
112
76
DIR * dir = opendir (path -> buf );
Original file line number Diff line number Diff line change @@ -2235,6 +2235,34 @@ static int get_index_dtype(struct index_state *istate,
2235
2235
return DT_UNKNOWN ;
2236
2236
}
2237
2237
2238
+ unsigned char get_dtype (struct dirent * e , struct strbuf * path )
2239
+ {
2240
+ struct stat st ;
2241
+ unsigned char dtype = DTYPE (e );
2242
+ size_t base_path_len ;
2243
+
2244
+ if (dtype != DT_UNKNOWN )
2245
+ return dtype ;
2246
+
2247
+ /* d_type unknown in dirent, try to fall back on lstat results */
2248
+ base_path_len = path -> len ;
2249
+ strbuf_addstr (path , e -> d_name );
2250
+ if (lstat (path -> buf , & st ))
2251
+ goto cleanup ;
2252
+
2253
+ /* determine d_type from st_mode */
2254
+ if (S_ISREG (st .st_mode ))
2255
+ dtype = DT_REG ;
2256
+ else if (S_ISDIR (st .st_mode ))
2257
+ dtype = DT_DIR ;
2258
+ else if (S_ISLNK (st .st_mode ))
2259
+ dtype = DT_LNK ;
2260
+
2261
+ cleanup :
2262
+ strbuf_setlen (path , base_path_len );
2263
+ return dtype ;
2264
+ }
2265
+
2238
2266
static int resolve_dtype (int dtype , struct index_state * istate ,
2239
2267
const char * path , int len )
2240
2268
{
Original file line number Diff line number Diff line change @@ -363,6 +363,17 @@ struct dir_struct {
363
363
364
364
struct dirent * readdir_skip_dot_and_dotdot (DIR * dirp );
365
365
366
+ /*
367
+ * Get the d_type of a dirent. If the d_type is unknown, derive it from
368
+ * stat.st_mode using the path to the dirent's containing directory (path) and
369
+ * the name of the dirent itself.
370
+ *
371
+ * Note that 'path' is assumed to have a trailing slash. It is also modified
372
+ * in-place during the execution of the function, but is then reverted to its
373
+ * original value before returning.
374
+ */
375
+ unsigned char get_dtype (struct dirent * e , struct strbuf * path );
376
+
366
377
/*Count the number of slashes for string s*/
367
378
int count_slashes (const char * s );
368
379
You can’t perform that action at this time.
0 commit comments