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 | |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 17 | To indicate a positive review, the reviewer chooses "+1" in Code-Review field |
| 18 | on Gerrit, or types "LGTM" (case insensitive) into a comment on Rietveld. This |
| 19 | stands for "Looks Good To Me." "-1" in Code-Review field on Gerrit or the text |
| 20 | "not LGTM" on Rietveld will cancel out a previous positive review. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 21 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 22 | If you have multiple reviewers, make it clear in the message you send |
| 23 | requesting review what you expect from each reviewer. Otherwise people might |
| 24 | assume their input is not required or waste time with redundant reviews. |
| 25 | |
Annie Sullivan | d04212e7 | 2017-10-19 21:11:32 | [diff] [blame^] | 26 | Please also read [Respectful Changes](cl_respect.md) and |
| 27 | [Respectful Code Reviews](cr_respect.md). |
| 28 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 29 | #### Expectations for all reviewers |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 30 | |
| 31 | * Aim to provide some kind of actionable response within 24 hours of receipt |
| 32 | (not counting weekends and holidays). This doesn't mean you have to have |
| 33 | done a complete review, but you should be able to give some initial |
| 34 | feedback, request more time, or suggest another reviewer. |
| 35 | |
| 36 | * It can be nice to indicate if you're away in your name in the code review |
| 37 | tool. If you do this, indicate when you'll be back. |
| 38 | |
| 39 | * Don't generally discourage people from sending you code reviews. This |
| 40 | includes writing a blanket ("slow") after your name in the review tool. |
| 41 | |
| 42 | ## OWNERS files |
| 43 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 44 | In various directories there are files named `OWNERS` that list the email |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 45 | addresses of people qualified to review changes in that directory. You must |
| 46 | get a positive review from an owner of each directory your change touches. |
| 47 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 48 | Owners files are recursive, so each file also applies to its subdirectories. |
| 49 | It's generally best to pick more specific owners. People listed in higher-level |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 50 | directories may have less experience with the code in question. For example, |
| 51 | the reviewers in the `//chrome/browser/component_name/OWNERS` file will likely |
| 52 | be more familiar with code in `//chrome/browser/component_name/sub_component` |
| 53 | than reviewers in the higher-level `//chrome/OWNERS` file. |
| 54 | |
| 55 | More detail on the owners file format is provided in the "More information" |
| 56 | section below. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 57 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 58 | *Tip:* The `git cl owners` command can help find owners. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 59 | |
| 60 | While owners must approve all patches, any committer can contribute to the |
| 61 | review. In some directories the owners can be overloaded or there might be |
| 62 | people not listed as owners who are more familiar with the low-level code in |
| 63 | question. In these cases it's common to request a low-level review from an |
| 64 | appropriate person, and then request a high-level owner review once that's |
| 65 | complete. As always, be clear what you expect of each reviewer to avoid |
| 66 | duplicated work. |
| 67 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 68 | Owners do not have to pick other owners for reviews. Since they should already |
| 69 | be familiar with the code in question, a thorough review from any appropriate |
| 70 | committer is sufficient. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 71 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 72 | #### Expectations of owners |
| 73 | |
| 74 | 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] | 75 | preferable to have many directories, each with a smaller number of specific |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 76 | owners rather than large directories with many owners. Owners must: |
| 77 | |
| 78 | * Demonstrate excellent judgment, teamwork and ability to uphold Chrome |
| 79 | development principles. |
| 80 | |
| 81 | * Be already acting as an owner, providing high-quality reviews and design |
| 82 | feedback |
| 83 | |
| 84 | * Be a Chromium project member with full commit access of at least 6 |
| 85 | months tenure. |
| 86 | |
| 87 | * Have submitted a substantial number of non-trivial changes to the affected |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 88 | directory. |
| 89 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 90 | * Have committed or reviewed substantial work to the affected directory |
| 91 | within the last 90 days. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 92 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 93 | * Have the bandwidth to contribute to reviews in a timely manner. If the load |
| 94 | is unsustainable, work to expand the number of owners. Don't try to |
| 95 | discourage people from sending reviews, including writing "slow" or |
| 96 | "emeritus" after your name. |
| 97 | |
| 98 | Seldom-updated directories may have exceptions. Directories in `third_party` |
| 99 | should list those most familiar with the library. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 100 | |
| 101 | ## TBR ("To Be Reviewed") |
| 102 | |
| 103 | "TBR" is our mechanism for post-commit review. It should be used rarely and |
| 104 | only in cases where a review is unnecessary or as described below. The most |
| 105 | common use of TBR is to revert patches that broke the build. |
| 106 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 107 | TBR does not mean "no review." A reviewer TBR-ed on a change should still |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 108 | review the change. If there are comments after landing, the author is obligated |
| 109 | to address them in a followup patch. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 110 | |
| 111 | Do not use TBR just because a change is urgent or the reviewer is being slow. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 112 | Contact the reviewer directly or find somebody. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 113 | |
| 114 | To send a change TBR, annotate the description and send email like normal. |
| 115 | Otherwise the reviewer won't know to review the patch. |
| 116 | |
| 117 | * Add the reviewer's email address in the code review tool's reviewer field |
| 118 | like normal. |
| 119 | |
| 120 | * Add a line "TBR=<reviewer's email>" to the bottom of the change list |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 121 | description. e.g. `[email protected],[email protected]` |
| 122 | |
| 123 | * Type a message so that the owners in the TBR list can understand who is |
| 124 | responsible for reviewing what, as part of their post-commit review |
| 125 | responsibility. e.g. |
| 126 | ``` |
| 127 | TBRing reviewers: |
| 128 | reviewer1: Please review changes to foo/ |
| 129 | reviewer2: Please review changes to bar/ |
| 130 | ``` |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 131 | |
| 132 | * Push the "send mail" button. |
| 133 | |
| 134 | ### TBR-ing certain types of mechanical changes |
| 135 | |
| 136 | Sometimes you might do something that affects many callers in different |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 137 | directories. For example, adding a parameter to a common function in |
| 138 | `//base`, with callers in `//chrome/browser/foo`, `//net/bar`, and many other |
| 139 | directories. If the updates to the callers is mechanical, you can: |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 140 | |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 141 | * Get a normal owner of the lower-level code you're changing (in this |
| 142 | example, the function in `//base`) to do a proper review of those changes. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 143 | |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 144 | * Get _somebody_ to review the downstream changes made to the callers as a |
| 145 | result of the `//base` change. This is often the same person from the |
| 146 | previous step but could be somebody else. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 147 | |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 148 | * Add the owners of the affected downstream directories as TBR. (In this |
| 149 | example, reviewers from `//chrome/browser/foo/OWNERS`, `//net/bar/OWNERS`, |
| 150 | etc.) |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 151 | |
| 152 | This process ensures that all code is reviewed prior to checkin and that the |
| 153 | concept of the change is reviewed by a qualified person, but you don't have to |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 154 | wait for many individual owners to review trivial changes to their directories. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 155 | |
| 156 | ### TBR-ing documentation updates |
| 157 | |
| 158 | You can TBR documentation updates. Documentation means markdown files, text |
| 159 | documents, and high-level comments in code. At finer levels of detail, comments |
| 160 | in source files become more like code and should be reviewed normally (not |
| 161 | using TBR). Non-TBR-able stuff includes things like function contracts and most |
| 162 | comments inside functions. |
| 163 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 164 | * Use good judgement. If you're changing something very important, tricky, |
| 165 | or something you may not be very familiar with, ask for the code review |
| 166 | up-front. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 167 | |
| 168 | * Don't TBR changes to policy documents like the style guide or this document. |
| 169 | |
| 170 | * Don't mix unrelated documentation updates with code changes. |
| 171 | |
| 172 | * Be sure to actually send out the email for the code review. If you get one, |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 173 | please actually read the changes. |
| 174 | |
| 175 | ## More information |
| 176 | |
| 177 | ### OWNERS file details |
| 178 | |
| 179 | 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] | 180 | for all details on the file format. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 181 | |
| 182 | This example indicates that two people are owners, in addition to any owners |
| 183 | from the parent directory. `git cl owners` will list the comment after an |
| 184 | owner address, so this is a good place to include restrictions or special |
| 185 | instructions. |
| 186 | ``` |
| 187 | # You can include comments like this. |
| 188 | [email protected] |
| 189 | [email protected] # Only for the frobinator. |
| 190 | ``` |
| 191 | |
| 192 | A `*` indicates that all committers are owners: |
| 193 | ``` |
| 194 | * |
| 195 | ``` |
| 196 | |
brettw | d040b0be | 2017-02-09 19:11:33 | [diff] [blame] | 197 | The text `set noparent` will stop owner propagation from parent directories. |
Jochen Eisinger | ea8f92d8 | 2017-08-02 17:40:14 | [diff] [blame] | 198 | This should be rarely used. If you want to use `set noparent` except for IPC |
| 199 | related files, please first reach out to [email protected]. |
| 200 | |
| 201 | In this example, only the two listed people are owners: |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 202 | ``` |
| 203 | set noparent |
| 204 | [email protected] |
| 205 | [email protected] |
| 206 | ``` |
| 207 | |
| 208 | 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] | 209 | matching a pattern. In this example, owners from the parent directory |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 210 | apply, plus one person for some classes of files, and all committers are |
| 211 | owners for the readme: |
| 212 | ``` |
| 213 | per-file [email protected] |
| 214 | per-file foo.*[email protected] |
| 215 | |
| 216 | per-file readme.txt=* |
| 217 | ``` |
| 218 | |
| 219 | Other `OWNERS` files can be included by reference by listing the path to the |
| 220 | file with `file://...`. This example indicates that only the people listed in |
| 221 | `//ipc/SECURITY_OWNERS` can review the messages files: |
| 222 | ``` |
| 223 | per-file *_messages*.h=set noparent |
| 224 | per-file *_messages*.h=file://ipc/SECURITY_OWNERS |
| 225 | ``` |