From BlenderWiki

Jump to: navigation, search

[edit] Using Patches

[edit] What is a patch?

A patch is no more than a plain text file which contains data about the differences between two versions of the same file or files on a line-by-line basis. If a line changes in a file it is compared to the corresponding line in the original version of the file, and the old line along with the newer version are stored in the patch file. The end result is a list of instructions for updating the code of the original file so that it matches the code in the version it is compared to. Below is an example of what you might find in a simple patch file:

[edit] Why work with patches?

Writing and applying patches can be both rewarding and very frustrating. In most cases, creating a patch is one of the only effective ways of sharing changes you've made to Blender's source code with others for review and/or feedback. Likewise, the features and code that others contribute are often only available in the form of a patch. It is thus very important to know how to create and apply patches in order to facilitate quick and accurate communication between developers ragarding Blender's source code.

[edit] When should I submit a patch?

Writing patches is generally done for two reasons:

[edit] To distribute a bugfix

Often you may spot a bug in Blender's source code before a developer has the opportunity to do the same work. Creating a patch is the perfect opportunity to get the work done without putting it on someone else's (likely very long) todo list.

[edit] Contributing new features

Many coders take it upon themselves to add functionality to Blender in their own free time. Without these 'homebrew' projects, Blender would not be what it is today. Outside contributions from hobbyists and professionals alike are crucial to the development process. Yes that means you!


[edit] What should my code look like?

As a general rule of thumb, when creating a patch you should adhere to the style of the file you are editing. However, its better to be safe than sorry! Before beginning work on a project with the Blender source code, it is best to read the Coding Style. This will save valuable time for all parties involved by giving you the guidelines you need to create patches that are consistent with the existing code base and will also inform you on how to maximize readability and organization.

[edit] Submitting Patches

If you do not have CVS write access, the best way to submit a patch to Blender is first to give your patch to someone else and have them test it. Once thats done, you can do two things;

  • Add the patch in the Patch Tracker.
  • subscribe to the bf-committers mailing list and send a mail that you added a patch in the tracker to bf-committers(AT)blender.org.

To get a patch just type cvs diff -u > ../patch.txt from inside the root blender directory, then email us patch.txt.

Try to keep everything in a patch related to one topic. If there are two things you're fixing, eg. adding a new hot key and fixing a memory leak, submit two separate patches, one for each topic.

[edit] How do I Apply Patches?

In order to apply the changes stored in a patch file to your checkout of the Blender source code you need to use the following command in your blender root directory. Note: This requires that patch is installed.

patch -p0 < mypatch.txt

You will then be given an indication of whether or not the operation was a success. If it was not, there are many possibilities as to why your source code was incompatible with the source code the patch was created against. It is best to contact the author to be sure you both have an updated version of sources or edit the resulting files manually to be sure everything is as it should be. Be warned! This can be a time consuming and frustrating process. You can immediately undo the changes made by a patch by using the -R switch as shown below, again from the root directory:

patch -p0 -R < mypatch.txt

This generally will be enough to revert your sources to their previous state.