|
|
Line 1: |
Line 1: |
| {{OSWikiContribBox}} | | {{OSWikiContribBox}} |
|
| |
|
| If you have a piece of source code (be it a fix, new feature, or optimization of existing code) submit the patches in a way that makes it easy for the Lindens to incorporate them into the source code. | | If you have a piece of source code (be it a fix, new feature, or optimization of existing code) prepare your changes in a way that makes it easy for the Lindens to incorporate them into the source code. |
|
| |
|
| == Good Patch Practice == | | == Good Change Practice == |
|
| |
|
| === General === | | === General === |
|
| |
|
| The people who review and apply patches are the bottleneck in the system. If you can make it easier for Lindens to understand, test and apply your patch without lots of cleanup, Lindens can incorporate more patches in a fixed amount of time.
| | It's easy for the people who review and apply changes to be the bottleneck in the system. If you can make it easier for Lindens to understand, test, and integrate your change, it is much better for everyone concerned. |
|
| |
|
| ===Before You Start=== | | ===Before You Start=== |
|
| |
|
| Check [https://jira.secondlife.com/secure/Dashboard.jspa JIRA Bug Tracker] to see if a similar issue has been submitted, and check its status. You will eventually attach to the existing issue if you find one. If your issue is new, it can help to create the issue before starting work so that others can begin voting for the patch. More votes lead to faster incorporation.
| | * Understand and use the [[Project Snowstorm#Processes|Project Snowstorm Processes]]; making sure that your change is part of the plan is the most important thing you can do to get it accepted. |
|
| |
|
| Developers are encouraged to complete the [http://secondlifegrid.net/programs/open_source/submission contribution agreement]. The sooner you do that, the sooner Lindens can accept your patch. Submissions to Snowglobe cannot be included in the official Second Life Viewer without this agreement in place.
| | * You ''must'' complete and sign the [http://secondlifegrid.net/programs/open_source/submission contribution agreement]. |
|
| |
|
| === Coding Standard === | | === Coding Standard === |
Line 21: |
Line 21: |
| === Comments === | | === Comments === |
|
| |
|
| Please do not add issue numbers and your name to the code section. These have to be removed by hand. While comments explaining code in a general working context are helpful, bracketing a patch with comments like "// PATCH START" and "// PATCH END" does not add any information, and adds to the manual cleanup Lindens have to do.
| | Do not add issue numbers and your name to the code itself. While comments explaining code in a general working context are helpful and strongly encouraged, bracketing a change with comments like "// PATCH START" and "// PATCH END" does not add any information, and is likely to get your change returned for revision. |
|
| |
|
| In short, add to the patch what is expected to appear in the final source. | | Do not comment out or use the preprocessor to disable code that you are replacing: just delete it. The source control system can find it again if we need it, and leaving dead code around makes things harder to read and much harder to search. |
| | |
| | In short, make your change what is expected to appear in the final source. |
|
| |
|
| === Give Yourself Credit! === | | === Give Yourself Credit! === |
|
| |
|
| While names and JIRAs shouldn't appear in source, they do belong in doc/contributions.txt. Please don't be shy about adding the issue label and adding your name. We use this file for a number of purposes, including the generation of the [[Source contributions]] page. This also helps Lindens track the purpose of a given patch file. | | While names and JIRAs shouldn't appear in source, they do belong in doc/contributions.txt. Please don't be shy about adding the issue label and adding your name. |
|
| |
|
| === One Patch for one Issue === | | === One Change for one Issue === |
|
| |
|
| Each patch should do exactly one thing. If you have three different bugs to fix, please submit three different patches. When you fold unrelated hunks into a single patch, Lindens have to try to figure out which part of the patch applies to which bug, and split it out by hand, usually into several patches. Combo patches are particularly time consuming, and the manual splitting up makes it very easy to lose pieces of patches altogether. | | Each submission should do exactly one thing. If you have three different bugs to fix, please submit three different change sets (unless they are very closely related and being treated as one item in the sprint). If you are unsure whether or not it is ok to combine changes into one submission, ask the Lindens. |
|
| |
|
| === Less is more === | | === Less is more === |
|
| |
|
| Smaller patches are easier to review and therefore more likely to be integrated quickly. The longer it takes for a patch to be incorporated, the higher the likelihood that the underlying code will change enough for the patch to fail. Please do not include formatting or other clean-up changes. These make a patch harder to review and more likely to fail. | | Smaller patches are easier to review and therefore more likely to be integrated quickly. This does not mean that you should omit comments or unit tests, however - adding to those is strongly encouraged. |
| | |
| === Path structure ===
| |
| | |
| It's best practice for your patch to be made on the directory level where the linden folder resides so that the path/file names in your patch will start with '''linden/'''. If you are working from a SVN, a diff in SVN style starting from the '''indra''' directory level [https://lists.secondlife.com/pipermail/sldev/2008-May/009568.html is also fine].
| |
| | |
| === Additional Suggestions ===
| |
| | |
| Getting your patches accepted into open source projects is a bit of an art. The Red Hat Linux project contains [http://et.redhat.com/~rjones/how-to-supply-code-to-open-source-projects/ some excellent tips] that you may find to be helpful.
| |
| | |
| == Creating a Patch ==
| |
| | |
| Patches should be submitted in unified diff format. This format is similar to simple diffs, but with more detailed information, and it can be automatically integrated into the source. You can generate a unified diff by calling ''diff -u <original file> <new file>'' (under Windows you will find the diff command as part of the CygWin project in C:\CYGWIN\BIN).
| |
| | |
| Please submit a single plain text uncompressed patch file that affects all of the files you need to modify. This is far easier to review than a collection of tiny one-file patches.
| |
| | |
| Also bad for reviewability are a compressed patch, or a tarball or zip containing one or more patches.
| |
| | |
| === Unified diff of all changed files in a folder tree ===
| |
| The easiest way to generate a clean patch is to keep two copies of the source tree. Leave one completely unmodified, and make all of your changes in the second. Then use "diff -urN" to generate the patch. You can use the --exclude option to omit unwanted files. For example:
| |
| | |
| diff -urN --exclude="*.o" my_untouched_tree my_modified_tree
| |
| | |
| === Unified diff of multiple files ===
| |
| If for any reason you can not use a whole tree diff as above, you can still merge patches from different files into one, by appending the output of patch commands to the previous output (via '''>>''' redirection for the 2nd and later commands).
| |
| | |
| diff -u linden-untouched/indra/newview/viewer.h linden/indra/newview/viewer.h >mychanges.patch.txt
| |
| diff -u linden-untouched/indra/newview/viewer.cpp linden/indra/newview/viewer.cpp '''>>'''mychanges.patch.txt
| |
| diff -u linden-untouched/indra/newview/llviewerwindow.cpp linden/indra/newview/llviewerwindow.cpp '''>>'''mychanges.patch.txt
| |
| | |
| <br/>
| |
| | |
| === CR/LF vs LF and Whitespace===
| |
| In some situations, you will find that the patch contains the whole file, rather than just the lines changed. The reason is that sometimes, files in Linux format find their way into the source distribution. With these diff.exe will treat all lines as different from those in your modified file.
| |
| | |
| There are various options that will help here. You can add ''--strip-trailing-cr'' to the command line to fix this.
| |
| | |
| diff -u --strip-trailing-cr linden-untouched/indra/newview/viewer.h linden/indra/newview/viewer.h >mychanges.patch.txt
| |
| | |
| In some situations try the '''w''' (ignore whitespace) and/or '''B''' (ignore empty lines) options are also helpful (e.g. with tabs vs. space or spurious space characters while editing). Type '''diff --help''' for more details.
| |
| | |
| <br/>
| |
| | |
| === Sample output ===
| |
| For reference, here's what a unified diff looks like.
| |
| | |
| --- linden-untouched/indra/newview/viewer.cpp 2007-05-14 16:47:26.000000000 +0200
| |
| +++ linden/indra/newview/viewer.cpp 2007-05-22 08:49:50.484375000 +0200
| |
| @@ -6302,7 +6326,7 @@
| |
|
| |
| llinfos << "Cleaning Up" << llendflush;
| |
|
| |
| - LLKeyframeMotion::flushKeyframeCache();
| |
| + LLKeyframeMotion::flushKeyframeCache(TRUE);
| |
|
| |
| // Must clean up texture references before viewer window is destroyed.
| |
| LLHUDObject::cleanupHUDObjects();
| |
| @@ -6562,6 +6586,8 @@
| |
| delete gVFS;
| |
| gVFS = NULL;
| |
|
| |
| + LLCurl::cleanup();
| |
| +
| |
| // This will eventually be done in LLApp
| |
| LLCommon::cleanupClass();
| |
| }
| |
| | |
| == Submitting the Patch on JIRA ==
| |
| | |
| When you are ready for the world to view your patch, submit the patch on the [https://jira.secondlife.com/secure/Dashboard.jspa| JIRA Bug Tracker]. Create a new issue or attach the patch to an existing entry as appropriate. Attach the ''.patch.txt'' file itself as a file attachment and make sure that the check mark for ''Patch attached'' is set (you can do that when creating the issue or by choosing Edit for an existing one). Along with your patch, it helps to provide a brief description explaining your patch from an implementor's view. Non-trivial patches benefit form a simple review plan naming what systems were affected and describing what peers can do to verify that the patch works and doesn't break surrounding systems. Very often, you will find that writing only a few lines will give you pause and make you double-check some code.
| |
| | |
| For all but the most trivial patches, it is a good idea to submit the patch for peer review on the [[Developer_communication_tools|mailing list]]. This way fellow developers can review the patch, uncover possible bugs, comment on undesired interactions or generally share ideas with you. Subscribe to the mailing list, then write an email to the list with a link to the description of what your patch does.
| |
| | |
| Good luck!
| |
| | |
| == Applying patches to your source ==
| |
| | |
| In case you are interested, the application of other patches to your source is easy. Assuming that you are at the directory level from where the patch references the files (usually in the folder where you see the '''linden''' folder), applying a patch can be done via:
| |
| | |
| c:\cygwin\bin\patch -p 0 -i changes.patch
| |
| | |
| or
| |
| | |
| c:\cygwin\bin\patch -p 0 < changes.patch
| |
| | |
| On your first attempts, you might also be interested in the '''--verbose''', '''--backup''' or '''--dry-run''' (simulate patch) options. See '''patch --help''' for details.
| |
| | |
| c:\cygwin\bin\patch -p 0 --verbose --backup --dry-run -i changes.patch
| |
| | |
| Also, if a patch fails, look for files ending with '''.rej''' in the target folder.
| |
If you have a piece of source code (be it a fix, new feature, or optimization of existing code) prepare your changes in a way that makes it easy for the Lindens to incorporate them into the source code.
Good Change Practice
General
It's easy for the people who review and apply changes to be the bottleneck in the system. If you can make it easier for Lindens to understand, test, and integrate your change, it is much better for everyone concerned.
Before You Start
- Understand and use the Project Snowstorm Processes; making sure that your change is part of the plan is the most important thing you can do to get it accepted.
Coding Standard
Please read and follow the coding standard: Second Life coding standard
Do not add issue numbers and your name to the code itself. While comments explaining code in a general working context are helpful and strongly encouraged, bracketing a change with comments like "// PATCH START" and "// PATCH END" does not add any information, and is likely to get your change returned for revision.
Do not comment out or use the preprocessor to disable code that you are replacing: just delete it. The source control system can find it again if we need it, and leaving dead code around makes things harder to read and much harder to search.
In short, make your change what is expected to appear in the final source.
Give Yourself Credit!
While names and JIRAs shouldn't appear in source, they do belong in doc/contributions.txt. Please don't be shy about adding the issue label and adding your name.
One Change for one Issue
Each submission should do exactly one thing. If you have three different bugs to fix, please submit three different change sets (unless they are very closely related and being treated as one item in the sprint). If you are unsure whether or not it is ok to combine changes into one submission, ask the Lindens.
Less is more
Smaller patches are easier to review and therefore more likely to be integrated quickly. This does not mean that you should omit comments or unit tests, however - adding to those is strongly encouraged.