Sign in Join
Wiki copytemporary

Creating A Patch: what changed

Revision 1 to 2. 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
1515`svn checkout --depth files `[`https://github.com/fpc/Lazarus/branches`](https://github.com/fpc/Lazarus/branches)` all`\
1616`cd all`\
1717`svn update --set-depth infinity main`
1818
1919`svn checkout --depth files `[`https://github.com/fpc/FPCSource/branches`](https://github.com/fpc/FPCSource/branches)` all`\
2020`cd all`\
2121`svn update --set-depth infinity main`
2222
23-> **Warning:** **If you submit patches, do <u>not</u> 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**
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**
2424
2525## Platform differences
2626
2727The instructions later assume you have opened a command prompt and moved (cd) to the directory of the repository. Here are the details :
2828
2929### Windows
3030
3131Assuming you checked out Lazarus into C:\lazarus, open command prompt (cmd.exe) and type "cd \lazarus".
3232
3333### *nix systems
3434
3535Assuming you checked out Lazarus into ~/lazarus, open terminal and type "cd ~/lazarus".
3636
3737## Creating a patch using SVN
3838
3939``` bash
4040svn diff > mypatch.diff
4141```
4242
4343This includes all changed files in the whole SVN repository.
4444
4545You can also define the individual files, to make sure no garbage is included, eg. :
4646
4747``` bash
4848svn diff ide/main.pp ideintf/objectinspector.pp > mypatch.diff
4949```
5050
5151> **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...
5252
5353See also [[TortoiseSvn|TortoiseSvn#Troubleshooting]] if you have problems.
5454
5555## Creating a patch using Git
5656
5757First, develop your code in a separate branch! While your development branch is active, you can create patches of all your local commits by :
5858
5959``` bash
6060git format-patch master
6161```
6262
6363It creates a set of patches named like "0001-CommitMsg.patch", "0002-CommitMsg.patch" and so on.
6464
6565If you want all the changes in one patch, either combine the commits using "git rebase -i ..." or use the following command :
6666
6767``` bash
6868git format-patch master --stdout > mypatch.patch
6969```
7070
7171## Submitting the patch
7272
7373Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).
7474
7575The 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.
7676
7777## Git
7878
7979The GitHub repository [1](https://github.com/graemeg/lazarus) is only a mirror and does not accept pull-requests.
8080
8181## Applying a patch
8282
8383This 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:
8484
8585``` bash
8686patch --dry-run < somepatch.diff
8787```
8888
8989The 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.
9090
9191### A patch made with "svn diff"
9292
9393To do the final patching, use the following commandline:
9494
9595``` bash
9696patch < somepatch.diff
9797```
9898
9999If 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:
100100
101101``` bash
102102patch -p0 < somepatch.diff
103103```
104104
105105Any GUI tool for diffs on Windows can handle these patches, too, including TortoiseMerge.
106106
107107### A patch made with "git format-patch"
108108
109109#### Git
110110
111111Git itself applies the patch like this :
112112
113113``` bash
114114git apply 0001-gitpatch.patch
115115```
116116
117117#### patch
118118
119119The "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.
120120
121121``` bash
122122patch -p1 < 0001-gitpatch.patch
123123```
124124
125125"patch" is available for Windows, too, but there are also GUI tools for the job.
126126
127127#### TortoiseMerge
128128
129129TortoiseMerge 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.
130130
131131ToDo: add more GUI tools that support Git format patches
132132
133133### Troubleshooting
134134
135135Finally, 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.
136136
137137On Windows, the patch.exe supplied with FPC/Lazarus is very picky; you may have better luck with the patch.exe supplied by Git:
138138
139139```dos
140140"C:\Program Files (x86)\Git\bin\patch.exe" -p0 < mypatch.diff
141141```
142142
143143... or the svn patch command available since SVN 1.7.
144144
145145## See also
146146
147147- [[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.
148148- [[Tips on writing bug reports]] detailed information on what should be covered in a bug report.
149149- [[Database bug reporting]] Specific info and sample programs for database bugs
150150- [[Moderating the bug tracker]]
151151
152152---
153153*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