Skip to content

Commit ec14d4e

Browse files
Martin Ågrengitster
authored andcommitted
builtin.h: take over documentation from api-builtin.txt
Delete Documentation/technical/api-builtin.txt and move its content into builtin.h. Format it as a comment. Remove a '+' which was needed when the information was formatted for AsciiDoc. Similarly, change "::" to ":". Document SUPPORT_SUPER_PREFIX, thereby bringing the documentation up to date with the available flags. While at it, correct '3 more things to do' to '4 more things to do'. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 384a8b2 commit ec14d4e

File tree

2 files changed

+80
-73
lines changed

2 files changed

+80
-73
lines changed

Documentation/technical/api-builtin.txt

Lines changed: 0 additions & 73 deletions
This file was deleted.

builtin.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,86 @@
66
#include "cache.h"
77
#include "commit.h"
88

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+
989
#define DEFAULT_MERGE_LOG_LEN 20
1090

1191
extern const char git_usage_string[];

0 commit comments

Comments
 (0)