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