Joe Gregorio | 02f7202 | 2021-03-27 10:12:45 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: 'Applying patches' |
| 3 | linkTitle: 'Applying patches' |
| 4 | --- |
| 5 | |
| 6 | If you are a Skia committer and have been asked to commit an |
| 7 | externally-submitted patch, this is how to do it. (This technique is useful in |
| 8 | other situations too, like if you just want to try out somebody else's patch |
| 9 | locally.) |
| 10 | |
| 11 | Notes: |
| 12 | |
| 13 | - For the examples below, we will assume that this is the change you want to |
| 14 | patch into your local checkout: https://codereview.appspot.com/6201055/ |
| 15 | - These instructions should work on Mac or Linux; Windows is trickier, because |
| 16 | there is no standard Windows "patch" tool. |
| 17 | |
| 18 | See also [Contributing Code for The Chromium Projects] |
| 19 | (http://dev.chromium.org/developers/contributing-code#TOC-Instructions-for-Reviewer:-Checking-in-the-patch-for-a-non-committer). |
| 20 | |
| 21 | If you use `git cl`, then you should be able to use the shortcut: |
| 22 | |
| 23 | ``` |
| 24 | git cl patch 6201055 |
| 25 | ``` |
| 26 | |
| 27 | If you use `gcl`, or the above doesn't work, the following should always work. |
| 28 | |
| 29 | 1. Prepare your local workspace to accept the patch. |
| 30 | |
| 31 | - cd into the root directory (usually `trunk/`) of the workspace where you |
| 32 | want to apply the patch. |
| 33 | - Make sure that the workspace is up-to-date and clean (or "updated and clean |
| 34 | enough" for your purposes). If the codereview patch was against an old |
| 35 | revision of the repo, you may need to sync your local workspace to that |
| 36 | same revision. |
| 37 | |
| 38 | 2. Download the raw patch set. |
| 39 | |
| 40 | - Open the codereview web page and look for the "Download raw patch set" link |
| 41 | near the upper right-hand corner. Right-click on that link and copy it to |
| 42 | the clipboard. (In my case, the link is |
| 43 | https://codereview.appspot.com/download/issue6201055_1.diff ) |
| 44 | - If you are on Linux or Mac and have "curl" or "wget" installed, you can |
| 45 | download the patch from the command line: |
| 46 | |
| 47 | ``` |
| 48 | curl https://codereview.appspot.com/download/issue6201055_1.diff |
| 49 | --output patch.txt |
| 50 | # or... |
| 51 | wget https://codereview.appspot.com/download/issue6201055_1.diff |
| 52 | --output-document=patch.txt |
| 53 | ``` |
| 54 | |
| 55 | - Otherwise, figure out some other way to download this file and save it as |
| 56 | `patch.txt` |
| 57 | |
| 58 | 3. Apply this patch to your local checkout. |
| 59 | |
| 60 | - You should still be in the root directory of the workspace where you want |
| 61 | to apply the patch. |
| 62 | |
| 63 | ``` |
| 64 | patch -p1 <patch.txt |
| 65 | ``` |
| 66 | |
| 67 | - Then you can run `diff` and visually check the local changes. |
| 68 | |
| 69 | 4. Complications: If the patch fails to apply, the following may be happening: |
| 70 | |
| 71 | - Wrong revision. Maybe your local workspace is not up to date? Or maybe the |
| 72 | patch was made against an old revision of the repository, and cannot be |
| 73 | applied to the latest revision? (In that case, revert any changes and sync |
| 74 | your workspace to an older revision, then re-apply the patch.) |