*`uncrustify-fix-style.sh` will accept a space-delimited list of files as its argument. Thus, you can auto-format an entire directory by running something like this:
``./tools/code-style/uncrustify-fix-style.sh `find cpu/cc2538 -type f -name "*.[ch]"` ``
This is _not_ a silver bullet and developer intervention is still required. Below are some examples of code which will get misformatted by uncrustify:
* Math symbol following a cast to a typedef
```
a = (uint8_t) ~P0_1; /* Cast to a typedef. Space gets added here (incorrect) */
a = (int)~P0_1; /* Cast to a known type. Space gets removed (correct) */
a = (uint8_t)P0_1; /* Variable directly after the cast. Space gets removed (correct) */
```
*`while(<condition>);` will become `while(<condition>) ;` (space incorrectly added after closing paren)
*`asm("wfi");` becomes `asm ("wfi");`: A space gets added before the opening paren, because the `asm` keyword stops this from getting interpreted as a normal function call / macro invocation. This is only a problem with `asm`. For instance, `foo("bar");` gets formatted correctly.
Naming
------
We require that all code contributed to the Contiki tree follow the
Contiki source code naming standard:
* File names are composed of lower-case characters and dashes. Like
this: simple-udp.c
* Variable and function names are composed of lower-case characters
and underscores. Like this: simple_udp_send();
* Variable and function names that are visible outside of their module
must begin with the name of the module. Like this:
simple_udp_send(), which is in the simple-udp module, declared in
simple-udp.h, and implemented in simple-udp.c.
* C macros are composed of upper-case characters and underscores. Like
this: PROCESS_THREAD().
* Configuration definitions begin with the module name and CONF_. Like
this: PROCESS_CONF_NUMEVENTS.
How to Contribute Code
----------------------
When your code is formatted according to the Contiki code style and
follows the Contiki naming standard, it is time to send it to the
Contiki maintainers to look at!
All code contributions to Contiki are submitted as [Github pull
* Create a new branch for your modifications. This branch should be based on the latest contiki master branch.
* If you already added the commits to another branch you can [cherry-pick](http://git-scm.com/docs/git-cherry-pick) them onto your new branch.
* Push the new branch to github.
* Raise the new Pull Requests on this new branch. Raising a Pull Request for the master branch is almost always a bad idea.
* If changes are requested do not close the pull request but rewrite your history. [Details about rewriting your history](http://git-scm.com/book/en/Git-Tools-Rewriting-History)
* You now force-push the changes to github. The pull-request is automatically updated.
In Git terminology this is equivalent to:
* Make sure you have the original contiki repo as origin.
* Add your work. For example by cherry-picking your changes from another branch.
```bash
$ git cherry-pick <HASHOFCOMMIT>
```
* Push to _your_ github repository
```bash
$ git push origin my_new_feature
```
* Make a Pull Request for that branch
* Rewrite your history if requested
```bash
$ git rebase -i contiki-orig/master
```
* As rewriting your history can break things you must force-push the changes. **Warning**: Force-pushing normally is dangerous and you might break things. Make sure you are never force-pushing branches other people are supposed to work with.
```bash
$ git push origin my_new_feature -f
```
* NOTE: To avoid all the pain of selectively picking commits, rebasing and force-pushing - begin your development with a branch OTHER THAN your master branch, and push changes to that branch after any local commits.
Pull requests (PRs) are reviewed by the [merge team](https://github.com/orgs/contiki-os/people).
Generally, PRs require two "+1" before they can be merged by someone on the merge team.
The since Contiki 3.0, the merging policy is the following:
* The PR receives **one "-1"** from a merge team member (along with specific feedback). The PR is closed. A "-1" must be accompanied with a clear explanation why the PR will not be considered for inclusion.
* The PR receives **two "+1"** from merge team members. The PR is merged.
* The PR was inactive for **two months**. A team member may either:
* Comment "Is there any interest for this PR? Is there any work pending on it? If not I will close it in **one month**." Back to initial state in case of activity, close otherwise.
* Comment "I approve this PR. If nobody disapproves within **one month**, I will merge it." Back to initial state in case of activity, merge otherwise.
There is an exception to the rule.
Code that requires esoteric expertise such as some applications, platforms or tools can be merged after a single "+1" from its domain expert.