Sign in Join
Wiki copytemporary

Creating A Patch: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11If you want to submit improvements to the FPC or Lazarus code, you need to submit a patch which developers can easily merge.
22
33Exceptions:
44
551. .po translation files should be sent as whole files
662. new files should be sent as whole files, with instructions where they should be placed
77
88## Requirements
99
1010You need the **main/development** version of Lazarus (or FPC). You can get Lazarus using either Git or SVN.
1111
1212- Git: [[Getting Lazarus|Getting Lazarus development version]]. This is the native repository.
1313- SVN: Read-only mirror of the official GitLab repository requires some svn gymnastics due to a bug in many versions of svn:
1414
15-`svn checkout --depth files `[`https://github.com/fpc/Lazarus/branches`](https://github.com/fpc/Lazarus/branches)` all`\
16-`cd all`\
17-`svn update --set-depth infinity main`
15+```text
16+svn checkout --depth files https://github.com/fpc/Lazarus/branches all
17+cd all
18+svn update --set-depth infinity main
19+```
1820
19-`svn checkout --depth files `[`https://github.com/fpc/FPCSource/branches`](https://github.com/fpc/FPCSource/branches)` all`\
20-`cd all`\
21-`svn update --set-depth infinity main`
21+```text
22+svn checkout --depth files https://github.com/fpc/FPCSource/branches all
23+cd all
24+svn update --set-depth infinity main
25+```
2226
2327> **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**
2428
2529## Platform differences
2630
2731The instructions later assume you have opened a command prompt and moved (cd) to the directory of the repository. Here are the details :
2832
2933### Windows
3034
3135Assuming you checked out Lazarus into C:\lazarus, open command prompt (cmd.exe) and type "cd \lazarus".
3236
3337### *nix systems
3438
3539Assuming you checked out Lazarus into ~/lazarus, open terminal and type "cd ~/lazarus".
3640
3741## Creating a patch using SVN
3842
3943``` bash
4044svn diff > mypatch.diff
4145```
4246
4347This includes all changed files in the whole SVN repository.
4448
4549You can also define the individual files, to make sure no garbage is included, eg. :
4650
4751``` bash
4852svn diff ide/main.pp ideintf/objectinspector.pp > mypatch.diff
4953```
5054
5155> **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...
5256
5357See also [[TortoiseSvn|TortoiseSvn#Troubleshooting]] if you have problems.
5458
5559## Creating a patch using Git
5660
5761First, develop your code in a separate branch! While your development branch is active, you can create patches of all your local commits by :
5862
5963``` bash
6064git format-patch master
6165```
6266
6367It creates a set of patches named like "0001-CommitMsg.patch", "0002-CommitMsg.patch" and so on.
6468
6569If you want all the changes in one patch, either combine the commits using "git rebase -i ..." or use the following command :
6670
6771``` bash
6872git format-patch master --stdout > mypatch.patch
6973```
7074
7175## Submitting the patch
7276
7377Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).
7478
7579The 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.
7680
7781## Git
7882
7983The GitHub repository [1](https://github.com/graemeg/lazarus) is only a mirror and does not accept pull-requests.
8084
8185## Applying a patch
8286
8387This 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:
8488
8589``` bash
8690patch --dry-run < somepatch.diff
8791```
8892
8993The 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.
9094
9195### A patch made with "svn diff"
9296
9397To do the final patching, use the following commandline:
9498
9599``` bash
96100patch < somepatch.diff
97101```
98102
99103If 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:
100104
101105``` bash
102106patch -p0 < somepatch.diff
103107```
104108
105109Any GUI tool for diffs on Windows can handle these patches, too, including TortoiseMerge.
106110
107111### A patch made with "git format-patch"
108112
109113#### Git
110114
111115Git itself applies the patch like this :
112116
113117``` bash
114118git apply 0001-gitpatch.patch
115119```
116120
117121#### patch
118122
119123The "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.
120124
121125``` bash
122126patch -p1 < 0001-gitpatch.patch
123127```
124128
125129"patch" is available for Windows, too, but there are also GUI tools for the job.
126130
127131#### TortoiseMerge
128132
129133TortoiseMerge 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.
130134
131135ToDo: add more GUI tools that support Git format patches
132136
133137### Troubleshooting
134138
135139Finally, 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.
136140
137141On Windows, the patch.exe supplied with FPC/Lazarus is very picky; you may have better luck with the patch.exe supplied by Git:
138142
139143```dos
140144"C:\Program Files (x86)\Git\bin\patch.exe" -p0 < mypatch.diff
141145```
142146
143147... or the svn patch command available since SVN 1.7.
144148
145149## See also
146150
147151- [[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.
148152- [[Tips on writing bug reports]] detailed information on what should be covered in a bug report.
149153- [[Database bug reporting]] Specific info and sample programs for database bugs
150154- [[Moderating the bug tracker]]
151155
152156---
153157*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).*

Back to history