Actions

Difference between revisions of "Learn more about patch files"

From Joomla! Documentation

m
(Other Important Articles About Patch Files)
(4 intermediate revisions by 3 users not shown)
Line 22: Line 22:
  
 
</code>
 
</code>
Looking more closely, we see that the patch always starts with the name of the changed file relatiive to the Joomla! root. In this case it is the file gmail.php in the plugins/authenticaion folder.
+
Looking more closely, we see that the patch always starts with the name of the changed file relative to the Joomla! root. In this case it is the file gmail.php in the plugins/authenticaion folder.
  
Next we see the file named again in two lines. The number in the first line represents the version of the code base or build on which the patch was created, The working copy is the copy that is changed. What do I mean by build? Every time a change is made to he codebase, that creates a new revision or build. You can find your build number in the changelog.php file in your joomla! root.
+
Next we see the file named again in two lines. The number in the first line represents the version of the code base or build on which the patch was created, The working copy is the copy that is changed. What do I mean by build? Every time a change is made to the codebase, that creates a new revision or build. You can find your build number in the changelog.php file in your joomla! root.
  
Next comes @@ -87,7 +87,7 @@ which tells us that the change will starton line 87 of the file.
+
Next comes @@ -87,7 +87,7 @@ which tells us that the change will start on line 87 of the file.
  
 
Finally we see the code. The old line 87 has a – in front of it and the new line 87 has a +.
 
Finally we see the code. The old line 87 has a – in front of it and the new line 87 has a +.
Line 37: Line 37:
  
 
Now, if you're contributing a bug fix  as opposed to just reporting an issue, the ideal is to submit a patch file that you have tested. However, if you can't do that, at least give this information:
 
Now, if you're contributing a bug fix  as opposed to just reporting an issue, the ideal is to submit a patch file that you have tested. However, if you can't do that, at least give this information:
 
 
  
 
     * The complete names and paths of any files changed
 
     * The complete names and paths of any files changed
Line 44: Line 42:
 
     * The old and new versions of the changed lines
 
     * The old and new versions of the changed lines
  
   
+
However, making a patch file is even better and is not complicated if you install a subversion client such as Tortoise or the Subclipse plugin for Eclipse. For information on how to install the Eclipse IDE, see [[Setting_up_your_workstation_for_Joomla!_development | Setting up your workstation for Joomla! development]].
 +
 
 +
==Patch Files and UTF-8 Characters==
 +
Most patch files are for PHP files that contain simple text. However, patch files can also be used to patch language INI files, and these can often contain UTF-8 characters. There is a known problem when you try to apply a patch with UTF-8 characters using Eclipse. The patch file may show errors when you try to apply it. One possible work-around to this problem is to copy the file to your clipboard and then in the Patch Input Specification in Eclipse, select Clipboard instead of File. Note that the preview for the patched files may show question marks for the UTF-8 characters, but the patch will apply correctly.
 +
 
 +
You can check that the patch did apply correctly by using the Compare With&rarr;Base Revision feature in Eclipse.
  
However, making a patch file is even better and is not complicated if you install a subversion client such as Tortoise or the Subclipse plugin for Eclipse.
+
==Other Important Articles About Patch Files==
 +
[http://docs.joomla.org/Git_for_Testers_and_Trackers#Important_Notes_About_Patch_File_Format Important Notes About Patch File Format]<br/>
 +
[http://docs.joomla.org/Git_for_Testers_and_Trackers#Apply_Patches_and_Pull_Requests_Without_Branches Apply Patches and Pull Requests Without Branches]<br/>
 +
[http://docs.joomla.org/Git_for_Testers_and_Trackers#Apply_Patches_and_Pull_Requests_Using_Branches Apply Patches and Pull Requests Using Branches]<br/>

Revision as of 09:10, 22 March 2013


Test this patch, make a patch, are things you hear when you report an issue or when you're working on bugs. What exactly is a patch?

A patch is a file that indicates which exact lines in which exact files should be changed.

Here's a recent patch from issue 11354 which corrected a simple typo.

Index: plugins/authentication/gmail.php
===================================================================
--- plugins/authentication/gmail.php (revision 10386)
+++ plugins/authentication/gmail.php (working copy)
@@ -87,7 +87,7 @@
 }
 }
 else {
- $message = 'curl isn\'t insalled';
+ $message = 'curl isn\'t installed';
 } 
 if ($success)

Looking more closely, we see that the patch always starts with the name of the changed file relative to the Joomla! root. In this case it is the file gmail.php in the plugins/authenticaion folder.

Next we see the file named again in two lines. The number in the first line represents the version of the code base or build on which the patch was created, The working copy is the copy that is changed. What do I mean by build? Every time a change is made to the codebase, that creates a new revision or build. You can find your build number in the changelog.php file in your joomla! root.

Next comes @@ -87,7 +87,7 @@ which tells us that the change will start on line 87 of the file.

Finally we see the code. The old line 87 has a – in front of it and the new line 87 has a +.

The new version of the line will replace the old line in the file.

Of course most patches are much more complex than this, but they really just are repeated instances of this structure.

So if you saw this patch file and wanted to fix your version of Joomla! all you would need to do is find line 87 of gmail.php and make that change. So if someone tells you “There's a patch on the tracker” what they are saying is that you can go download the patch and apply it to your version of Joomla!. However one thing to keep in mind is that if your version does not match the version in the code repository it is possible that that patch will not work because it depends on or impacts other parts of the code.

Now, if you're contributing a bug fix as opposed to just reporting an issue, the ideal is to submit a patch file that you have tested. However, if you can't do that, at least give this information:

   * The complete names and paths of any files changed
   * The line numbers of the changes
   * The old and new versions of the changed lines

However, making a patch file is even better and is not complicated if you install a subversion client such as Tortoise or the Subclipse plugin for Eclipse. For information on how to install the Eclipse IDE, see Setting up your workstation for Joomla! development.

Patch Files and UTF-8 Characters

Most patch files are for PHP files that contain simple text. However, patch files can also be used to patch language INI files, and these can often contain UTF-8 characters. There is a known problem when you try to apply a patch with UTF-8 characters using Eclipse. The patch file may show errors when you try to apply it. One possible work-around to this problem is to copy the file to your clipboard and then in the Patch Input Specification in Eclipse, select Clipboard instead of File. Note that the preview for the patched files may show question marks for the UTF-8 characters, but the patch will apply correctly.

You can check that the patch did apply correctly by using the Compare With→Base Revision feature in Eclipse.

Other Important Articles About Patch Files

Important Notes About Patch File Format
Apply Patches and Pull Requests Without Branches
Apply Patches and Pull Requests Using Branches