PATH:
usr
/
share
/
doc
/
git-1.8.3.1
/
technical
builtin API =========== Adding a new built-in --------------------- There are 4 things to do to add a built-in command implementation to Git: . Define the implementation of the built-in command `foo` with signature: int cmd_foo(int argc, const char **argv, const char *prefix); . Add the external declaration for the function to `builtin.h`. . Add the command to `commands[]` table in `handle_internal_command()`, defined in `git.c`. The entry should look like: { "foo", cmd_foo, <options> }, + where options is the bitwise-or of: `RUN_SETUP`:: Make sure there is a Git directory to work on, and if there is a work tree, chdir to the top of it if the command was invoked in a subdirectory. If there is no work tree, no chdir() is done. `USE_PAGER`:: If the standard output is connected to a tty, spawn a pager and feed our output to it. `NEED_WORK_TREE`:: Make sure there is a work tree, i.e. the command cannot act on bare repositories. This only makes sense when `RUN_SETUP` is also set. . Add `builtin-foo.o` to `BUILTIN_OBJS` in `Makefile`. Additionally, if `foo` is a new command, there are 3 more things to do: . Add tests to `t/` directory. . Write documentation in `Documentation/git-foo.txt`. . Add an entry for `git-foo` to `command-list.txt`. . Add an entry for `/git-foo` to `.gitignore`. How a built-in is called ------------------------ The implementation `cmd_foo()` takes three parameters, `argc`, `argv, and `prefix`. The first two are similar to what `main()` of a standalone command would be called with. When `RUN_SETUP` is specified in the `commands[]` table, and when you were started from a subdirectory of the work tree, `cmd_foo()` is called after chdir(2) to the top of the work tree, and `prefix` gets the path to the subdirectory the command started from. This allows you to convert a user-supplied pathname (typically relative to that directory) to a pathname relative to the top of the work tree. The return value from `cmd_foo()` becomes the exit status of the command.
[-] api-strbuf.html
[edit]
[-] api-credentials.txt
[edit]
[-] shallow.txt
[edit]
[-] api-sigchain.html
[edit]
[-] racy-git.html
[edit]
[-] api-allocation-growing.txt
[edit]
[-] api-tree-walking.html
[edit]
[-] index-format.txt
[edit]
[-] pack-protocol.html
[edit]
[-] api-setup.txt
[edit]
[-] api-lockfile.html
[edit]
[-] api-directory-listing.txt
[edit]
[-] api-remote.txt
[edit]
[-] pack-format.html
[edit]
[-] api-quote.txt
[edit]
[-] index-format.html
[edit]
[-] api-in-core-index.txt
[edit]
[-] api-hash.txt
[edit]
[-] send-pack-pipeline.html
[edit]
[-] api-strbuf.txt
[edit]
[+]
..
[-] protocol-common.html
[edit]
[-] pack-heuristics.html
[edit]
[-] api-sha1-array.html
[edit]
[-] api-xdiff-interface.html
[edit]
[-] api-xdiff-interface.txt
[edit]
[-] api-hashmap.html
[edit]
[-] api-ref-iteration.txt
[edit]
[-] trivial-merge.html
[edit]
[-] api-gitattributes.txt
[edit]
[-] pack-format.txt
[edit]
[-] api-run-command.txt
[edit]
[-] api-parse-options.html
[edit]
[-] api-ref-iteration.html
[edit]
[-] trivial-merge.txt
[edit]
[-] api-decorate.txt
[edit]
[-] api-builtin.txt
[edit]
[-] api-directory-listing.html
[edit]
[-] pack-protocol.txt
[edit]
[-] api-hash.html
[edit]
[-] api-quote.html
[edit]
[-] api-setup.html
[edit]
[-] api-argv-array.html
[edit]
[-] api-remote.html
[edit]
[-] api-grep.txt
[edit]
[-] protocol-capabilities.txt
[edit]
[-] api-revision-walking.html
[edit]
[-] api-string-list.txt
[edit]
[-] api-history-graph.txt
[edit]
[-] api-diff.html
[edit]
[-] protocol-common.txt
[edit]
[-] api-sigchain.txt
[edit]
[-] api-gitattributes.html
[edit]
[-] api-grep.html
[edit]
[-] api-history-graph.html
[edit]
[-] api-lockfile.txt
[edit]
[-] api-index.txt
[edit]
[-] api-revision-walking.txt
[edit]
[-] api-sha1-array.txt
[edit]
[-] api-string-list.html
[edit]
[-] api-object-access.txt
[edit]
[-] api-hashmap.txt
[edit]
[-] protocol-capabilities.html
[edit]
[-] api-object-access.html
[edit]
[-] pack-heuristics.txt
[edit]
[-] shallow.html
[edit]
[-] api-run-command.html
[edit]
[-] racy-git.txt
[edit]
[-] api-merge.html
[edit]
[-] api-index-skel.txt
[edit]
[-] api-tree-walking.txt
[edit]
[-] send-pack-pipeline.txt
[edit]
[-] api-in-core-index.html
[edit]
[-] api-diff.txt
[edit]
[-] api-index.html
[edit]
[-] api-credentials.html
[edit]
[-] api-builtin.html
[edit]
[-] api-allocation-growing.html
[edit]
[-] api-merge.txt
[edit]
[-] api-parse-options.txt
[edit]
[-] api-config.html
[edit]
[-] api-decorate.html
[edit]
[-] api-index.sh
[edit]
[-] api-argv-array.txt
[edit]
[-] api-config.txt
[edit]