|
1 | 1 | #ifndef DIR_H
|
2 | 2 | #define DIR_H
|
3 | 3 |
|
4 |
| -/* See Documentation/technical/api-directory-listing.txt */ |
5 |
| - |
6 | 4 | #include "cache.h"
|
7 | 5 | #include "strbuf.h"
|
8 | 6 |
|
| 7 | +/** |
| 8 | + * The directory listing API is used to enumerate paths in the work tree, |
| 9 | + * optionally taking `.git/info/exclude` and `.gitignore` files per directory |
| 10 | + * into account. |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Calling sequence |
| 15 | + * ---------------- |
| 16 | + * |
| 17 | + * Note: The index may be checked for .gitignore files that are |
| 18 | + * CE_SKIP_WORKTREE marked. If you want to exclude files, make sure you have |
| 19 | + * loaded the index first. |
| 20 | + * |
| 21 | + * - Prepare `struct dir_struct dir` and clear it with `memset(&dir, 0, |
| 22 | + * sizeof(dir))`. |
| 23 | + * |
| 24 | + * - To add single exclude pattern, call `add_pattern_list()` and then |
| 25 | + * `add_pattern()`. |
| 26 | + * |
| 27 | + * - To add patterns from a file (e.g. `.git/info/exclude`), call |
| 28 | + * `add_patterns_from_file()` , and/or set `dir.exclude_per_dir`. A |
| 29 | + * short-hand function `setup_standard_excludes()` can be used to set |
| 30 | + * up the standard set of exclude settings. |
| 31 | + * |
| 32 | + * - Set options described in the Data Structure section above. |
| 33 | + * |
| 34 | + * - Call `read_directory()`. |
| 35 | + * |
| 36 | + * - Use `dir.entries[]`. |
| 37 | + * |
| 38 | + * - Call `clear_directory()` when none of the contained elements are no longer in use. |
| 39 | + * |
| 40 | + */ |
| 41 | + |
9 | 42 | struct dir_entry {
|
10 | 43 | unsigned int len;
|
11 | 44 | char name[FLEX_ARRAY]; /* more */
|
@@ -144,25 +177,101 @@ struct untracked_cache {
|
144 | 177 | unsigned int use_fsmonitor : 1;
|
145 | 178 | };
|
146 | 179 |
|
| 180 | +/** |
| 181 | + * structure is used to pass directory traversal options to the library and to |
| 182 | + * record the paths discovered. A single `struct dir_struct` is used regardless |
| 183 | + * of whether or not the traversal recursively descends into subdirectories. |
| 184 | + */ |
147 | 185 | struct dir_struct {
|
148 |
| - int nr, alloc; |
149 |
| - int ignored_nr, ignored_alloc; |
| 186 | + |
| 187 | + /* The number of members in `entries[]` array. */ |
| 188 | + int nr; |
| 189 | + |
| 190 | + /* Internal use; keeps track of allocation of `entries[]` array.*/ |
| 191 | + int alloc; |
| 192 | + |
| 193 | + /* The number of members in `ignored[]` array. */ |
| 194 | + int ignored_nr; |
| 195 | + |
| 196 | + int ignored_alloc; |
| 197 | + |
| 198 | + /* bit-field of options */ |
150 | 199 | enum {
|
| 200 | + |
| 201 | + /** |
| 202 | + * Return just ignored files in `entries[]`, not untracked files. |
| 203 | + * This flag is mutually exclusive with `DIR_SHOW_IGNORED_TOO`. |
| 204 | + */ |
151 | 205 | DIR_SHOW_IGNORED = 1<<0,
|
| 206 | + |
| 207 | + /* Include a directory that is not tracked. */ |
152 | 208 | DIR_SHOW_OTHER_DIRECTORIES = 1<<1,
|
| 209 | + |
| 210 | + /* Do not include a directory that is not tracked and is empty. */ |
153 | 211 | DIR_HIDE_EMPTY_DIRECTORIES = 1<<2,
|
| 212 | + |
| 213 | + /** |
| 214 | + * If set, recurse into a directory that looks like a Git directory. |
| 215 | + * Otherwise it is shown as a directory. |
| 216 | + */ |
154 | 217 | DIR_NO_GITLINKS = 1<<3,
|
| 218 | + |
| 219 | + /** |
| 220 | + * Special mode for git-add. Return ignored files in `ignored[]` and |
| 221 | + * untracked files in `entries[]`. Only returns ignored files that match |
| 222 | + * pathspec exactly (no wildcards). Does not recurse into ignored |
| 223 | + * directories. |
| 224 | + */ |
155 | 225 | DIR_COLLECT_IGNORED = 1<<4,
|
| 226 | + |
| 227 | + /** |
| 228 | + * Similar to `DIR_SHOW_IGNORED`, but return ignored files in |
| 229 | + * `ignored[]` in addition to untracked files in `entries[]`. |
| 230 | + * This flag is mutually exclusive with `DIR_SHOW_IGNORED`. |
| 231 | + */ |
156 | 232 | DIR_SHOW_IGNORED_TOO = 1<<5,
|
| 233 | + |
157 | 234 | DIR_COLLECT_KILLED_ONLY = 1<<6,
|
| 235 | + |
| 236 | + /** |
| 237 | + * Only has meaning if `DIR_SHOW_IGNORED_TOO` is also set; if this is |
| 238 | + * set, the untracked contents of untracked directories are also |
| 239 | + * returned in `entries[]`. |
| 240 | + */ |
158 | 241 | DIR_KEEP_UNTRACKED_CONTENTS = 1<<7,
|
| 242 | + |
| 243 | + /** |
| 244 | + * Only has meaning if `DIR_SHOW_IGNORED_TOO` is also set; if this is |
| 245 | + * set, returns ignored files and directories that match an exclude |
| 246 | + * pattern. If a directory matches an exclude pattern, then the |
| 247 | + * directory is returned and the contained paths are not. A directory |
| 248 | + * that does not match an exclude pattern will not be returned even if |
| 249 | + * all of its contents are ignored. In this case, the contents are |
| 250 | + * returned as individual entries. |
| 251 | + * |
| 252 | + * If this is set, files and directories that explicitly match an ignore |
| 253 | + * pattern are reported. Implicitly ignored directories (directories that |
| 254 | + * do not match an ignore pattern, but whose contents are all ignored) |
| 255 | + * are not reported, instead all of the contents are reported. |
| 256 | + */ |
159 | 257 | DIR_SHOW_IGNORED_TOO_MODE_MATCHING = 1<<8,
|
| 258 | + |
160 | 259 | DIR_SKIP_NESTED_GIT = 1<<9
|
161 | 260 | } flags;
|
| 261 | + |
| 262 | + /* An array of `struct dir_entry`, each element of which describes a path. */ |
162 | 263 | struct dir_entry **entries;
|
| 264 | + |
| 265 | + /** |
| 266 | + * used for ignored paths with the `DIR_SHOW_IGNORED_TOO` and |
| 267 | + * `DIR_COLLECT_IGNORED` flags. |
| 268 | + */ |
163 | 269 | struct dir_entry **ignored;
|
164 | 270 |
|
165 |
| - /* Exclude info */ |
| 271 | + /** |
| 272 | + * The name of the file to be read in each directory for excluded files |
| 273 | + * (typically `.gitignore`). |
| 274 | + */ |
166 | 275 | const char *exclude_per_dir;
|
167 | 276 |
|
168 | 277 | /*
|
|
0 commit comments