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