Sign in Join
Wiki copytemporary

Creating A Patch: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Creating A Patch

OldNewLine
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+
3+Exceptions:
4+
5+1. .po translation files should be sent as whole files
6+2. new files should be sent as whole files, with instructions where they should be placed
7+
8+## Requirements
9+
10+You need the **main/development** version of Lazarus (or FPC). You can get Lazarus using either Git or SVN.
11+
12+- Git: [[Getting Lazarus|Getting Lazarus development version]]. This is the native repository.
13+- SVN: Read-only mirror of the official GitLab repository requires some svn gymnastics due to a bug in many versions of svn:
14+
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`
18+
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`
22+
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**
24+
25+## Platform differences
26+
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+
29+### Windows
30+
31+Assuming you checked out Lazarus into C:\lazarus, open command prompt (cmd.exe) and type "cd \lazarus".
32+
33+### *nix systems
34+
35+Assuming you checked out Lazarus into ~/lazarus, open terminal and type "cd ~/lazarus".
36+
37+## Creating a patch using SVN
38+
39+``` bash
40+svn diff > mypatch.diff
41+```
42+
43+This includes all changed files in the whole SVN repository.
44+
45+You can also define the individual files, to make sure no garbage is included, eg. :
46+
47+``` bash
48+svn diff ide/main.pp ideintf/objectinspector.pp > mypatch.diff
49+```
50+
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+
53+See also [[TortoiseSvn|TortoiseSvn#Troubleshooting]] if you have problems.
54+
55+## Creating a patch using Git
56+
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+
59+``` bash
60+git format-patch master
61+```
62+
63+It creates a set of patches named like "0001-CommitMsg.patch", "0002-CommitMsg.patch" and so on.
64+
65+If you want all the changes in one patch, either combine the commits using "git rebase -i ..." or use the following command :
66+
67+``` bash
68+git format-patch master --stdout > mypatch.patch
69+```
70+
71+## Submitting the patch
72+
73+Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).
74+
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+
77+## Git
78+
79+The GitHub repository [1](https://github.com/graemeg/lazarus) is only a mirror and does not accept pull-requests.
80+
81+## Applying a patch
82+
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+
85+``` bash
86+patch --dry-run < somepatch.diff
87+```
88+
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+
91+### A patch made with "svn diff"
92+
93+To do the final patching, use the following commandline:
94+
95+``` bash
96+patch < somepatch.diff
97+```
98+
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+
101+``` bash
102+patch -p0 < somepatch.diff
103+```
104+
105+Any GUI tool for diffs on Windows can handle these patches, too, including TortoiseMerge.
106+
107+### A patch made with "git format-patch"
108+
109+#### Git
110+
111+Git itself applies the patch like this :
112+
113+``` bash
114+git apply 0001-gitpatch.patch
115+```
116+
117+#### patch
118+
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+
121+``` bash
122+patch -p1 < 0001-gitpatch.patch
123+```
124+
125+"patch" is available for Windows, too, but there are also GUI tools for the job.
126+
127+#### TortoiseMerge
128+
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+
131+ToDo: add more GUI tools that support Git format patches
132+
133+### Troubleshooting
134+
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+
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+
139+```dos
140+"C:\Program Files (x86)\Git\bin\patch.exe" -p0 < mypatch.diff
141+```
142+
143+... or the svn patch command available since SVN 1.7.
144+
145+## See also
146+
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+- [[Tips on writing bug reports]] detailed information on what should be covered in a bug report.
149+- [[Database bug reporting]] Specific info and sample programs for database bugs
150+- [[Moderating the bug tracker]]
151+
152+---
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).*

Back to history