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