2007-11-25 08:48:04 +01:00
|
|
|
directory listing API
|
|
|
|
=====================
|
|
|
|
|
|
|
|
The directory listing API is used to enumerate paths in the work tree,
|
|
|
|
optionally taking `.git/info/exclude` and `.gitignore` files per
|
|
|
|
directory into account.
|
|
|
|
|
|
|
|
Data structure
|
|
|
|
--------------
|
|
|
|
|
|
|
|
`struct dir_struct` structure is used to pass directory traversal
|
2012-12-27 03:32:21 +01:00
|
|
|
options to the library and to record the paths discovered. A single
|
|
|
|
`struct dir_struct` is used regardless of whether or not the traversal
|
|
|
|
recursively descends into subdirectories.
|
|
|
|
|
|
|
|
The notable options are:
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
`exclude_per_dir`::
|
|
|
|
|
|
|
|
The name of the file to be read in each directory for excluded
|
|
|
|
files (typically `.gitignore`).
|
|
|
|
|
2012-12-27 03:32:20 +01:00
|
|
|
`flags`::
|
2007-11-25 08:48:04 +01:00
|
|
|
|
2013-04-15 21:15:03 +02:00
|
|
|
A bit-field of options (the `*IGNORED*` flags are mutually exclusive):
|
2007-11-25 08:48:04 +01:00
|
|
|
|
2012-12-27 03:32:20 +01:00
|
|
|
`DIR_SHOW_IGNORED`:::
|
2007-11-25 08:48:04 +01:00
|
|
|
|
2013-04-15 21:15:03 +02:00
|
|
|
Return just ignored files in `entries[]`, not untracked files.
|
|
|
|
|
|
|
|
`DIR_SHOW_IGNORED_TOO`:::
|
|
|
|
|
|
|
|
Similar to `DIR_SHOW_IGNORED`, but return ignored files in `ignored[]`
|
|
|
|
in addition to untracked files in `entries[]`.
|
|
|
|
|
|
|
|
`DIR_COLLECT_IGNORED`:::
|
|
|
|
|
|
|
|
Special mode for git-add. Return ignored files in `ignored[]` and
|
|
|
|
untracked files in `entries[]`. Only returns ignored files that match
|
|
|
|
pathspec exactly (no wildcards). Does not recurse into ignored
|
|
|
|
directories.
|
2007-11-25 08:48:04 +01:00
|
|
|
|
2012-12-27 03:32:20 +01:00
|
|
|
`DIR_SHOW_OTHER_DIRECTORIES`:::
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
Include a directory that is not tracked.
|
|
|
|
|
2012-12-27 03:32:20 +01:00
|
|
|
`DIR_HIDE_EMPTY_DIRECTORIES`:::
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
Do not include a directory that is not tracked and is empty.
|
|
|
|
|
2012-12-27 03:32:20 +01:00
|
|
|
`DIR_NO_GITLINKS`:::
|
2007-11-25 08:48:04 +01:00
|
|
|
|
2013-01-21 20:17:53 +01:00
|
|
|
If set, recurse into a directory that looks like a Git
|
2007-11-25 08:48:04 +01:00
|
|
|
directory. Otherwise it is shown as a directory.
|
|
|
|
|
2012-12-27 03:32:21 +01:00
|
|
|
The result of the enumeration is left in these fields:
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
`entries[]`::
|
|
|
|
|
|
|
|
An array of `struct dir_entry`, each element of which describes
|
|
|
|
a path.
|
|
|
|
|
|
|
|
`nr`::
|
|
|
|
|
|
|
|
The number of members in `entries[]` array.
|
|
|
|
|
|
|
|
`alloc`::
|
|
|
|
|
|
|
|
Internal use; keeps track of allocation of `entries[]` array.
|
|
|
|
|
2013-04-15 21:15:03 +02:00
|
|
|
`ignored[]`::
|
|
|
|
|
|
|
|
An array of `struct dir_entry`, used for ignored paths with the
|
|
|
|
`DIR_SHOW_IGNORED_TOO` and `DIR_COLLECT_IGNORED` flags.
|
|
|
|
|
|
|
|
`ignored_nr`::
|
|
|
|
|
|
|
|
The number of members in `ignored[]` array.
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
Calling sequence
|
|
|
|
----------------
|
|
|
|
|
2009-08-20 15:47:01 +02:00
|
|
|
Note: index may be looked at for .gitignore files that are CE_SKIP_WORKTREE
|
|
|
|
marked. If you to exclude files, make sure you have loaded index first.
|
|
|
|
|
2007-11-25 08:48:04 +01:00
|
|
|
* Prepare `struct dir_struct dir` and clear it with `memset(&dir, 0,
|
|
|
|
sizeof(dir))`.
|
|
|
|
|
2013-01-06 17:58:03 +01:00
|
|
|
* To add single exclude pattern, call `add_exclude_list()` and then
|
|
|
|
`add_exclude()`.
|
|
|
|
|
|
|
|
* To add patterns from a file (e.g. `.git/info/exclude`), call
|
|
|
|
`add_excludes_from_file()` , and/or set `dir.exclude_per_dir`. A
|
|
|
|
short-hand function `setup_standard_excludes()` can be used to set
|
|
|
|
up the standard set of exclude settings.
|
2007-11-25 08:48:04 +01:00
|
|
|
|
|
|
|
* Set options described in the Data Structure section above.
|
|
|
|
|
|
|
|
* Call `read_directory()`.
|
|
|
|
|
|
|
|
* Use `dir.entries[]`.
|
|
|
|
|
2013-01-06 17:58:13 +01:00
|
|
|
* Call `clear_directory()` when none of the contained elements are no longer in use.
|
2013-01-06 17:58:05 +01:00
|
|
|
|
2007-11-25 08:48:04 +01:00
|
|
|
(JC)
|