1 .. _phabricator-reviews:
3 =============================
4 Code Reviews with Phabricator
5 =============================
10 If you prefer to use a web user interface for code reviews, you can now submit
11 your patches for Clang and LLVM at `LLVM's Phabricator`_ instance.
13 While Phabricator is a useful tool for some, the relevant -commits mailing list
14 is the system of record for all LLVM code review. The mailing list should be
15 added as a subscriber on all reviews, and Phabricator users should be prepared
16 to respond to free-form comments in mail sent to the commits list.
21 To get started with Phabricator, navigate to `https://reviews.llvm.org`_ and
22 click the power icon in the top right. You can register with a GitHub account,
23 a Google account, or you can create your own profile.
25 Make *sure* that the email address registered with Phabricator is subscribed
26 to the relevant -commits mailing list. If you are not subscribed to the commit
27 list, all mail sent by Phabricator on your behalf will be held for moderation.
29 Note that if you use your git user name as Phabricator user name,
30 Phabricator will automatically connect your submits to your Phabricator user in
31 the `Code Repository Browser`_.
33 Requesting a review via the command line
34 ----------------------------------------
36 Phabricator has a tool called *Arcanist* to upload patches from
37 the command line. To get you set up, follow the
38 `Arcanist Quick Start`_ instructions.
40 You may need to apply a fix to your arcanist repo in order to submit a patch:
42 .. code-block:: console
45 % git am <path/to/llvm-project>/llvm/utils/phabricator/*.patch
47 You can learn more about how to use arc to interact with
48 Phabricator in the `Arcanist User Guide`_.
49 The basic way of creating a revision for the current commit in your local
57 Sometime you may want to create a draft revision to show the proof of concept
58 or for experimental purposes, In that case you can use the `--draft` option. It
59 will create a new draft revision. The good part is: it will not send mail to
60 llvm-commit mailing list, patch reviewers, and all other subscribers, buildbot
61 will also run on every patch update:
65 arc diff --draft HEAD~
68 If you later update your commit message, you need to add the `--verbatim`
69 option to have `arc` update the description on Phabricator:
73 arc diff --edit --verbatim
76 .. _phabricator-request-review-web:
78 Requesting a review via the web interface
79 -----------------------------------------
81 The tool to create and review patches in Phabricator is called
84 Note that you can upload patches created through git, but using `arc` on the
85 command line (see previous section) is preferred: it adds more metadata to
86 Phabricator which are useful for the pre-merge testing system and for
87 propagating attribution on commits when someone else has to push it for you.
89 To make reviews easier, please always include **as much context as
90 possible** with your diff! Don't worry, Phabricator
91 will automatically send a diff with a smaller context in the review
92 email, but having the full file in the web interface will help the
93 reviewer understand your code.
95 To get a full diff, use one of the following commands (or just use Arcanist
96 to upload your patch):
98 * ``git show HEAD -U999999 > mypatch.patch``
99 * ``git diff -U999999 @{u} > mypatch.patch``
100 * ``git diff HEAD~1 -U999999 > mypatch.patch``
102 Before uploading your patch, please make sure it is formatted properly, as
103 described in :ref:`How to Submit a Patch <format patches>`.
105 To upload a new patch:
107 * Click *Differential*.
108 * Click *+ Create Diff*.
109 * Paste the text diff or browse to the patch file. Leave this first Repository
110 field blank. (We'll fill in the Repository later, when sending the review.)
112 * Leave the drop down on *Create a new Revision...* and click *Continue*.
113 * Enter a descriptive title and summary. The title and summary are usually
114 in the form of a :ref:`commit message <commit messages>`.
115 * Add reviewers (see below for advice). (If you set the Repository field
116 correctly, llvm-commits or cfe-commits will be subscribed automatically;
117 otherwise, you will have to manually subscribe them.)
118 * In the Repository field, enter "rG LLVM Github Monorepo".
121 To submit an updated patch:
123 * Click *Differential*.
124 * Click *+ Create Diff*.
125 * Paste the updated diff or browse to the updated patch file. Click *Create Diff*.
126 * Select the review you want to from the *Attach To* dropdown and click
128 * Leave the Repository field blank. (We previously filled out the Repository
129 for the review request.)
130 * Add comments about the changes in the new diff. Click *Save*.
132 Choosing reviewers: You typically pick one or two people as initial reviewers.
133 This choice is not crucial, because you are merely suggesting and not requiring
134 them to participate. Many people will see the email notification on cfe-commits
135 or llvm-commits, and if the subject line suggests the patch is something they
136 should look at, they will.
138 .. _creating-a-patch-series:
140 Creating a patch series
141 -----------------------
143 Chaining reviews together requires some manual work. There are two ways to do it
144 (these are also described `here <https://moz-conduit.readthedocs.io/en/latest/arcanist-user.html#series-of-commits>`_
145 along with some screenshots of what to expect).
147 .. _using-the-web-interface:
149 Using the web interface
150 ^^^^^^^^^^^^^^^^^^^^^^^
152 This assumes that you've already created a Phabricator review for each commit,
153 using `arc` or the web interface.
155 * Go to what will be the last review in the series (the most recent).
156 * Click "Edit Related Revisions" then "Edit Parent Revisions".
157 * This will open a dialog where you will enter the patch number of the parent patch
158 (or patches). The patch number is of the form D<number> and you can find it by
159 looking at the URL for the review e.g. reviews.llvm/org/D12345.
160 * Click "Save Parent Revisions" after entering them.
161 * You should now see a "Stack" tab in the "Revision Contents" section of the web
162 interface, showing the parent patch that you added.
164 Repeat this with each previous review until you reach the first in the series. This
165 one won't have a parent since it's the start of the series.
167 If you prefer to start with the first in the series and go forward, you can use the
168 "Edit Child Revisions" option instead.
170 .. _using-patch-summaries:
172 Using patch summaries
173 ^^^^^^^^^^^^^^^^^^^^^
175 This applies to new and existing reviews, uploaded with `arc` or the web interface.
177 * Upload the first review and note its patch number, either with the web interface
179 * For each commit after that, add the following line to the commit message or patch
180 summary: "Depends on D<num>", where "<num>" is the patch number of the previous review.
181 This must be entirely on its own line, with a blank line before it.
184 [llvm] Example commit
188 * If you want a single review to have multiple parent reviews then
189 add more with "and", for example: "Depends on D12344 and D12345".
190 * Upload the commit with the web interface or `arc`
191 (``arc diff --verbatim`` to update an existing review).
192 * You will see a "Stack" tab in the "Revision Contents" section of the review
193 in the web interface, showing the parent review.
194 * Repeat these steps until you've uploaded or updated all the patches in
197 When you push the patches, please remove the "Depends on" lines from the
198 commit messages, since they add noise and duplicate git's implicit ordering.
200 One frequently used workflow for creating a series of patches using patch summaries
201 is based on git's rebasing. These steps assume that you have a series of commits that
202 you have not posted for review, but can be adapted to update existing reviews.
204 * git interactive rebase back to the first commit you want to upload for review::
206 git rebase -i HEAD~<number of commits you have written>
208 * Mark all commits for editing by changing "pick" to "edit" in the instructions
210 * Start the rebase (usually by writing and closing the instructions).
211 * For the first commit:
213 - Upload the current commit for a review (with ``arc diff`` or the web
216 - Continue to the next commit with ``git rebase --continue``
220 - Add the "Depends on..." line using ``git commit --amend``
224 - Continue the rebase.
226 * Once the rebase is complete, you've created your patch series.
228 .. _finding-potential-reviewers:
230 Finding potential reviewers
231 ---------------------------
233 Here are a couple of ways to pick the initial reviewer(s):
235 * Use ``git blame`` and the commit log to find names of people who have
236 recently modified the same area of code that you are modifying.
237 * Look in CODE_OWNERS.TXT to see who might be responsible for that area.
238 * If you've discussed the change on a dev list, the people who participated
239 might be appropriate reviewers.
241 Even if you think the code owner is the busiest person in the world, it's still
242 okay to put them as a reviewer. Being the code owner means they have accepted
243 responsibility for making sure the review happens.
245 Reviewing code with Phabricator
246 -------------------------------
248 Phabricator allows you to add inline comments as well as overall comments
249 to a revision. To add an inline comment, select the lines of code you want
250 to comment on by clicking and dragging the line numbers in the diff pane.
251 When you have added all your comments, scroll to the bottom of the page and
252 click the Submit button.
254 You can add overall comments in the text box at the bottom of the page.
255 When you're done, click the Submit button.
257 Phabricator has many useful features, for example allowing you to select
258 diffs between different versions of the patch as it was reviewed in the
259 *Revision Update History*. Most features are self descriptive - explore, and
260 if you have a question, drop by on #llvm in IRC to get help.
262 Note that as e-mail is the system of reference for code reviews, and some
263 people prefer it over a web interface, we do not generate automated mail
264 when a review changes state, for example by clicking "Accept Revision" in
265 the web interface. Thus, please type LGTM into the comment box to accept
266 a change from Phabricator.
268 .. _pre-merge-testing:
273 The pre-merge tests are a continuous integration (CI) workflow. The workflow
274 checks the patches uploaded to Phabricator before a user merges them to the main
275 branch - thus the term *pre-merge testing*.
277 When a user uploads a patch to Phabricator, Phabricator triggers the checks and
278 then displays the results. This way bugs in a patch are contained during the
279 code review stage and do not pollute the main branch.
281 Our goal with pre-merge testing is to report most true problems while strongly
282 minimizing the number of false positive reports. Our goal is that problems
283 reported are always actionable. If you notice a false positive, please report
284 it so that we can identify the cause.
286 If you notice issues or have an idea on how to improve pre-merge checks, please
287 `create a new issue <https://github.com/google/llvm-premerge-checks/issues/new>`_
288 or give a ❤️ to an existing one.
293 To get a patch on Phabricator tested, the build server must be able to apply the
294 patch to the checked out git repository. Please make sure that either:
296 * You set a git hash as ``sourceControlBaseRevision`` in Phabricator which is
297 available on the GitHub repository,
298 * **or** you define the dependencies of your patch in Phabricator,
299 * **or** your patch can be applied to the main branch.
301 Only then can the build server apply the patch locally and run the builds and
304 Accessing build results
305 ^^^^^^^^^^^^^^^^^^^^^^^
306 Phabricator will automatically trigger a build for every new patch you upload or
307 modify. Phabricator shows the build results at the top of the entry. Clicking on
308 the links (in the red box) will show more details:
310 .. image:: Phabricator_premerge_results.png
312 The CI will compile and run tests, run clang-format and clang-tidy on lines
315 If a unit test failed, this is shown below the build status. You can also expand
316 the unit test to see the details:
318 .. image:: Phabricator_premerge_unit_tests.png
323 In case you want to opt-out entirely of pre-merge testing, add yourself to the
324 `OPT OUT project <https://reviews.llvm.org/project/view/83/>`_. If you decide
325 to opt-out, please let us know why, so we might be able to improve in the future.
330 The code responsible for running the pre-merge flow can be found in the `external
331 repository <https://github.com/google/llvm-premerge-checks>`_. For enhancement
332 ideas and most bugs, please file an issue on said repository. For immediate
333 operational problems, the point of contact is
334 `Mikhail Goncharov <mailto:goncharo@google.com>`_.
336 Background on the pre-merge infrastructure can be found in `this 2020 DevMeeting
337 talk <https://llvm.org/devmtg/2020-09/slides/Goncharov-Pre-merge_checks.pdf>`_
342 Once a patch has been reviewed and approved on Phabricator it can then be
343 committed to trunk. If you do not have commit access, someone has to
344 commit the change for you (with attribution). It is sufficient to add
345 a comment to the approved review indicating you cannot commit the patch
346 yourself. If you have commit access, there are multiple workflows to commit the
347 change. Whichever method you follow it is recommended that your commit message
352 Differential Revision: <URL>
354 where ``<URL>`` is the URL for the code review, starting with
355 ``https://reviews.llvm.org/``.
357 This allows people reading the version history to see the review for
358 context. This also allows Phabricator to detect the commit, close the
359 review, and add a link from the review to the commit.
361 Note that if you use the Arcanist tool the ``Differential Revision`` line will
362 be added automatically. If you don't want to use Arcanist, you can add the
363 ``Differential Revision`` line (as the last line) to the commit message
366 Using the Arcanist tool can simplify the process of committing reviewed code as
367 it will retrieve reviewers, the ``Differential Revision``, etc from the review
368 and place it in the commit message. You may also commit an accepted change
369 directly using ``git push``, per the section in the :ref:`getting started
370 guide <commit_from_git>`.
372 Note that if you commit the change without using Arcanist and forget to add the
373 ``Differential Revision`` line to your commit message then it is recommended
374 that you close the review manually. In the web UI, under "Leap Into Action" put
375 the git revision number in the Comment, set the Action to "Close Revision" and
376 click Submit. Note the review must have been Accepted first.
378 Committing someone's change from Phabricator
379 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
381 On a clean Git repository on an up to date ``main`` branch run the
382 following (where ``<Revision>`` is the Phabricator review number):
386 arc patch D<Revision>
389 This will create a new branch called ``arcpatch-D<Revision>`` based on the
390 current ``main`` and will create a commit corresponding to ``D<Revision>`` with a
391 commit message derived from information in the Phabricator review.
393 Check you are happy with the commit message and amend it if necessary.
394 For example, ensure the 'Author' property of the commit is set to the original author.
395 You can use a command to correct the author property if it is incorrect:
399 git commit --amend --author="John Doe <jdoe@llvm.org>"
401 Then, make sure the commit is up-to-date, and commit it. This can be done by running
406 git pull --rebase https://github.com/llvm/llvm-project.git main
407 git show # Ensure the patch looks correct.
408 ninja check-$whatever # Rerun the appropriate tests if needed.
409 git push https://github.com/llvm/llvm-project.git HEAD:main
415 If you decide you should not commit the patch, you should explicitly abandon
416 the review so that reviewers don't think it is still open. In the web UI,
417 scroll to the bottom of the page where normally you would enter an overall
418 comment. In the drop-down Action list, which defaults to "Comment," you should
419 select "Abandon Revision" and then enter a comment explaining why. Click the
420 Submit button to finish closing the review.
425 Please let us know whether you like it and what could be improved! We're still
426 working on setting up a bug tracker, but you can email klimek-at-google-dot-com
427 and chandlerc-at-gmail-dot-com and CC the llvm-dev mailing list with questions
428 until then. We also could use help implementing improvements. This sadly is
429 really painful and hard because the Phabricator codebase is in PHP and not as
430 testable as you might like. However, we've put exactly what we're deploying up
431 on an `llvm-reviews GitHub project`_ where folks can hack on it and post pull
432 requests. We're looking into what the right long-term hosting for this is, but
433 note that it is a derivative of an existing open source project, and so not
434 trivially a good fit for an official LLVM project.
436 .. _LLVM's Phabricator: https://reviews.llvm.org
437 .. _`https://reviews.llvm.org`: https://reviews.llvm.org
438 .. _Code Repository Browser: https://reviews.llvm.org/diffusion/
439 .. _Arcanist Quick Start: https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/
440 .. _Arcanist User Guide: https://secure.phabricator.com/book/phabricator/article/arcanist/
441 .. _llvm-reviews GitHub project: https://github.com/r4nt/llvm-reviews/