Creating A Patch: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | If you want to submit improvements to the FPC or Lazarus code, you need to submit a patch which developers can easily merge. | |
| 2 | 2 | ||
| 3 | 3 | Exceptions: | |
| 4 | 4 | ||
| 5 | 5 | 1. .po translation files should be sent as whole files | |
| 6 | 6 | 2. new files should be sent as whole files, with instructions where they should be placed | |
| 7 | 7 | ||
| 8 | 8 | ## Requirements | |
| 9 | 9 | ||
| 10 | 10 | You need the **main/development** version of Lazarus (or FPC). You can get Lazarus using either Git or SVN. | |
| 11 | 11 | ||
| 12 | 12 | - Git: [[Getting Lazarus|Getting Lazarus development version]]. This is the native repository. | |
| 13 | 13 | - SVN: Read-only mirror of the official GitLab repository requires some svn gymnastics due to a bug in many versions of svn: | |
| 14 | 14 | ||
| 15 | 15 | `svn checkout --depth files `[`https://github.com/fpc/Lazarus/branches`](https://github.com/fpc/Lazarus/branches)` all`\ | |
| 16 | 16 | `cd all`\ | |
| 17 | 17 | `svn update --set-depth infinity main` | |
| 18 | 18 | ||
| 19 | 19 | `svn checkout --depth files `[`https://github.com/fpc/FPCSource/branches`](https://github.com/fpc/FPCSource/branches)` all`\ | |
| 20 | 20 | `cd all`\ | |
| 21 | 21 | `svn update --set-depth infinity main` | |
| 22 | 22 | ||
| 23 | - | ||
| 23 | + | > **Warning:** **If you submit patches, do not base them on stable versions of Lazarus/FPC. Typically the development version is very different from stable versions as many improvements and fixes have been applied by the developers** | |
| 24 | 24 | ||
| 25 | 25 | ## Platform differences | |
| 26 | 26 | ||
| 27 | 27 | The instructions later assume you have opened a command prompt and moved (cd) to the directory of the repository. Here are the details : | |
| 28 | 28 | ||
| 29 | 29 | ### Windows | |
| 30 | 30 | ||
| 31 | 31 | Assuming you checked out Lazarus into C:\lazarus, open command prompt (cmd.exe) and type "cd \lazarus". | |
| 32 | 32 | ||
| 33 | 33 | ### *nix systems | |
| 34 | 34 | ||
| 35 | 35 | Assuming you checked out Lazarus into ~/lazarus, open terminal and type "cd ~/lazarus". | |
| 36 | 36 | ||
| 37 | 37 | ## Creating a patch using SVN | |
| 38 | 38 | ||
| 39 | 39 | ``` bash | |
| 40 | 40 | svn diff > mypatch.diff | |
| 41 | 41 | ``` | |
| 42 | 42 | ||
| 43 | 43 | This includes all changed files in the whole SVN repository. | |
| 44 | 44 | ||
| 45 | 45 | You can also define the individual files, to make sure no garbage is included, eg. : | |
| 46 | 46 | ||
| 47 | 47 | ``` bash | |
| 48 | 48 | svn diff ide/main.pp ideintf/objectinspector.pp > mypatch.diff | |
| 49 | 49 | ``` | |
| 50 | 50 | ||
| 51 | 51 | > **Note:** If using [TortoiseSVN](http://tortoisesvn.tigris.org/) on Windows, you can select the folder where Lazarus was checked out in Windows Explorer then right click to select TortoiseSVN-\>Create Patch... | |
| 52 | 52 | ||
| 53 | 53 | See also [[TortoiseSvn|TortoiseSvn#Troubleshooting]] if you have problems. | |
| 54 | 54 | ||
| 55 | 55 | ## Creating a patch using Git | |
| 56 | 56 | ||
| 57 | 57 | First, develop your code in a separate branch! While your development branch is active, you can create patches of all your local commits by : | |
| 58 | 58 | ||
| 59 | 59 | ``` bash | |
| 60 | 60 | git format-patch master | |
| 61 | 61 | ``` | |
| 62 | 62 | ||
| 63 | 63 | It creates a set of patches named like "0001-CommitMsg.patch", "0002-CommitMsg.patch" and so on. | |
| 64 | 64 | ||
| 65 | 65 | If you want all the changes in one patch, either combine the commits using "git rebase -i ..." or use the following command : | |
| 66 | 66 | ||
| 67 | 67 | ``` bash | |
| 68 | 68 | git format-patch master --stdout > mypatch.patch | |
| 69 | 69 | ``` | |
| 70 | 70 | ||
| 71 | 71 | ## Submitting the patch | |
| 72 | 72 | ||
| 73 | 73 | Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes). | |
| 74 | 74 | ||
| 75 | 75 | The recommended way to submit a patch is through the [bug tracker](http://bugs.freepascal.org), see [[How do I create a bug report]] for details. If there is a report for the issue your patch fixes, use that, otherwise create a new issue. Upload the file to attach it to the issue. | |
| 76 | 76 | ||
| 77 | 77 | ## Git | |
| 78 | 78 | ||
| 79 | 79 | The GitHub repository [1](https://github.com/graemeg/lazarus) is only a mirror and does not accept pull-requests. | |
| 80 | 80 | ||
| 81 | 81 | ## Applying a patch | |
| 82 | 82 | ||
| 83 | 83 | This explains how to apply somebody else's patch to your local repository. You can test the patch by using the --dry-run toggle switch like this: | |
| 84 | 84 | ||
| 85 | 85 | ``` bash | |
| 86 | 86 | patch --dry-run < somepatch.diff | |
| 87 | 87 | ``` | |
| 88 | 88 | ||
| 89 | 89 | The output of the patch program will be identical to the actual patching, only it does not alter the sourcecode files. Very handy for testing, without the possibility to screw up your source. | |
| 90 | 90 | ||
| 91 | 91 | ### A patch made with "svn diff" | |
| 92 | 92 | ||
| 93 | 93 | To do the final patching, use the following commandline: | |
| 94 | 94 | ||
| 95 | 95 | ``` bash | |
| 96 | 96 | patch < somepatch.diff | |
| 97 | 97 | ``` | |
| 98 | 98 | ||
| 99 | 99 | If that doesn't work because the path layout of your environment is different from the environment where the patch was created, you can tell *patch* to strip out all path information: | |
| 100 | 100 | ||
| 101 | 101 | ``` bash | |
| 102 | 102 | patch -p0 < somepatch.diff | |
| 103 | 103 | ``` | |
| 104 | 104 | ||
| 105 | 105 | Any GUI tool for diffs on Windows can handle these patches, too, including TortoiseMerge. | |
| 106 | 106 | ||
| 107 | 107 | ### A patch made with "git format-patch" | |
| 108 | 108 | ||
| 109 | 109 | #### Git | |
| 110 | 110 | ||
| 111 | 111 | Git itself applies the patch like this : | |
| 112 | 112 | ||
| 113 | 113 | ``` bash | |
| 114 | 114 | git apply 0001-gitpatch.patch | |
| 115 | 115 | ``` | |
| 116 | 116 | ||
| 117 | 117 | #### patch | |
| 118 | 118 | ||
| 119 | 119 | The "patch" command now supports git format patches with -p1. This is tested with patch v.2.6.1 on Linux, old versions may not support it. | |
| 120 | 120 | ||
| 121 | 121 | ``` bash | |
| 122 | 122 | patch -p1 < 0001-gitpatch.patch | |
| 123 | 123 | ``` | |
| 124 | 124 | ||
| 125 | 125 | "patch" is available for Windows, too, but there are also GUI tools for the job. | |
| 126 | 126 | ||
| 127 | 127 | #### TortoiseMerge | |
| 128 | 128 | ||
| 129 | 129 | TortoiseMerge supports the Git format patch without problems. It is installed together with Tortoise SVN but is not integrated in explorer. It must be opened from the Start menu. | |
| 130 | 130 | ||
| 131 | 131 | ToDo: add more GUI tools that support Git format patches | |
| 132 | 132 | ||
| 133 | 133 | ### Troubleshooting | |
| 134 | 134 | ||
| 135 | 135 | Finally, patches may have a Unix/Linux line ending (LF) while your local file has Windows (CR+LF) line endings or vice versa. You'll have to convert the patch file before applying on Windows at least, as the supplied patch.exe is picky about line endings. | |
| 136 | 136 | ||
| 137 | 137 | On Windows, the patch.exe supplied with FPC/Lazarus is very picky; you may have better luck with the patch.exe supplied by Git: | |
| 138 | 138 | ||
| 139 | 139 | ```dos | |
| 140 | 140 | "C:\Program Files (x86)\Git\bin\patch.exe" -p0 < mypatch.diff | |
| 141 | 141 | ``` | |
| 142 | 142 | ||
| 143 | 143 | ... or the svn patch command available since SVN 1.7. | |
| 144 | 144 | ||
| 145 | 145 | ## See also | |
| 146 | 146 | ||
| 147 | 147 | - [[How do I create a bug report]] general information on submitting bugs, what should be covered in a bug report, and using the bug tracker. | |
| 148 | 148 | - [[Tips on writing bug reports]] detailed information on what should be covered in a bug report. | |
| 149 | 149 | - [[Database bug reporting]] Specific info and sample programs for database bugs | |
| 150 | 150 | - [[Moderating the bug tracker]] | |
| 151 | 151 | ||
| 152 | 152 | --- | |
| 153 | 153 | *From the Free Pascal wiki, page "Creating A Patch", as it stood on 2022-01-13 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
