3 - Indentation in tabs, 8 characters wide, spaces after the tabs where
4 vertical alignment is required (see below)
6 **Note: this file uses spaces due to markdown rendering issues for tabs.
7 Code must be implemented using tabs.**
9 - Max line width 80ch, do not break up printed strings though
11 - Break up long lines at logical groupings, one line for each logical group
14 int a = somelongname() +
22 somelongfunctioncall(arg1,
27 - Function declarations: return type on separate line, {} on separate line,
28 arguments broken up as above.
38 somenamethatiswaytoolong(int a,
45 - `/* comments only */`, no `// comments`
47 - `variable_name`, not `VariableName` or `variableName`. same for functions.
49 - no typedefs of structs, enums, unions
51 - if it generates a compiler warning, it needs to be fixed
52 - if it generates a static checker warning, it needs to be fixed or
55 - declare variables when they are used first and try to keep them as local as possible.
56 Exception: basic loop variables, e.g. for (int i = 0; ...) should always be
57 declared inside the loop even where multiple loops exist
78 - avoid uninitialized variables where possible, declare them late instead.
79 Note that most of libinput predates this style, try to stick with the code
80 around you if in doubt.
102 - avoid calling non-obvious functions inside declaration blocks for multiple
110 int b = some_complicated_function();
121 int b = some_complicated_function();
125 There is a bit of gut-feeling involved with this, but the goal is to make
126 the variable values immediately recognizable.
128 - Where statements are near-identical and repeated, try to keep them
133 int a = get_some_value(x++);
135 a = get_some_value(x++);
137 a = get_some_value(x++);
144 a = = get_some_value(x++);
146 a = get_some_value(x++);
148 a = get_some_value(x++);
152 - if/else: { on the same line, no curly braces if both blocks are a single
153 statement. If either if or else block are multiple statements, both must
165 - public functions MUST be doxygen-commented, use doxygen's `@foo` rather than
168 - `#include "config.h"` comes first, followed by system headers, followed by
169 external library headers, followed by internal headers.
170 sort alphabetically where it makes sense (specifically system headers)
178 #include <libevdev/libevdev.h>
180 #include "libinput-private.h"
183 - goto jumps only to the end of the function, and only for good reasons
184 (usually cleanup). goto never jumps backwards
186 - Use stdbool.h's bool for booleans within the library (instead of `int`).
187 Exception: the public API uses int, not bool.
189 # Git commit message requirements
191 Our CI will check the commit messages for a few requirements. Below is the
192 list of what we expect from a git commit.
194 ## Commit message content
196 A [good commit message](http://who-t.blogspot.com/2009/12/on-commit-messages.html) needs to
197 answer three questions:
199 - Why is it necessary? It may fix a bug, it may add a feature, it may
200 improve performance, reliabilty, stability, or just be a change for the
202 - How does it address the issue? For short obvious patches this part can be
203 omitted, but it should be a high level description of what the approach
205 - What effects does the patch have? (In addition to the obvious ones, this
206 may include benchmarks, side effects, etc.)
208 These three questions establish the context for the actual code changes, put
209 reviewers and others into the frame of mind to look at the diff and check if
210 the approach chosen was correct. A good commit message also helps
211 maintainers to decide if a given patch is suitable for stable branches or
212 inclusion in a distribution.
214 ## Developer Certificate of Origin
216 Your commit **must** be signed off with a line:
218 Signed-off-by: <your name> <your email address>
220 By signing off, you indicate the [developer certificate of origin](https://developercertificate.org/).
222 > By making a contribution to this project, I certify that:
224 > (a) The contribution was created in whole or in part by me and I
225 > have the right to submit it under the open source license
226 > indicated in the file; or
228 > (b) The contribution is based upon previous work that, to the best
229 > of my knowledge, is covered under an appropriate open source
230 > license and I have the right under that license to submit that
231 > work with modifications, whether created in whole or in part
232 > by me, under the same open source license (unless I am
233 > permitted to submit under a different license), as indicated
236 > (c) The contribution was provided directly to me by some other
237 > person who certified (a), (b) or (c) and I have not modified
240 > (d) I understand and agree that this project and the contribution
241 > are public and that a record of the contribution (including all
242 > personal information I submit with it, including my sign-off) is
243 > maintained indefinitely and may be redistributed consistent with
244 > this project or the open source license(s) involved.
246 ## Commit message format
248 The canonical git commit message format is:
251 one line as the subject line with a high-level note
253 full explanation of the patch follows after an empty line. This explanation
254 can be multiple paragraphs and is largely free-form. Markdown is not
257 You can include extra data where required like:
258 - benchmark one says 10s
259 - benchmark two says 12s
261 Signed-off-by: <your name> <your email>
264 The subject line is the first thing everyone sees about this commit, so make
267 ## Commit message technical requirements
269 - The commit message should use present tense (not past tense). Do write
270 "change foo to bar", not "changed foo to bar".
271 - The text width of the commit should be 78 chars or less, especially the
273 - The author and signed-off-by must be your real name and email address. We
274 do not accept the default `@users.noreply` gitlab addresses.
276 git config --global user.name Your Name
277 git config --global user.email your@email