|
3 | 3 | We like to keep the source consistent and readable. Herein are some
|
4 | 4 | guidelines that should help with that.
|
5 | 5 |
|
| 6 | +## External API |
| 7 | + |
| 8 | +We have a few rules to avoid surprising ways of calling functions and |
| 9 | +some rules for consumers of the library to avoid stepping on each |
| 10 | +other's toes. |
| 11 | + |
| 12 | + - Property accessors return the value directly (e.g. an `int` or |
| 13 | + `const char *`) but if a function can fail, we return a `int` value |
| 14 | + and the output parameters go first in the parameter list, followed |
| 15 | + by the object that a function is operating on, and then any other |
| 16 | + arguments the function may need. |
| 17 | + |
| 18 | + - If a function returns an object as a return value, that function is |
| 19 | + a getter and the object's lifetime is tied to the parent |
| 20 | + object. Objects which are returned as the first argument as a |
| 21 | + pointer-to-pointer are owned by the caller and it is repsponsible |
| 22 | + for freeing it. Strings are returned via `git_buf` in order to |
| 23 | + allow for re-use and safe freeing. |
| 24 | + |
| 25 | + - Most of what libgit2 does relates to I/O so you as a general rule |
| 26 | + you should assume that any function can fail due to errors as even |
| 27 | + getting data from the filesystem can result in all sorts of errors |
| 28 | + and complex failure cases. |
| 29 | + |
| 30 | + - Paths inside the Git system are separated by a slash (0x2F). If a |
| 31 | + function accepts a path on disk, then backslashes (0x5C) are also |
| 32 | + accepted on Windows. |
| 33 | + |
| 34 | + - Do not mix allocators. If something has been allocated by libgit2, |
| 35 | + you do not know which is the right free function in the general |
| 36 | + case. Use the free functions provided for each object type. |
| 37 | + |
6 | 38 | ## Compatibility
|
7 | 39 |
|
8 | 40 | `libgit2` runs on many different platforms with many different compilers.
|
|
0 commit comments