brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 1 | # Code Reviews |
| 2 | |
| 3 | Code reviews are a central part of developing high-quality code for Chromium. |
| 4 | All changes must be reviewed. |
| 5 | |
| 6 | The bigger patch-upload-and-land process is covered in more detail the |
| 7 | [contributing code](https://www.chromium.org/developers/contributing-code) |
| 8 | page. |
| 9 | |
| 10 | # Code review policies |
| 11 | |
| 12 | Ideally the reviewer is someone who is familiar with the area of code you are |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 13 | touching. Any committer can review code, but an owner must provide a review |
| 14 | for each directory you are touching. If you have doubts, look at the git blame |
| 15 | for the file and the `OWNERS` files (see below). |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 16 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 17 | To indicate a positive review, the reviewer provides a "Code-Review +1" in |
| 18 | Gerrit, also known as an LGTM ("Looks Good To Me"). A score of "-1" indicates |
| 19 | the change should not be submitted as-is. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 20 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 21 | If you have multiple reviewers, provide a message indicating what you expect |
| 22 | from each reviewer. Otherwise people might assume their input is not required |
| 23 | or waste time with redundant reviews. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 24 | |
Annie Sullivan | d04212e7 | 2017-10-19 21:11:32 | [diff] [blame] | 25 | Please also read [Respectful Changes](cl_respect.md) and |
| 26 | [Respectful Code Reviews](cr_respect.md). |
| 27 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 28 | #### Expectations for all reviewers |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 29 | |
| 30 | * Aim to provide some kind of actionable response within 24 hours of receipt |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 31 | (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. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 34 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 35 | * Use the status field in Gerrit settings to indicate if you're away and when |
Mike Frysinger | 7b15bde | 2018-05-15 09:28:05 | [diff] [blame] | 36 | you'll be back. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 37 | |
| 38 | * Don't generally discourage people from sending you code reviews. This |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 39 | includes using a blanket "slow" in your status field. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 40 | |
| 41 | ## OWNERS files |
| 42 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 43 | In various directories there are files named `OWNERS` that list the email |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 44 | addresses of people qualified to review changes in that directory. You must |
| 45 | get a positive review from an owner of each directory your change touches. |
| 46 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 47 | Owners files are recursive, so each file also applies to its subdirectories. |
| 48 | It's generally best to pick more specific owners. People listed in higher-level |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 49 | directories may have less experience with the code in question. For example, |
| 50 | the reviewers in the `//chrome/browser/component_name/OWNERS` file will likely |
| 51 | be more familiar with code in `//chrome/browser/component_name/sub_component` |
| 52 | than reviewers in the higher-level `//chrome/OWNERS` file. |
| 53 | |
| 54 | More detail on the owners file format is provided in the "More information" |
| 55 | section below. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 56 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 57 | *Tip:* The `git cl owners` command can help find owners. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 58 | |
| 59 | While owners must approve all patches, any committer can contribute to the |
| 60 | review. In some directories the owners can be overloaded or there might be |
| 61 | people not listed as owners who are more familiar with the low-level code in |
| 62 | question. In these cases it's common to request a low-level review from an |
| 63 | appropriate person, and then request a high-level owner review once that's |
| 64 | complete. As always, be clear what you expect of each reviewer to avoid |
| 65 | duplicated work. |
| 66 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 67 | Owners do not have to pick other owners for reviews. Since they should already |
| 68 | be familiar with the code in question, a thorough review from any appropriate |
| 69 | committer is sufficient. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 70 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 71 | #### Expectations of owners |
| 72 | |
| 73 | The existing owners of a directory approve additions to the list. It is |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 74 | preferable to have many directories, each with a smaller number of specific |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 75 | owners rather than large directories with many owners. Owners must: |
| 76 | |
| 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 |
| 81 | feedback |
| 82 | |
| 83 | * Be a Chromium project member with full commit access of at least 6 |
| 84 | months tenure. |
| 85 | |
| 86 | * Have submitted a substantial number of non-trivial changes to the affected |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 87 | directory. |
| 88 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 89 | * Have committed or reviewed substantial work to the affected directory |
| 90 | within the last 90 days. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 91 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 92 | * 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 | |
Aaron Gable | 66811f6 | 2017-11-07 19:32:12 | [diff] [blame] | 97 | Seldom-updated directories may have exceptions to the "substantiality" and |
| 98 | "recency" requirements. Directories in `third_party` should list those most |
| 99 | familiar with the library, regardless of how often the code is updated. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 100 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 101 | ### OWNERS file details |
| 102 | |
| 103 | Refer to the [source code](https://chromium.googlesource.com/chromium/tools/depot_tools/+/master/owners.py) |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 104 | for all details on the file format. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 105 | |
| 106 | This example indicates that two people are owners, in addition to any owners |
| 107 | from the parent directory. `git cl owners` will list the comment after an |
| 108 | owner address, so this is a good place to include restrictions or special |
| 109 | instructions. |
| 110 | ``` |
| 111 | # You can include comments like this. |
| 112 | [email protected] |
| 113 | [email protected] # Only for the frobinator. |
| 114 | ``` |
| 115 | |
| 116 | A `*` indicates that all committers are owners: |
| 117 | ``` |
| 118 | * |
| 119 | ``` |
| 120 | |
brettw | d040b0be | 2017-02-09 19:11:33 | [diff] [blame] | 121 | The text `set noparent` will stop owner propagation from parent directories. |
Jochen Eisinger | ea8f92d8 | 2017-08-02 17:40:14 | [diff] [blame] | 122 | This should be rarely used. If you want to use `set noparent` except for IPC |
| 123 | related files, please first reach out to [email protected]. |
| 124 | |
| 125 | In this example, only the two listed people are owners: |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 126 | ``` |
| 127 | set noparent |
| 128 | [email protected] |
| 129 | [email protected] |
| 130 | ``` |
| 131 | |
| 132 | The `per-file` directive allows owners to be added that apply only to files |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 133 | matching a pattern. In this example, owners from the parent directory |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 134 | apply, plus one person for some classes of files, and all committers are |
| 135 | owners for the readme: |
| 136 | ``` |
| 137 | per-file [email protected] |
| 138 | per-file foo.*[email protected] |
| 139 | |
| 140 | per-file readme.txt=* |
| 141 | ``` |
| 142 | |
George Burgess IV | 1ef0493 | 2018-01-27 07:04:04 | [diff] [blame] | 143 | Note that `per-file` directives cannot directly specify subdirectories, e.g: |
| 144 | ``` |
| 145 | per-file foo/[email protected] |
| 146 | ``` |
| 147 | |
| 148 | is not OK; instead, place a `per-file` directive in `foo/OWNERS`. |
| 149 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 150 | Other `OWNERS` files can be included by reference by listing the path to the |
| 151 | file with `file://...`. This example indicates that only the people listed in |
| 152 | `//ipc/SECURITY_OWNERS` can review the messages files: |
| 153 | ``` |
| 154 | per-file *_messages*.h=set noparent |
| 155 | per-file *_messages*.h=file://ipc/SECURITY_OWNERS |
| 156 | ``` |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame^] | 157 | |
| 158 | ## TBR ("To Be Reviewed") |
| 159 | |
| 160 | "TBR" is our mechanism for post-commit review. It should be used rarely and |
| 161 | only in cases where a normal review is unnecessary, as described under |
| 162 | "When to TBR", below. |
| 163 | |
| 164 | TBR does not mean "no review." A reviewer TBR-ed on a change should still |
| 165 | review the change. If there are comments after landing, the author is obligated |
| 166 | to address them in a followup patch. |
| 167 | |
| 168 | Do not use TBR just because a change is urgent or the reviewer is being slow. |
| 169 | Contact the reviewer directly or find somebody else to review your change. |
| 170 | |
| 171 | ### How to TBR |
| 172 | |
| 173 | To send a change TBR, annotate the description and send email like normal. |
| 174 | Otherwise the reviewer won't know to review the patch. |
| 175 | |
| 176 | * Add the reviewer's email address in the code review tool's reviewer field |
| 177 | like normal. |
| 178 | |
| 179 | * Add a line "TBR=<reviewer's email>" to the bottom of the change list |
| 180 | description. e.g. `[email protected],[email protected]` |
| 181 | |
| 182 | * Type a message so that the owners in the TBR list can understand who is |
| 183 | responsible for reviewing what, as part of their post-commit review |
| 184 | responsibility. e.g. |
| 185 | ``` |
| 186 | TBRing reviewers: |
| 187 | reviewer1: Please review changes to foo/ |
| 188 | reviewer2: Please review changes to bar/ |
| 189 | ``` |
| 190 | |
| 191 | ### When to TBR |
| 192 | |
| 193 | #### Reverts and relands |
| 194 | |
| 195 | The most common use of TBR is to revert patches that broke the build. Clean |
| 196 | reverts of recent patches may be submitted TBR. However, TBR should not be used |
| 197 | if the revert required non-trivial conflict resolution, or if the patch being |
| 198 | reverted is older than a few days. |
| 199 | |
| 200 | A developer relanding a patch can TBR the OWNERS for changes which are identical |
| 201 | to the original (reverted) patch. If the reland patch contains any new changes |
| 202 | (such as bug fixes) on top of the original, those changes should go through the |
| 203 | normal review process. |
| 204 | |
| 205 | When creating a reland patch, you should first upload an up-to-date patchset |
| 206 | with the exact content of the original (reverted) patch, and then upload the |
| 207 | patchset to be relanded. This is important for the reviewers to understand what |
| 208 | the fix for relanding was. |
| 209 | |
| 210 | #### Mechanical changes |
| 211 | |
| 212 | You can use TBR with certain mechanical changes that affect many callers in |
| 213 | different directories. For example, adding a parameter to a common function in |
| 214 | `//base`, with callers in `//chrome/browser/foo`, `//net/bar`, and many other |
| 215 | directories. If the updates to the callers is mechanical, you can: |
| 216 | |
| 217 | * Get a normal owner of the lower-level code you're changing (in this |
| 218 | example, the function in `//base`) to do a proper review of those changes. |
| 219 | |
| 220 | * Get _somebody_ to review the downstream changes made to the callers as a |
| 221 | result of the `//base` change. This is often the same person from the |
| 222 | previous step but could be somebody else. |
| 223 | |
| 224 | * Add the owners of the affected downstream directories as TBR. (In this |
| 225 | example, reviewers from `//chrome/browser/foo/OWNERS`, `//net/bar/OWNERS`, |
| 226 | etc.) |
| 227 | |
| 228 | This process ensures that all code is reviewed prior to checkin and that the |
| 229 | concept of the change is reviewed by a qualified person, but you don't have to |
| 230 | wait for many individual owners to review trivial changes to their directories. |
| 231 | |
| 232 | #### Documentation updates |
| 233 | |
| 234 | You can TBR documentation updates. Documentation means markdown files, text |
| 235 | documents, and high-level comments in code. At finer levels of detail, comments |
| 236 | in source files become more like code and should be reviewed normally (not |
| 237 | using TBR). Non-TBR-able stuff includes things like function contracts and most |
| 238 | comments inside functions. |
| 239 | |
| 240 | * Use good judgement. If you're changing something very important, tricky, |
| 241 | or something you may not be very familiar with, ask for the code review |
| 242 | up-front. |
| 243 | |
| 244 | * Don't TBR changes to policy documents like the style guide or this document. |
| 245 | |
| 246 | * Don't mix unrelated documentation updates with code changes. |
| 247 | |
| 248 | * Be sure to actually send out the email for the code review. If you get one, |
| 249 | please actually read the changes. |
| 250 | |