blob: a128e3020d309a0abc74ae080f849b09e7667ba9 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001.. _chapter-contributing:
2
3============
4Contributing
5============
6
7We welcome contributions to Ceres, whether they are new features, bug
8fixes or tests. The Ceres `mailing
9<http://groups.google.com/group/ceres-solver>`_ list is the best place
10for all development related discussions. Please consider joining
11it. If you have ideas on how you would like to contribute to Ceres, it
12is a good idea to let us know on the mailing list before you start
13development. We may have suggestions that will save effort when trying
14to merge your work into the main branch. If you are looking for ideas,
15please let us know about your interest and skills and we will be happy
16to make a suggestion or three.
17
18We follow Google's `C++ Style Guide
19<https://google.github.io/styleguide/cppguide.html>`_ and
20use `git <http://git-scm.com/>`_ for version control. We use the
21`Gerrit <https://ceres-solver-review.googlesource.com/>`_ to collaborate and
22review changes to Ceres. Gerrit enables pre-commit reviews so that
23Ceres can maintain a linear history with clean, reviewed commits, and
24no merges.
25
26We now describe how to set up your development environment and submit
27a change list for review via Gerrit.
28
29Setting up your Environment
30===========================
31
321. 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
402. 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
473. 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
544. 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 Schuh1d1e6ea2020-12-23 21:56:30 -080059 creates ``Change-Id: ...`` lines in your commits.
Austin Schuh70cc9552019-01-21 19:46:48 -080060
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
695. 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 Schuh1d1e6ea2020-12-23 21:56:30 -0800896. 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 Schuh70cc9552019-01-21 19:46:48 -0800101Submitting a change
102===================
103
1041. Make your changes against master or whatever branch you
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800105 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 Schuh70cc9552019-01-21 19:46:48 -0800109
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
1132. 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
121 maintainers (Sameer Agarwal, Keir Mierle, Alex Stewart or William
122 Rucklidge) as reviewers.
123
1243. Wait for a review.
125
1264. 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.