What’s the right way to fork/re-use code from an open source project

copyrightlicensingopen source

Let's say I am working on an open source project and want to re-use a trivial utility function from another open source project (for example, a file search/replace function). Is it legal to copy the function and simply write a small copyright notice in top of the file? Should I include their name as copyright holders of the entire project in the license?

Similarly, let's say I fork an open source project. Where and how do I specify that the copyright is shared between both the original copyright holder and myself?

I guess the answer must somewhat vary according to the open source license but I'd like a general answer as much as possible.

PS: I'm mostly concerned about the legal aspect, but feel free to include your ethical point of view.

Best Answer

I'm trying to make this answer as 'meta' applicable as possible.

Using snippets / bits from other projects

Clearly mark the code with the original author's copyright. Make sure that your license of choice is fully compatible with the license of the code you are using. You will need permission of the author to move the code to a different license (unless they specifically allow you to do so, I.e. "GPL 2 or any later version")

Your program should have an AUTHORS file (or similar), where you list all contributors and things that you used from other projects.

Forking a project

For each module that you substantially change, add your copyright under the original author's. The same thing goes for licensing, you are bound by the terms of the license that was in effect when you forked it. If the project says "GPL2 only", you must respect that, you can't go to GPL3 without their permission.

This varies, greatly, depending on the license at hand. The QPL says you can only distribute changes in patch format, for instance, so make sure you understand the terms that allow you to distribute modified versions of the software.

Beyond that, always preserve copyright. If adding your own copyright to what exists, be sure that you clearly mark exactly what you are claiming.