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:
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.
Writing patches is generally done for two reasons:
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.
If you do not have SVN 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;
1) Add the patch in the Patch Tracker.
2) Subscribe to the bf-committers mailing list and send a mail (including the patch number!) that you added a patch in the tracker to bf-committers(at)blender.org.
To get a patch just type svn diff > ../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.
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 match 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.
Submitting patches in this tracker are very welcome! To make timely and proper reviews possible, we'd recommend you to check on the guidelines below.
Doing a good review can take a lot of time, and because almost all regular Blender developers are volunteers, we cannot make a promise you'll get such a review here! Below are tips how to get reviews done:
We recommend every of the active Blender developers to spend some time on reviewing patches. In the past we've done that a lot, and with a bit of luck you'll get great comments and advise for how to improve it. However... to prevent people to feel obliged to spend time on lengthy review discussions we also add a grading convention:
First of all, we're all software developers here, and we understand code work on Blender shows a lot of commitment, and has been your time investment with all the good intentions to help us out. A rejection doesn't mean we don't like you, nor that we don't like to see actively helping out as a contributor! It's all human beings here, with personal preferences, and ideas for how to make Blender a better product.
It makes Blender as an open source project strong if we allow active developers and maintainers to make individual choices too. They're getting empowered to do development, which also implies they have get the benefit of the doubt in making tough decisions.
Nevertheless, mistakes can always happen! Here's what to do to get a patch considered after all: