]> git.proxmox.com Git - libgit2.git/blame - CONVENTIONS
Merge branch 'repo-init' of https://github.com/nulltoken/libgit2 into nulltoken-repo...
[libgit2.git] / CONVENTIONS
CommitLineData
7335ffc3
SP
1libgit2 conventions
2===================
3
4Namespace Prefixes
5------------------
6
7All types and functions start with 'git_'.
8
9All #define macros start with 'GIT_'.
10
11
12Type Definitions
13----------------
14
6533aadc
SP
15Most types should be opaque, e.g.:
16
17----
18 typedef struct git_odb git_odb;
19----
20
21with allocation functions returning an "instance" created within
22the library, and not within the application. This allows the type
23to grow (or shrink) in size without rebuilding client code.
7335ffc3
SP
24
25
26Public Exported Function Definitions
27------------------------------------
28
29All exported functions must be declared as:
30
31----
32 GIT_EXTERN(result_type) git_modulename_functionname(arg_list);
33----
34
35
36Semi-Private Exported Functions
37-------------------------------
38
39Functions whose modulename is followed by two underscores,
40for example 'git_odb__read_packed', are semi-private functions.
41They are primarily intended for use within the library itself,
42and may disappear or change their signature in a future release.
43
44
45Calling Conventions
46-------------------
47
de2220a4
SP
48Functions should prefer to return a 'int' to indicate success or
49failure and supply any output through the first argument (or first
50few arguments if multiple outputs are supplied).
7335ffc3 51
de2220a4
SP
52int status codes are 0 for GIT_SUCCESS and < 0 for an error.
53This permits common POSIX result testing:
7335ffc3
SP
54
55----
56 if (git_odb_open(&odb, path))
57 abort("odb open failed");
58----
59
6dafd056
SP
60Functions returning a pointer may return NULL instead of an int
61if there is only one type of failure (ENOMEM).
62
63Functions returning a pointer may also return NULL if the common
64case needed by the application is strictly success/failure and a
65(possibly slower) function exists that the caller can use to get
66more detailed information. Parsing common data structures from
67on-disk formats is a good example of this pattern; in general a
68"corrupt" entity can be treated as though it does not exist but
69a more sophisticated "fsck" support function can report how the
70entity is malformed.
71
7335ffc3 72
0e7fa1fe
SP
73Documentation Fomatting
74-----------------------
75
76All comments should conform to Doxygen "javadoc" style conventions
77for formatting the public API documentation.
78
7335ffc3
SP
79
80Public Header Format
81--------------------
82
83All public headers defining types, functions or macros must use
84the following form, where ${filename} is the name of the file,
85after replacing non-identifier characters with '_'.
86
87----
d1ea30c3
SP
88 #ifndef INCLUDE_git_${filename}_h__
89 #define INCLUDE_git_${filename}_h__
7335ffc3 90
d1ea30c3 91 #include "git/common.h"
7335ffc3
SP
92
93 /**
d1ea30c3 94 * @file git/${filename}.h
7335ffc3 95 * @brief Git some description
d1ea30c3 96 * @defgroup git_${filename} some description routines
7335ffc3
SP
97 * @ingroup Git
98 * @{
99 */
100 GIT_BEGIN_DECL
101
102 ... definitions ...
103
104 /** @} */
105 GIT_END_DECL
106 #endif
107----