|
6 | 6 | #include "cache.h"
|
7 | 7 | #include "commit.h"
|
8 | 8 |
|
| 9 | +/* |
| 10 | + * builtin API |
| 11 | + * =========== |
| 12 | + * |
| 13 | + * Adding a new built-in |
| 14 | + * --------------------- |
| 15 | + * |
| 16 | + * There are 4 things to do to add a built-in command implementation to |
| 17 | + * Git: |
| 18 | + * |
| 19 | + * . Define the implementation of the built-in command `foo` with |
| 20 | + * signature: |
| 21 | + * |
| 22 | + * int cmd_foo(int argc, const char **argv, const char *prefix); |
| 23 | + * |
| 24 | + * . Add the external declaration for the function to `builtin.h`. |
| 25 | + * |
| 26 | + * . Add the command to the `commands[]` table defined in `git.c`. |
| 27 | + * The entry should look like: |
| 28 | + * |
| 29 | + * { "foo", cmd_foo, <options> }, |
| 30 | + * |
| 31 | + * where options is the bitwise-or of: |
| 32 | + * |
| 33 | + * `RUN_SETUP`: |
| 34 | + * If there is not a Git directory to work on, abort. If there |
| 35 | + * is a work tree, chdir to the top of it if the command was |
| 36 | + * invoked in a subdirectory. If there is no work tree, no |
| 37 | + * chdir() is done. |
| 38 | + * |
| 39 | + * `RUN_SETUP_GENTLY`: |
| 40 | + * If there is a Git directory, chdir as per RUN_SETUP, otherwise, |
| 41 | + * don't chdir anywhere. |
| 42 | + * |
| 43 | + * `USE_PAGER`: |
| 44 | + * |
| 45 | + * If the standard output is connected to a tty, spawn a pager and |
| 46 | + * feed our output to it. |
| 47 | + * |
| 48 | + * `NEED_WORK_TREE`: |
| 49 | + * |
| 50 | + * Make sure there is a work tree, i.e. the command cannot act |
| 51 | + * on bare repositories. |
| 52 | + * This only makes sense when `RUN_SETUP` is also set. |
| 53 | + * |
| 54 | + * `SUPPORT_SUPER_PREFIX`: |
| 55 | + * |
| 56 | + * The built-in supports `--super-prefix`. |
| 57 | + * |
| 58 | + * . Add `builtin/foo.o` to `BUILTIN_OBJS` in `Makefile`. |
| 59 | + * |
| 60 | + * Additionally, if `foo` is a new command, there are 4 more things to do: |
| 61 | + * |
| 62 | + * . Add tests to `t/` directory. |
| 63 | + * |
| 64 | + * . Write documentation in `Documentation/git-foo.txt`. |
| 65 | + * |
| 66 | + * . Add an entry for `git-foo` to `command-list.txt`. |
| 67 | + * |
| 68 | + * . Add an entry for `/git-foo` to `.gitignore`. |
| 69 | + * |
| 70 | + * |
| 71 | + * How a built-in is called |
| 72 | + * ------------------------ |
| 73 | + * |
| 74 | + * The implementation `cmd_foo()` takes three parameters, `argc`, `argv, |
| 75 | + * and `prefix`. The first two are similar to what `main()` of a |
| 76 | + * standalone command would be called with. |
| 77 | + * |
| 78 | + * When `RUN_SETUP` is specified in the `commands[]` table, and when you |
| 79 | + * were started from a subdirectory of the work tree, `cmd_foo()` is called |
| 80 | + * after chdir(2) to the top of the work tree, and `prefix` gets the path |
| 81 | + * to the subdirectory the command started from. This allows you to |
| 82 | + * convert a user-supplied pathname (typically relative to that directory) |
| 83 | + * to a pathname relative to the top of the work tree. |
| 84 | + * |
| 85 | + * The return value from `cmd_foo()` becomes the exit status of the |
| 86 | + * command. |
| 87 | + */ |
| 88 | + |
9 | 89 | #define DEFAULT_MERGE_LOG_LEN 20
|
10 | 90 |
|
11 | 91 | extern const char git_usage_string[];
|
|
0 commit comments