6. Patches

There are times when you are not the maintainer of a project or do not have CVS access but would like to contribute with code (whether it is enhancements or bug fixes). This is particularily true to new members who need to prove themselves to a given project's maintainer so he/she would allow them to directly commit to their source tree. It is also possible that the contributor simply wants to make one (or more) contributions but not get directly involved in the project. In either case, a patch is the answer.

Other than the fact that it is easier to deal with patches when wanting to integrate it back into the main code, it makes it much easier for the developer and/or maintainer of a project to review the changes proposed.

To create a patch for changes on a single file, you can simply do:

$ diff -uB file.c.orig file.c > my.patch
    

Make sure to have the original file first and then the modified one second. This would avoid the headache of reverse patches that often result when patches are created in a hurry.

In the case where the modifications span across multiple files and directories you can use the -r switch.

$ diff -uBr dir.orig/ dir/ > my.patch
    

In some cases, there may be newly created files not found in the original distribution of a given project. In this case, we use the -N switch.

One thing to note when creating patches recursively, espcially with the use of the -N switch is to ensure the original directory is a virgin one. That is, without bootstrapping the project or autoconfiguring it. That is because bootstrapping creates many files that will automatically be added to the patch, causing the maintainer much unnecessary pain!

Once you have created the patch you will need to submit it via the bug tracking system used by Arabeyes.