Creating A Patch

From Lazarus wiki
Revision as of 12:38, 22 October 2012 by Chronos (talk | contribs) (notes)

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

This assumes you have gotten Lazarus from SVN. See Getting Lazarus Via SVN

Creating the patch: 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:
    
    {press enter}
  3. cd \lazarus
    
    {press enter}
  4. svn diff > mypatch.diff
    
    {press enter}
Note-icon.png

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...

Creating the patch: 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
    
    {press enter}
  3. cd lazarus
    
    {press enter}
  4. svn diff > mypatch.diff
    
    {press enter}

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. If the file is big, please compress it to zip or tar.gz/tgz.

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 patch@lazarus.dommelstein.net. When sending patches to the patch mailbox, make sure your subject contains at least the word patch.

That's all, thanks for your contribution!

Troubleshooting

This mostly applies to Windows but could apply for other platforms as well.

Error "svn command not found" or similar

Most probably you do not have svn.exe in your PATH environment variable. The following steps should fix this problem:

Temporarily add svn directory to path

  1. Locate svn.exe using the Find Files feature of your Start menu.
  2. Once you have located svn.exe you need to add the directory it is in to your PATH.

As an example: From the command prompt type:

set PATH=%PATH%;"C:\Program Files\TortoiseSVN\"
Note-icon.png

Note: The directory containing svn.exe might not be the same on your computer as the one used in this document. It is used here only as an example.


Permanently add svn directory to path

While this section is optional, it saves you from changing the path all the time. For Windows 98 or lower, you can add the line above (or similar) to your C:\autoexec.bat file near the end.

For Windows 2000 or greater you can add this directory to your PATH by:

  1. Right-Clicking on "My Computer"
  2. Select "Properties"
  3. Choose the "Advanced" tab.
  4. Click the "Environment Variables" button.
  5. Locate the "Path" line in "System Variables" and add: ;"C:\Program Files\TortoiseSVN\" to the end.
Note-icon.png

Note: Your directory containing svn.exe might not be the same on your computer as the one used in this document. It is used here only as an example.

Applying a patch

To apply a patch is simple. You can test the patch by using the --dry-run toggle switch like this:

patch --dry-run < mypatch.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.

To do the final patching, you use the following commandline:

patch < mypatch.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 < mypatch.diff

Depending on the contents of the patch, you might also try with -p1 or other numbers. It might be best to use the --dry-run option as well when doing this.

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