1 _ _ ____ _ 2 ___| | | | _ \| | 3 / __| | | | |_) | | 4 | (__| |_| | _ <| |___ 5 \___|\___/|_| \_\_____| 6 7 When Contributing Source Code 8 9 This document is intended to offer guidelines that can be useful to keep in 10 mind when you decide to contribute to the project. This concerns new features 11 as well as corrections to existing flaws or bugs. 12 13 1. Learning cURL 14 1.1 Join the Community 15 1.2 License 16 1.3 What To Read 17 18 2. cURL Coding Standards 19 2.1 Naming 20 2.2 Indenting 21 2.3 Commenting 22 2.4 Line Lengths 23 2.5 General Style 24 2.6 Non-clobbering All Over 25 2.7 Platform Dependent Code 26 2.8 Write Separate Patches 27 2.9 Patch Against Recent Sources 28 2.10 Document 29 2.11 Test Cases 30 31 3. Pushing Out Your Changes 32 3.1 Write Access to git Repository 33 3.2 How To Make a Patch with git 34 3.3 How To Make a Patch without git 35 3.4 How to get your changes into the main sources 36 3.5 Write good commit messages 37 3.6 About pull requests 38 39============================================================================== 40 411. Learning cURL 42 431.1 Join the Community 44 45 Skip over to http://curl.haxx.se/mail/ and join the appropriate mailing 46 list(s). Read up on details before you post questions. Read this file before 47 you start sending patches! We prefer patches and discussions being held on 48 the mailing list(s), not sent to individuals. 49 50 Before posting to one of the curl mailing lists, please read up on the mailing 51 list etiquette: http://curl.haxx.se/mail/etiquette.html 52 53 We also hang out on IRC in #curl on irc.freenode.net 54 55 If you're at all interested in the code side of things, consider clicking 56 'watch' on the curl repo at github to get notified on pull requests and new 57 issues posted there. 58 591.2. License 60 61 When contributing with code, you agree to put your changes and new code under 62 the same license curl and libcurl is already using unless stated and agreed 63 otherwise. 64 65 If you add a larger piece of code, you can opt to make that file or set of 66 files to use a different license as long as they don't enforce any changes to 67 the rest of the package and they make sense. Such "separate parts" can not be 68 GPL licensed (as we don't want copyleft to affect users of libcurl) but they 69 must use "GPL compatible" licenses (as we want to allow users to use libcurl 70 properly in GPL licensed environments). 71 72 When changing existing source code, you do not alter the copyright of the 73 original file(s). The copyright will still be owned by the original 74 creator(s) or those who have been assigned copyright by the original 75 author(s). 76 77 By submitting a patch to the curl project, you are assumed to have the right 78 to the code and to be allowed by your employer or whatever to hand over that 79 patch/code to us. We will credit you for your changes as far as possible, to 80 give credit but also to keep a trace back to who made what changes. Please 81 always provide us with your full real name when contributing! 82 831.3 What To Read 84 85 Source code, the man pages, the INTERNALS document, TODO, KNOWN_BUGS and the 86 most recent changes in the git log. Just lurking on the curl-library mailing 87 list is gonna give you a lot of insights on what's going on right now. Asking 88 there is a good idea too. 89 902. cURL Coding Standards 91 922.1 Naming 93 94 Try using a non-confusing naming scheme for your new functions and variable 95 names. It doesn't necessarily have to mean that you should use the same as in 96 other places of the code, just that the names should be logical, 97 understandable and be named according to what they're used for. File-local 98 functions should be made static. We like lower case names. 99 100 See the INTERNALS document on how we name non-exported library-global 101 symbols. 102 1032.2 Indenting 104 105 Use the same indenting levels and bracing method as all the other code 106 already does. It makes the source code easier to follow if all of it is 107 written using the same style. We don't ask you to like it, we just ask you to 108 follow the tradition! ;-) This mainly means: 2-level indents, using spaces 109 only (no tabs) and having the opening brace ({) on the same line as the if() 110 or while(). 111 112 Also note that we use if() and while() with no space before the parenthesis. 113 1142.3 Commenting 115 116 Comment your source code extensively using C comments (/* comment */), DO NOT 117 use C++ comments (// this style). Commented code is quality code and enables 118 future modifications much more. Uncommented code risk having to be completely 119 replaced when someone wants to extend things, since other persons' source 120 code can get quite hard to read. 121 1222.4 Line Lengths 123 124 We write source lines shorter than 80 columns. 125 1262.5 General Style 127 128 Keep your functions small. If they're small you avoid a lot of mistakes and 129 you don't accidentally mix up variables etc. 130 1312.6 Non-clobbering All Over 132 133 When you write new functionality or fix bugs, it is important that you don't 134 fiddle all over the source files and functions. Remember that it is likely 135 that other people have done changes in the same source files as you have and 136 possibly even in the same functions. If you bring completely new 137 functionality, try writing it in a new source file. If you fix bugs, try to 138 fix one bug at a time and send them as separate patches. 139 1402.7 Platform Dependent Code 141 142 Use #ifdef HAVE_FEATURE to do conditional code. We avoid checking for 143 particular operating systems or hardware in the #ifdef lines. The 144 HAVE_FEATURE shall be generated by the configure script for unix-like systems 145 and they are hard-coded in the config-[system].h files for the others. 146 1472.8 Write Separate Patches 148 149 It is annoying when you get a huge patch from someone that is said to fix 511 150 odd problems, but discussions and opinions don't agree with 510 of them - or 151 509 of them were already fixed in a different way. Then the patcher needs to 152 extract the single interesting patch from somewhere within the huge pile of 153 source, and that gives a lot of extra work. Preferably, all fixes that 154 correct different problems should be in their own patch with an attached 155 description exactly what they correct so that all patches can be selectively 156 applied by the maintainer or other interested parties. 157 158 Also, separate patches enable bisecting much better when we track problems in 159 the future. 160 1612.9 Patch Against Recent Sources 162 163 Please try to get the latest available sources to make your patches 164 against. It makes the life of the developers so much easier. The very best is 165 if you get the most up-to-date sources from the git repository, but the 166 latest release archive is quite OK as well! 167 1682.10 Document 169 170 Writing docs is dead boring and one of the big problems with many open source 171 projects. Someone's gotta do it. It makes it a lot easier if you submit a 172 small description of your fix or your new features with every contribution so 173 that it can be swiftly added to the package documentation. 174 175 The documentation is always made in man pages (nroff formatted) or plain 176 ASCII files. All HTML files on the web site and in the release archives are 177 generated from the nroff/ASCII versions. 178 1792.11 Test Cases 180 181 Since the introduction of the test suite, we can quickly verify that the main 182 features are working as they're supposed to. To maintain this situation and 183 improve it, all new features and functions that are added need to be tested 184 in the test suite. Every feature that is added should get at least one valid 185 test case that verifies that it works as documented. If every submitter also 186 posts a few test cases, it won't end up as a heavy burden on a single person! 187 188 If you don't have test cases or perhaps you have done something that is very 189 hard to write tests for, do explain exactly how you have otherwise tested and 190 verified your changes. 191 1923. Pushing Out Your Changes 193 1943.1 Write Access to git Repository 195 196 If you are a frequent contributor, or have another good reason, you can of 197 course get write access to the git repository and then you'll be able to push 198 your changes straight into the git repo instead of sending changes by mail as 199 patches. Just ask if this is what you'd want. You will be required to have 200 posted a few quality patches first, before you can be granted push access. 201 2023.2 How To Make a Patch with git 203 204 You need to first checkout the repository: 205 206 git clone https://github.com/bagder/curl.git 207 208 You then proceed and edit all the files you like and you commit them to your 209 local repository: 210 211 git commit [file] 212 213 As usual, group your commits so that you commit all changes that at once that 214 constitutes a logical change. See also section "3.5 Write good commit 215 messages". 216 217 Once you have done all your commits and you're happy with what you see, you 218 can make patches out of your changes that are suitable for mailing: 219 220 git format-patch remotes/origin/master 221 222 This creates files in your local directory named NNNN-[name].patch for each 223 commit. 224 225 Now send those patches off to the curl-library list. You can of course opt to 226 do that with the 'git send-email' command. 227 2283.3 How To Make a Patch without git 229 230 Keep a copy of the unmodified curl sources. Make your changes in a separate 231 source tree. When you think you have something that you want to offer the 232 curl community, use GNU diff to generate patches. 233 234 If you have modified a single file, try something like: 235 236 diff -u unmodified-file.c my-changed-one.c > my-fixes.diff 237 238 If you have modified several files, possibly in different directories, you 239 can use diff recursively: 240 241 diff -ur curl-original-dir curl-modified-sources-dir > my-fixes.diff 242 243 The GNU diff and GNU patch tools exist for virtually all platforms, including 244 all kinds of Unixes and Windows: 245 246 For unix-like operating systems: 247 248 https://savannah.gnu.org/projects/patch/ 249 https://www.gnu.org/software/diffutils/ 250 251 For Windows: 252 253 http://gnuwin32.sourceforge.net/packages/patch.htm 254 http://gnuwin32.sourceforge.net/packages/diffutils.htm 255 2563.4 How to get your changes into the main sources 257 258 Submit your patch to the curl-library mailing list. 259 260 Make the patch against as recent sources as possible. 261 262 Make sure your patch adheres to the source indent and coding style of already 263 existing source code. Failing to do so just adds more work for me. 264 265 Respond to replies on the list about the patch and answer questions and/or 266 fix nits/flaws. This is very important. I will take lack of replies as a sign 267 that you're not very anxious to get your patch accepted and I tend to simply 268 drop such patches from my TODO list. 269 270 If you've followed the above paragraphs and your patch still hasn't been 271 incorporated after some weeks, consider resubmitting it to the list. 272 2733.5 Write good commit messages 274 275 A short guide to how to do fine commit messages in the curl project. 276 277 ---- start ---- 278 [area]: [short line describing the main effect] 279 280 [separate the above single line from the rest with an empty line] 281 282 [full description, no wider than 72 columns that describe as much as 283 possible as to why this change is made, and possibly what things 284 it fixes and everything else that is related] 285 286 [Bug: link to source of the report or more related discussion] 287 [Reported-by: John Doe - credit the reporter] 288 [whatever-else-by: credit all helpers, finders, doers] 289 ---- stop ---- 290 291 Don't forget to use commit --author="" if you commit someone else's work, 292 and make sure that you have your own user and email setup correctly in git 293 before you commit 294 2953.6 About pull requests 296 297 With git (and especially github) it is easy and tempting to send a pull 298 request to the curl project to have changes merged this way instead of 299 mailing patches to the curl-library mailing list. 300 301 We used to dislike this but we're trying to change that and accept that this 302 is a frictionless way for people to contribute to the project. We now welcome 303 pull requests! 304 305 We will continue to avoid using github's merge tools to make the history 306 linear and to make sure commits follow our style guidelines. 307