Difference between revisions of "Creating A Patch"

From Lazarus wiki
Jump to navigationJump to search
Line 49: Line 49:
 
Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).
 
Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).
  
The recommended way to submit a patch is through the [http://bugs.freepascal.org bug tracker], 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. If the file is big, please compress it to zip or tar.gz/tgz.
+
The recommended way to submit a patch is through the [http://bugs.freepascal.org bug tracker], 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.
  
Alternatively, you can zip or gzip the file you have created and email it to the Lazarus mailing list (40 kB limit) or the mailbox for patches [mailto:patch@lazarus.dommelstein.net patch@lazarus.dommelstein.net]. When sending patches to the patch mailbox, make sure your subject contains at least the word patch.
+
==Using a forked Git repository directly==
 
+
zzz
That's all, thanks for your contribution!
 
  
 
==Applying a patch==
 
==Applying a patch==

Revision as of 13:21, 4 November 2012

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) português (pt) русский (ru) slovenčina (sk)

If you want to submit improvements to the FPC or Lazarus code, you will need to submit a patch so developers can easily merge your improvements in current and future versions of the code.

Exceptions:

  1. .po translation files should be sent as whole files
  2. new files should be sent as whole files, with instructions where they should be placed

Requirements

You can get Lazarus using either SVN or Git.

Creating the patch using SVN: Windows

We'll assume that you have your SVN checkout of Lazarus in C:\lazarus. Please adjust if your Lazarus installation is somewhere else.

  1. Open a MS-DOS prompt, e.g. Start, type cmd.exe, {press enter} and go to the Lazarus source directory:
  2. c:
    
  3. cd \lazarus
    
  4. svn diff > mypatch.diff
    
Light bulb  Note: If using TortoiseSVN, you can select the folder where Lazarus was checked out in Windows Explorer then right click to select TortoiseSVN->Create Patch... See also TortoiseSvn#Troubleshooting

Creating the patch using SVN: Linux, BSD, OS X, Unix

We'll assume that you have your SVN checkout of Lazarus in $HOME/lazarus. Please adjust if your Lazarus installation is somewhere else.

  1. Open your favorite terminal program
  2. cd $HOME
    
  3. cd lazarus
    
  4. svn diff > mypatch.diff
    

Creating the patch using Git

First, develop your code in a separate branch! While your development branch is active, you can create patches of all your local commits by :

git format-patch master

It creates a set of patches named like "0001-CommitMsg.patch", "0002-CommitMsg.patch" and so on.

If you want all the changes in one patch, either combine the commits using "git rebase -i ..." or use the following command :

git format-patch master --stdout > mypatch.patch

Note: "master" branch follows the SVN trunk by default when using git-svn link. However the mirror repository in GitHub uses "upstream" branch instead. Then you must replace "master" with "upstream" in the above commands.

Submitting the patch

Now you have a patch. I'd suggest to look the file over to see if it looks ok (no unexpected changes).

The recommended way to submit a patch is through the bug tracker, 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.

Using a forked Git repository directly

zzz

Applying a patch

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:

patch --dry-run < somepatch.diff

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.

A patch made with "svn diff"

To do the final patching, use the following commandline:

patch < somepatch.diff

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:

patch -p0 < somepatch.diff

A patch made with "git format-patch"

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.

(ToDo: test "patch" on Windows)

patch -p1 < 0001-gitpatch.patch

Troubleshooting

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.

On Windows, the patch.exe supplied with FPC/Lazarus is very picky; you may have better luck with the patch.exe supplied by Git:

"C:\Program Files (x86)\Git\bin\patch.exe" -p0 < mypatch.diff