blob: 4ebdead6d95cc33bba71a0e4f0305d0a442c88d6 [file] [log] [blame] [view]
brettw40e953e2017-02-08 17:49:281# Code Reviews
2
3Code reviews are a central part of developing high-quality code for Chromium.
4All changes must be reviewed.
5
6The bigger patch-upload-and-land process is covered in more detail the
7[contributing code](https://www.chromium.org/developers/contributing-code)
8page.
9
10# Code review policies
11
12Ideally the reviewer is someone who is familiar with the area of code you are
brettw2019b9e2017-02-09 06:40:2013touching. Any committer can review code, but an owner must provide a review
14for each directory you are touching. If you have doubts, look at the git blame
15for the file and the `OWNERS` files (see below).
brettw40e953e2017-02-08 17:49:2816
Michael Giuffridaaf367052018-03-22 20:22:3417To indicate a positive review, the reviewer provides a "Code-Review +1" in
18Gerrit, also known as an LGTM ("Looks Good To Me"). A score of "-1" indicates
19the change should not be submitted as-is.
brettw40e953e2017-02-08 17:49:2820
Michael Giuffridaaf367052018-03-22 20:22:3421If you have multiple reviewers, provide a message indicating what you expect
22from each reviewer. Otherwise people might assume their input is not required
23or waste time with redundant reviews.
brettw2019b9e2017-02-09 06:40:2024
Annie Sullivand04212e72017-10-19 21:11:3225Please also read [Respectful Changes](cl_respect.md) and
26[Respectful Code Reviews](cr_respect.md).
27
brettw2019b9e2017-02-09 06:40:2028#### Expectations for all reviewers
brettw40e953e2017-02-08 17:49:2829
30 * Aim to provide some kind of actionable response within 24 hours of receipt
Michael Giuffridaaf367052018-03-22 20:22:3431 (not counting weekends and holidays). This doesn't mean you have to do a
32 complete review, but you should be able to give some initial feedback,
33 request more time, or suggest another reviewer.
brettw40e953e2017-02-08 17:49:2834
Michael Giuffridaaf367052018-03-22 20:22:3435 * Use the status field in Gerrit settings to indicate if you're away and when
Mike Frysinger7b15bde2018-05-15 09:28:0536 you'll be back.
brettw40e953e2017-02-08 17:49:2837
38 * Don't generally discourage people from sending you code reviews. This
Michael Giuffridaaf367052018-03-22 20:22:3439 includes using a blanket "slow" in your status field.
brettw40e953e2017-02-08 17:49:2840
41## OWNERS files
42
brettw2019b9e2017-02-09 06:40:2043In various directories there are files named `OWNERS` that list the email
brettw40e953e2017-02-08 17:49:2844addresses of people qualified to review changes in that directory. You must
45get a positive review from an owner of each directory your change touches.
46
brettw2019b9e2017-02-09 06:40:2047Owners files are recursive, so each file also applies to its subdirectories.
48It's generally best to pick more specific owners. People listed in higher-level
thestig9208d8ba2017-06-09 22:05:3249directories may have less experience with the code in question. For example,
50the reviewers in the `//chrome/browser/component_name/OWNERS` file will likely
51be more familiar with code in `//chrome/browser/component_name/sub_component`
52than reviewers in the higher-level `//chrome/OWNERS` file.
53
54More detail on the owners file format is provided in the "More information"
55section below.
brettw40e953e2017-02-08 17:49:2856
brettw2019b9e2017-02-09 06:40:2057*Tip:* The `git cl owners` command can help find owners.
brettw40e953e2017-02-08 17:49:2858
59While owners must approve all patches, any committer can contribute to the
60review. In some directories the owners can be overloaded or there might be
61people not listed as owners who are more familiar with the low-level code in
62question. In these cases it's common to request a low-level review from an
63appropriate person, and then request a high-level owner review once that's
64complete. As always, be clear what you expect of each reviewer to avoid
65duplicated work.
66
brettw2019b9e2017-02-09 06:40:2067Owners do not have to pick other owners for reviews. Since they should already
68be familiar with the code in question, a thorough review from any appropriate
69committer is sufficient.
brettw40e953e2017-02-08 17:49:2870
brettw2019b9e2017-02-09 06:40:2071#### Expectations of owners
72
73The existing owners of a directory approve additions to the list. It is
Wei-Yin Chen (陳威尹)681bc322017-07-20 01:55:1174preferable to have many directories, each with a smaller number of specific
Dirk Pranke4f9740c2018-10-17 03:01:0675owners rather than large directories with many owners. Owners should:
brettw2019b9e2017-02-09 06:40:2076
77 * Demonstrate excellent judgment, teamwork and ability to uphold Chrome
78 development principles.
79
80 * Be already acting as an owner, providing high-quality reviews and design
Dirk Pranke4f9740c2018-10-17 03:01:0681 feedback.
brettw2019b9e2017-02-09 06:40:2082
Dirk Pranke4f9740c2018-10-17 03:01:0683 * Be a Chromium project member with full commit access of at least three
brettw2019b9e2017-02-09 06:40:2084 months tenure.
85
86 * Have submitted a substantial number of non-trivial changes to the affected
brettw40e953e2017-02-08 17:49:2887 directory.
88
brettw2019b9e2017-02-09 06:40:2089 * Have committed or reviewed substantial work to the affected directory
Dirk Pranke4f9740c2018-10-17 03:01:0690 within the last ninety days.
brettw40e953e2017-02-08 17:49:2891
brettw2019b9e2017-02-09 06:40:2092 * Have the bandwidth to contribute to reviews in a timely manner. If the load
93 is unsustainable, work to expand the number of owners. Don't try to
94 discourage people from sending reviews, including writing "slow" or
95 "emeritus" after your name.
96
Dirk Pranke4f9740c2018-10-17 03:01:0697The above are guidelines more than they are hard rules, and exceptions are
98okay as long as there is a consensus by the existing owners for them.
99For example, seldom-updated directories may have exceptions to the
100"substantiality" and "recency" requirements. Directories in `third_party`
101should list those most familiar with the library, regardless of how often
102the code is updated.
brettw40e953e2017-02-08 17:49:28103
brettw2019b9e2017-02-09 06:40:20104### OWNERS file details
105
106Refer to the [source code](https://chromium.googlesource.com/chromium/tools/depot_tools/+/master/owners.py)
thestig9208d8ba2017-06-09 22:05:32107for all details on the file format.
brettw2019b9e2017-02-09 06:40:20108
109This example indicates that two people are owners, in addition to any owners
110from the parent directory. `git cl owners` will list the comment after an
111owner address, so this is a good place to include restrictions or special
112instructions.
113```
114# You can include comments like this.
115[email protected]
116[email protected] # Only for the frobinator.
117```
118
119A `*` indicates that all committers are owners:
120```
121*
122```
123
brettwd040b0be2017-02-09 19:11:33124The text `set noparent` will stop owner propagation from parent directories.
Jochen Eisingerea8f92d82017-08-02 17:40:14125This should be rarely used. If you want to use `set noparent` except for IPC
126related files, please first reach out to [email protected].
127
128In this example, only the two listed people are owners:
brettw2019b9e2017-02-09 06:40:20129```
130set noparent
131[email protected]
132[email protected]
133```
134
135The `per-file` directive allows owners to be added that apply only to files
Wei-Yin Chen (陳威尹)681bc322017-07-20 01:55:11136matching a pattern. In this example, owners from the parent directory
brettw2019b9e2017-02-09 06:40:20137apply, plus one person for some classes of files, and all committers are
138owners for the readme:
139```
140per-file [email protected]
141per-file foo.*[email protected]
142
143per-file readme.txt=*
144```
145
George Burgess IV1ef04932018-01-27 07:04:04146Note that `per-file` directives cannot directly specify subdirectories, e.g:
147```
148per-file foo/[email protected]
149```
150
151is not OK; instead, place a `per-file` directive in `foo/OWNERS`.
152
brettw2019b9e2017-02-09 06:40:20153Other `OWNERS` files can be included by reference by listing the path to the
154file with `file://...`. This example indicates that only the people listed in
155`//ipc/SECURITY_OWNERS` can review the messages files:
156```
157per-file *_messages*.h=set noparent
158per-file *_messages*.h=file://ipc/SECURITY_OWNERS
159```
Steve Kobesf885edf2018-09-11 13:41:11160
161## TBR ("To Be Reviewed")
162
163"TBR" is our mechanism for post-commit review. It should be used rarely and
164only in cases where a normal review is unnecessary, as described under
165"When to TBR", below.
166
167TBR does not mean "no review." A reviewer TBR-ed on a change should still
168review the change. If there are comments after landing, the author is obligated
169to address them in a followup patch.
170
171Do not use TBR just because a change is urgent or the reviewer is being slow.
172Contact the reviewer directly or find somebody else to review your change.
173
174### How to TBR
175
176To send a change TBR, annotate the description and send email like normal.
177Otherwise the reviewer won't know to review the patch.
178
179 * Add the reviewer's email address in the code review tool's reviewer field
180 like normal.
181
182 * Add a line "TBR=<reviewer's email>" to the bottom of the change list
183 description. e.g. `[email protected],[email protected]`
184
185 * Type a message so that the owners in the TBR list can understand who is
186 responsible for reviewing what, as part of their post-commit review
187 responsibility. e.g.
188 ```
189 TBRing reviewers:
190 reviewer1: Please review changes to foo/
191 reviewer2: Please review changes to bar/
192 ```
193
194### When to TBR
195
196#### Reverts and relands
197
198The most common use of TBR is to revert patches that broke the build. Clean
199reverts of recent patches may be submitted TBR. However, TBR should not be used
200if the revert required non-trivial conflict resolution, or if the patch being
201reverted is older than a few days.
202
203A developer relanding a patch can TBR the OWNERS for changes which are identical
204to the original (reverted) patch. If the reland patch contains any new changes
205(such as bug fixes) on top of the original, those changes should go through the
206normal review process.
207
208When creating a reland patch, you should first upload an up-to-date patchset
209with the exact content of the original (reverted) patch, and then upload the
210patchset to be relanded. This is important for the reviewers to understand what
211the fix for relanding was.
212
213#### Mechanical changes
214
215You can use TBR with certain mechanical changes that affect many callers in
216different directories. For example, adding a parameter to a common function in
217`//base`, with callers in `//chrome/browser/foo`, `//net/bar`, and many other
218directories. If the updates to the callers is mechanical, you can:
219
Gabriel Charette064574c2018-11-17 01:36:32220 1. Get a normal owner of the lower-level code you're changing (in this
221 example, the function in `//base`) to do a proper review of those changes.
Steve Kobesf885edf2018-09-11 13:41:11222
Gabriel Charette064574c2018-11-17 01:36:32223 2. Get _somebody_ to review the downstream changes made to the callers as a
224 result of the `//base` change. This is often the same person from the
225 previous step but could be somebody else.
Steve Kobesf885edf2018-09-11 13:41:11226
Gabriel Charette064574c2018-11-17 01:36:32227 3. TBR the owner of the lower-level code you're changing (in this example,
228 `//base`), after they've LGTM'ed the API change, to bypass owners review of
229 the API consumers incurring trivial side-effects.
Steve Kobesf885edf2018-09-11 13:41:11230
231This process ensures that all code is reviewed prior to checkin and that the
Gabriel Charette064574c2018-11-17 01:36:32232concept of the change is reviewed by a qualified person, without having to ping
233many owners with little say in the trivial side-effects they incur.
234
235**Note:** The above policy is only viable for strictly mechanical changes. For
236large-scale scripted changes you should:
237
238 1. Have an owner of the core change review the script.
239
240 2. Use `git cl split` to shard the large change into many small CLs with a
241 clear description of what each reviewer is expected to verify
242 ([example](https://chromium-review.googlesource.com/1191225)).
Steve Kobesf885edf2018-09-11 13:41:11243
244#### Documentation updates
245
246You can TBR documentation updates. Documentation means markdown files, text
247documents, and high-level comments in code. At finer levels of detail, comments
248in source files become more like code and should be reviewed normally (not
249using TBR). Non-TBR-able stuff includes things like function contracts and most
250comments inside functions.
251
252 * Use good judgement. If you're changing something very important, tricky,
253 or something you may not be very familiar with, ask for the code review
254 up-front.
255
256 * Don't TBR changes to policy documents like the style guide or this document.
257
258 * Don't mix unrelated documentation updates with code changes.
259
260 * Be sure to actually send out the email for the code review. If you get one,
261 please actually read the changes.
262