Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f8cb02

Browse files
committed
CONVENTIONS: update to include general public API principles
1 parent 68ad315 commit 1f8cb02

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CONVENTIONS.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@
33
We like to keep the source consistent and readable. Herein are some
44
guidelines that should help with that.
55

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+
638
## Compatibility
739

840
`libgit2` runs on many different platforms with many different compilers.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Threading
8080

8181
See [THREADING](THREADING.md) for information
8282

83+
Conventions
84+
===========
85+
86+
See [CONVENTIONS](CONVENTIONS.md) for an overview of the external
87+
and internal API/coding conventions we use.
88+
8389
Building libgit2 - Using CMake
8490
==============================
8591

0 commit comments

Comments
 (0)