Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 1 | .. _chapter-contributing: |
| 2 | |
| 3 | ============ |
| 4 | Contributing |
| 5 | ============ |
| 6 | |
| 7 | We welcome contributions to Ceres, whether they are new features, bug |
| 8 | fixes or tests. The Ceres `mailing |
| 9 | <http://groups.google.com/group/ceres-solver>`_ list is the best place |
| 10 | for all development related discussions. Please consider joining |
| 11 | it. If you have ideas on how you would like to contribute to Ceres, it |
| 12 | is a good idea to let us know on the mailing list before you start |
| 13 | development. We may have suggestions that will save effort when trying |
| 14 | to merge your work into the main branch. If you are looking for ideas, |
| 15 | please let us know about your interest and skills and we will be happy |
| 16 | to make a suggestion or three. |
| 17 | |
| 18 | We follow Google's `C++ Style Guide |
| 19 | <https://google.github.io/styleguide/cppguide.html>`_ and |
| 20 | use `git <http://git-scm.com/>`_ for version control. We use the |
| 21 | `Gerrit <https://ceres-solver-review.googlesource.com/>`_ to collaborate and |
| 22 | review changes to Ceres. Gerrit enables pre-commit reviews so that |
| 23 | Ceres can maintain a linear history with clean, reviewed commits, and |
| 24 | no merges. |
| 25 | |
| 26 | We now describe how to set up your development environment and submit |
| 27 | a change list for review via Gerrit. |
| 28 | |
| 29 | Setting up your Environment |
| 30 | =========================== |
| 31 | |
| 32 | 1. Download and configure ``git``. |
| 33 | |
| 34 | * Mac ``brew install git``. |
| 35 | * Linux ``sudo apt-get install git``. |
| 36 | * Windows. Download `msysgit |
| 37 | <https://code.google.com/p/msysgit/>`_, which includes a minimal |
| 38 | `Cygwin <http://www.cygwin.com/>`_ install. |
| 39 | |
| 40 | 2. Sign up for `Gerrit |
| 41 | <https://ceres-solver-review.googlesource.com/>`_. You will also need to |
| 42 | `sign the Contributor License Agreement (CLA) |
| 43 | <https://opensource.google.com/docs/cla/#sign>`_ with Google, which gives |
| 44 | Google a royalty-free unlimited license to use your contributions. You |
| 45 | retain copyright. |
| 46 | |
| 47 | 3. Clone the Ceres Solver ``git`` repository from Gerrit. |
| 48 | |
| 49 | .. code-block:: bash |
| 50 | |
| 51 | git clone https://ceres-solver.googlesource.com/ceres-solver |
| 52 | |
| 53 | |
| 54 | 4. Build Ceres, following the instructions in |
| 55 | :ref:`chapter-installation`. |
| 56 | |
| 57 | On Mac and Linux, the ``CMake`` build will download and enable |
| 58 | the Gerrit pre-commit hook automatically. This pre-submit hook |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 59 | creates ``Change-Id: ...`` lines in your commits. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 60 | |
| 61 | If this does not work OR you are on Windows, execute the |
| 62 | following in the root directory of the local ``git`` repository: |
| 63 | |
| 64 | .. code-block:: bash |
| 65 | |
| 66 | curl -o .git/hooks/commit-msg https://ceres-solver-review.googlesource.com/tools/hooks/commit-msg |
| 67 | chmod +x .git/hooks/commit-msg |
| 68 | |
| 69 | 5. Configure your Gerrit password with a ``.gitcookies`` which allows pushing |
| 70 | to Gerrit without having to enter a very long random password every time: |
| 71 | |
| 72 | * Sign into `http://ceres-solver-review.googlesource.com |
| 73 | <http://ceres-solver-review.googlesource.com>`_. |
| 74 | |
| 75 | * Click ``Settings -> HTTP Credentials -> Obtain Password``. |
| 76 | |
| 77 | * (maybe) Select an account for multi-login. This should be the |
| 78 | same as your Gerrit login. |
| 79 | |
| 80 | * Click ``Allow access`` when the page requests access to your |
| 81 | ``git`` repositories. |
| 82 | |
| 83 | * Follow the instructions from Gerrit to create a ``.gitcookies`` file on |
| 84 | your system, either in ``$HOME/.gitcookies`` (Mac and Linux) or |
| 85 | ``%USERPROFILE%\.gitcookies`` (Windows). Note that for Windows, please get |
| 86 | a recent `Git for Windows <https://git-scm.com/download/win>`_ install to |
| 87 | enable automatic lookup in the ``%USERPROFILE%\.gitcookies``. |
| 88 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 89 | 6. Install ``clang-format``. |
| 90 | |
| 91 | * Mac ``brew install clang-format``. |
| 92 | * Linux ``sudo apt-get install clang-format``. |
| 93 | * Windows. You can get clang-format with `clang or stand-alone via |
| 94 | npm <https://superuser.com/a/1505297/1141693>`_. |
| 95 | |
| 96 | You can ensure all sources files are correctly formatted before |
| 97 | committing by manually running ``clang-format -i FILENAME``, by |
| 98 | running the script ``./scripts/format_all.sh``, or by configuring |
| 99 | your editor to format upon saving. |
| 100 | |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 101 | Submitting a change |
| 102 | =================== |
| 103 | |
| 104 | 1. Make your changes against master or whatever branch you |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 105 | like. Ensure that the changes are formatted according to |
| 106 | ``clang-format``. Commit your changes as one patch. When you |
| 107 | commit, the Gerrit hook will add a ``Change-Id:`` line as the last |
| 108 | line of the commit. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 109 | |
| 110 | Make sure that your commit message is formatted in the `50/72 style |
| 111 | <http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`_. |
| 112 | |
| 113 | 2. Push your changes to the Ceres Gerrit instance: |
| 114 | |
| 115 | .. code-block:: bash |
| 116 | |
| 117 | git push origin HEAD:refs/for/master |
| 118 | |
| 119 | When the push succeeds, the console will display a URL showing the |
| 120 | address of the review. Go to the URL and add at least one of the |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 121 | maintainers (Sameer Agarwal, Keir Mierle, Alex Stewart, William |
| 122 | Rucklidge or Sergiu Deitsch) as reviewers. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 123 | |
| 124 | 3. Wait for a review. |
| 125 | |
| 126 | 4. Once review comments come in, address them. Please reply to each |
| 127 | comment in Gerrit, which makes the re-review process easier. After |
| 128 | modifying the code in your ``git`` instance, *don't make a new |
| 129 | commit*. Instead, update the last commit using a command like the |
| 130 | following: |
| 131 | |
| 132 | .. code-block:: bash |
| 133 | |
| 134 | git commit --amend -a |
| 135 | |
| 136 | This will update the last commit, so that it has both the original |
| 137 | patch and your updates as a single commit. You will have a chance |
| 138 | to edit the commit message as well. Push the new commit to Gerrit |
| 139 | as before. |
| 140 | |
| 141 | Gerrit will use the ``Change-Id:`` to match the previous commit |
| 142 | with the new one. The review interface retains your original patch, |
| 143 | but also shows the new patch. |
| 144 | |
| 145 | Publish your responses to the comments, and wait for a new round |
| 146 | of reviews. |