Blame CONTRIBUTING.md

Packit 2997f0
# Contributing to librdkafka
Packit 2997f0
Packit 2997f0
(This document is based on [curl's CONTRIBUTE.md](https://github.com/curl/curl/blob/master/docs/CONTRIBUTE.md) - thank you!)
Packit 2997f0
Packit 2997f0
This document is intended to offer guidelines on how to best contribute to the
Packit 2997f0
librdkafka project. This concerns new features as well as bug fixes and
Packit 2997f0
general improvements.
Packit 2997f0
Packit 2997f0
### License and copyright
Packit 2997f0
Packit 2997f0
When contributing with code, you agree to put your changes and new code under
Packit 2997f0
the same license librdkafka is already using unless stated and agreed
Packit 2997f0
otherwise.
Packit 2997f0
Packit 2997f0
When changing existing source code, you do not alter the copyright of the
Packit 2997f0
original file(s). The copyright will still be owned by the original creator(s)
Packit 2997f0
or those who have been assigned copyright by the original author(s).
Packit 2997f0
Packit 2997f0
By submitting a patch to the librdkafka, you are assumed to have the right
Packit 2997f0
to the code and to be allowed by your employer or whatever to hand over that
Packit 2997f0
patch/code to us. We will credit you for your changes as far as possible, to
Packit 2997f0
give credit but also to keep a trace back to who made what changes. Please
Packit 2997f0
always provide us with your full real name when contributing!
Packit 2997f0
Packit 2997f0
Official librdkafka project maintainer(s) assume ownership of all accepted
Packit 2997f0
submissions.
Packit 2997f0
Packit 2997f0
## Write a good patch
Packit 2997f0
Packit 2997f0
### Follow code style
Packit 2997f0
Packit 2997f0
When writing C code, follow the code style already established in
Packit 2997f0
the project. Consistent style makes code easier to read and mistakes less
Packit 2997f0
likely to happen.
Packit 2997f0
Packit 2997f0
See the end of this document for the C style guide to use in librdkafka.
Packit 2997f0
Packit 2997f0
Packit 2997f0
### Write Separate Changes
Packit 2997f0
Packit 2997f0
It is annoying when you get a huge patch from someone that is said to fix 511
Packit 2997f0
odd problems, but discussions and opinions don't agree with 510 of them - or
Packit 2997f0
509 of them were already fixed in a different way. Then the person merging
Packit 2997f0
this change needs to extract the single interesting patch from somewhere
Packit 2997f0
within the huge pile of source, and that gives a lot of extra work.
Packit 2997f0
Packit 2997f0
Preferably, each fix that correct a problem should be in its own patch/commit
Packit 2997f0
with its own description/commit message stating exactly what they correct so
Packit 2997f0
that all changes can be selectively applied by the maintainer or other
Packit 2997f0
interested parties.
Packit 2997f0
Packit 2997f0
Also, separate changes enable bisecting much better when we track problems
Packit 2997f0
and regression in the future.
Packit 2997f0
Packit 2997f0
### Patch Against Recent Sources
Packit 2997f0
Packit 2997f0
Please try to make your patches against latest master branch.
Packit 2997f0
Packit 2997f0
### Test Cases
Packit 2997f0
Packit 2997f0
Bugfixes should also include a new test case in the regression test suite
Packit 2997f0
that verifies the bug is fixed.
Packit 2997f0
Create a new tests/00<freenumber>-<short_bug_description>.c file and
Packit 2997f0
try to reproduce the issue in its most simple form.
Packit 2997f0
Verify that the test case fails for earlier versions and passes with your
Packit 2997f0
bugfix in-place.
Packit 2997f0
Packit 2997f0
New features and APIs should also result in an added test case.
Packit 2997f0
Packit 2997f0
Submitted patches must pass all existing tests.
Packit 2997f0
For more information on the test suite see [tests/README]
Packit 2997f0
Packit 2997f0
Packit 2997f0
Packit 2997f0
## How to get your changes into the main sources
Packit 2997f0
Packit 2997f0
File a [pull request on github](https://github.com/edenhill/librdkafka/pulls)
Packit 2997f0
Packit 2997f0
Your change will be reviewed and discussed there and you will be
Packit 2997f0
expected to correct flaws pointed out and update accordingly, or the change
Packit 2997f0
risk stalling and eventually just get deleted without action. As a submitter
Packit 2997f0
of a change, you are the owner of that change until it has been merged.
Packit 2997f0
Packit 2997f0
Make sure to monitor your PR on github and answer questions and/or
Packit 2997f0
fix nits/flaws. This is very important. We will take lack of replies as a
Packit 2997f0
sign that you're not very anxious to get your patch accepted and we tend to
Packit 2997f0
simply drop such changes.
Packit 2997f0
Packit 2997f0
When you adjust your pull requests after review, please squash the
Packit 2997f0
commits so that we can review the full updated version more easily
Packit 2997f0
and keep history cleaner.
Packit 2997f0
Packit 2997f0
For example:
Packit 2997f0
Packit 2997f0
    # Interactive rebase to let you squash/fixup commits
Packit 2997f0
    $ git rebase -i master
Packit 2997f0
Packit 2997f0
    # Mark fixes-on-fixes commits as 'fixup' (or just 'f') in the
Packit 2997f0
    # first column. These will be silently integrated into the
Packit 2997f0
    # previous commit, so make sure to move the fixup-commit to
Packit 2997f0
    # the line beneath the parent commit.
Packit 2997f0
Packit 2997f0
    # Since this probably rewrote the history of previously pushed
Packit 2997f0
    # commits you will need to make a force push, which is usually
Packit 2997f0
    # a bad idea but works good for pull requests.
Packit 2997f0
    $ git push --force origin your_feature_branch
Packit 2997f0
Packit 2997f0
Packit 2997f0
### Write good commit messages
Packit 2997f0
Packit 2997f0
A short guide to how to write commit messages in the curl project.
Packit 2997f0
Packit 2997f0
    ---- start ----
Packit 2997f0
    [area]: [short line describing the main effect] [(#issuenumber)]
Packit 2997f0
           -- empty line --
Packit 2997f0
    [full description, no wider than 72 columns that describe as much as
Packit 2997f0
    possible as to why this change is made, and possibly what things
Packit 2997f0
    it fixes and everything else that is related]
Packit 2997f0
    ---- stop ----
Packit 2997f0
Packit 2997f0
Example:
Packit 2997f0
Packit 2997f0
    cgrp: restart query timer on all heartbeat failures (#10023)
Packit 2997f0
    
Packit 2997f0
    If unhandled errors were received in HeartbeatResponse
Packit 2997f0
    the cgrp could get stuck in a state where it would not
Packit 2997f0
    refresh its coordinator.
Packit 2997f0
Packit 2997f0
Packit 2997f0
Packit 2997f0
# librdkafka C style guide
Packit 2997f0
Packit 2997f0
## Function and globals naming
Packit 2997f0
Packit 2997f0
Use self-explanatory hierarchical snake-case naming.
Packit 2997f0
Pretty much all symbols should start with `rd_kafka_`, followed by
Packit 2997f0
their subsystem (e.g., `cgrp`, `broker`, `buf`, etc..), followed by an
Packit 2997f0
action (e.g, `find`, `get`, `clear`, ..).
Packit 2997f0
Packit 2997f0
Packit 2997f0
## Variable naming
Packit 2997f0
Packit 2997f0
For existing types use the type prefix as variable name.
Packit 2997f0
The type prefix is typically the first part of struct member fields.
Packit 2997f0
Example:
Packit 2997f0
Packit 2997f0
  * `rd_kafka_broker_t` has field names starting with `rkb_..`, thus broker
Packit 2997f0
     variable names should be named `rkb`
Packit 2997f0
Packit 2997f0
Packit 2997f0
For other types use reasonably concise but descriptive names.
Packit 2997f0
`i` and `j` are typical int iterators.
Packit 2997f0
Packit 2997f0
## Variable declaration
Packit 2997f0
Packit 2997f0
Variables must be declared at the head of a scope, no in-line variable
Packit 2997f0
declarations are allowed.
Packit 2997f0
Packit 2997f0
## Indenting
Packit 2997f0
Packit 2997f0
Use 8 spaces indent, same as the Linux kernel.
Packit 2997f0
In emacs, use `c-set-style "linux`.
Packit 2997f0
For C++, use Google's C++ style.
Packit 2997f0
Packit 2997f0
## Comments
Packit 2997f0
Packit 2997f0
Use `/* .. */` comments, not `// ..`
Packit 2997f0
Packit 2997f0
For functions, use doxygen syntax, e.g.:
Packit 2997f0
Packit 2997f0
    /**
Packit 2997f0
     * @brief <short description>
Packit 2997f0
     * ..
Packit 2997f0
     * @returns <something..>
Packit 2997f0
     */
Packit 2997f0
Packit 2997f0
Packit 2997f0
Make sure to comment non-obvious code and situations where the full
Packit 2997f0
context of an operation is not easily graspable.
Packit 2997f0
Packit 2997f0
Also make sure to update existing comments when the code changes.
Packit 2997f0
Packit 2997f0
Packit 2997f0
## Line length
Packit 2997f0
Packit 2997f0
Try hard to keep line length below 80 characters, when this is not possible
Packit 2997f0
exceed it with reason.
Packit 2997f0
Packit 2997f0
Packit 2997f0
## Braces
Packit 2997f0
Packit 2997f0
Braces go on the same line as their enveloping statement:
Packit 2997f0
Packit 2997f0
    int some_func (..) {
Packit 2997f0
      while (1) {
Packit 2997f0
        if (1) {
Packit 2997f0
          do something;
Packit 2997f0
          ..
Packit 2997f0
        } else {
Packit 2997f0
          do something else;
Packit 2997f0
          ..
Packit 2997f0
        }
Packit 2997f0
      }
Packit 2997f0
 
Packit 2997f0
      /* Single line scopes should not have braces */
Packit 2997f0
      if (1)
Packit 2997f0
        hi();
Packit 2997f0
      else if (2)
Packit 2997f0
        /* Say hello */
Packit 2997f0
        hello();
Packit 2997f0
      else
Packit 2997f0
        bye();
Packit 2997f0
Packit 2997f0
Packit 2997f0
## Spaces
Packit 2997f0
Packit 2997f0
All expression parentheses should be prefixed and suffixed with a single space:
Packit 2997f0
Packit 2997f0
    int some_func (int a) {
Packit 2997f0
Packit 2997f0
        if (1)
Packit 2997f0
          ....;
Packit 2997f0
Packit 2997f0
        for (i = 0 ; i < 19 ; i++) {
Packit 2997f0
Packit 2997f0
Packit 2997f0
        }
Packit 2997f0
    }
Packit 2997f0
Packit 2997f0
Packit 2997f0
Use space around operators:
Packit 2997f0
Packit 2997f0
    int a = 2;
Packit 2997f0
  
Packit 2997f0
    if (b >= 3)
Packit 2997f0
       c += 2;
Packit 2997f0
Packit 2997f0
Except for these:
Packit 2997f0
  
Packit 2997f0
    d++;
Packit 2997f0
    --e;
Packit 2997f0
Packit 2997f0
Packit 2997f0
## New block on new line
Packit 2997f0
Packit 2997f0
New blocks should be on a new line:
Packit 2997f0
Packit 2997f0
    if (1)
Packit 2997f0
      new();
Packit 2997f0
    else
Packit 2997f0
      old();
Packit 2997f0
Packit 2997f0
Packit 2997f0
## Parentheses
Packit 2997f0
Packit 2997f0
Don't assume the reader knows C operator precedence by heart for complex
Packit 2997f0
statements, add parentheses to ease readability.
Packit 2997f0
Packit 2997f0
Packit 2997f0
## ifdef hell
Packit 2997f0
Packit 2997f0
Avoid ifdef's as much as possible.
Packit 2997f0
Platform support checking should be performed in configure.librdkafka.
Packit 2997f0
Packit 2997f0
Packit 2997f0
Packit 2997f0
Packit 2997f0
Packit 2997f0
# librdkafka C++ style guide
Packit 2997f0
Packit 2997f0
Follow [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html)