|
| 1 | +Path-Walk API |
| 2 | +============= |
| 3 | + |
| 4 | +The path-walk API is used to walk reachable objects, but to visit objects |
| 5 | +in batches based on a common path they appear in, or by type. |
| 6 | + |
| 7 | +For example, all reachable commits are visited in a group. All tags are |
| 8 | +visited in a group. Then, all root trees are visited. At some point, all |
| 9 | +blobs reachable via a path `my/dir/to/A` are visited. When there are |
| 10 | +multiple paths possible to reach the same object, then only one of those |
| 11 | +paths is used to visit the object. |
| 12 | + |
| 13 | +When walking a range of commits with some `UNINTERESTING` objects, the |
| 14 | +objects with the `UNINTERESTING` flag are included in these batches. In |
| 15 | +order to walk `UNINTERESTING` objects, the `--boundary` option must be |
| 16 | +used in the commit walk in order to visit `UNINTERESTING` commits. |
| 17 | + |
| 18 | +Basics |
| 19 | +------ |
| 20 | + |
| 21 | +To use the path-walk API, include `path-walk.h` and call |
| 22 | +`walk_objects_by_path()` with a customized `path_walk_info` struct. The |
| 23 | +struct is used to set all of the options for how the walk should proceed. |
| 24 | +Let's dig into the different options and their use. |
| 25 | + |
| 26 | +`path_fn` and `path_fn_data`:: |
| 27 | + The most important option is the `path_fn` option, which is a |
| 28 | + function pointer to the callback that can execute logic on the |
| 29 | + object IDs for objects grouped by type and path. This function |
| 30 | + also receives a `data` value that corresponds to the |
| 31 | + `path_fn_data` member, for providing custom data structures to |
| 32 | + this callback function. |
| 33 | + |
| 34 | +`revs`:: |
| 35 | + To configure the exact details of the reachable set of objects, |
| 36 | + use the `revs` member and initialize it using the revision |
| 37 | + machinery in `revision.h`. Initialize `revs` using calls such as |
| 38 | + `setup_revisions()` or `parse_revision_opt()`. Do not call |
| 39 | + `prepare_revision_walk()`, as that will be called within |
| 40 | + `walk_objects_by_path()`. |
| 41 | ++ |
| 42 | +It is also important that you do not specify the `--objects` flag for the |
| 43 | +`revs` struct. The revision walk should only be used to walk commits, and |
| 44 | +the objects will be walked in a separate way based on those starting |
| 45 | +commits. |
| 46 | ++ |
| 47 | +If you want the path-walk API to emit `UNINTERESTING` objects based on the |
| 48 | +commit walk's boundary, be sure to set `revs.boundary` so the boundary |
| 49 | +commits are emitted. |
| 50 | + |
| 51 | +`commits`, `blobs`, `trees`, `tags`:: |
| 52 | + By default, these members are enabled and signal that the path-walk |
| 53 | + API should call the `path_fn` on objects of these types. Specialized |
| 54 | + applications could disable some options to make it simpler to walk |
| 55 | + the objects or to have fewer calls to `path_fn`. |
| 56 | ++ |
| 57 | +While it is possible to walk only commits in this way, consumers would be |
| 58 | +better off using the revision walk API instead. |
| 59 | + |
| 60 | +`prune_all_uninteresting`:: |
| 61 | + By default, all reachable paths are emitted by the path-walk API. |
| 62 | + This option allows consumers to declare that they are not |
| 63 | + interested in paths where all included objects are marked with the |
| 64 | + `UNINTERESTING` flag. This requires using the `boundary` option in |
| 65 | + the revision walk so that the walk emits commits marked with the |
| 66 | + `UNINTERESTING` flag. |
| 67 | + |
| 68 | +Examples |
| 69 | +-------- |
| 70 | + |
| 71 | +See example usages in: |
| 72 | + `t/helper/test-path-walk.c`, |
| 73 | + `builtin/pack-objects.c` |
0 commit comments