• Immutable Page
  • Info
  • Attachments

Diff for "PatchTipsAndTricks"

Differences between revisions 3 and 4

Deletions are marked like this. Additions are marked like this.
Line 43: Line 43:
= Submitting a patchset =

Sometimes you need to send multiple related patches. This is useful for grouping, say, to group driver clean up patches for one particular driver into a set, or grouping patches that are part of a new feature into one set.

For example, take a look at this patch set:

 * [http://marc.info/?l=linux-doc&m=136604732318550&w=2 cover letter]
 * [http://marc.info/?l=linux-kernel&m=136604728318534&w=2 PATCH 1/7]
 * [http://marc.info/?l=linux-doc&m=136751167021547&w=2 PATCH 2/7]
 * [http://marc.info/?l=linux-doc&m=136751167021548&w=2 PATCH 3/7]
 * [http://marc.info/?l=linux-doc&m=136751167821552&w=2 PATCH 4/7]
 * [http://marc.info/?l=linux-doc&m=136751168121553&w=2 PATCH 5/7]
 * [http://marc.info/?l=linux-doc&m=136751168421557&w=2 PATCH 6/7]
 * [http://marc.info/?l=linux-doc&m=136751168521559&w=2 PATCH 7/7]

Typically, the subject prefix for patches in the patchset are [PATCH X/Y] or [RFC X/Y], where Y is the total number of patches, and X is the current patch number. Patchsets often have a "cover letter" that is [PATCH 0/Y] or [RFC 0/Y]. A cover letter is used to explain why the patchset is necessary, and provide an overview of the end result of the patches. Cover letters are also great places to ask for help in reviewing specific patches in the patchset.

In order to create patchsets like this, you will need to use either {{{`git send-email``}} or {{{`git format-patch`}}}. These tools will generate the right "In-Reply-To" Headers, so that in a text mail client, the patches will appear next to each other, rather than having unrelated email in between. Otherwise, patches may get jumbled, depending on when they were received.

== Using git format-patch to send patchsets ==

First, use {{{`git log --pretty=oneline --abbrev-commit`}}} to figure out the first commit ID you want to send. For example, say that my tree had this git log history:

b7ca36a Docs: Move ref to Frohwalt Egerer to end of REPORTING-BUGS
bf6adaf Docs: Add a tips section to REPORTING-BUGS.
bc6bed4 Docs: Expectations for bug reporters and maintainers
2c97a63 Docs: Add info on supported kernels to REPORTING-BUGS.
7883a25 Docs: Add "Gather info" section to REPORTING-BUGS.
d60418b Docs: Step-by-step directions for reporting bugs.
3b12c21 Trivial: docs: Remove six-space indentation in REPORTING-BUGS.
bb33db7 Merge branches 'timers-urgent-for-linus', 'irq-urgent-for-linus' and 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
41ef2d5 Linux 3.9-rc7

The first commit I want to send as part of the patchset has commit ID 3b12c21. The last patch I want to send has commit ID b7ca36a. So, I want to pass the commit range 3b12c21^..b7ca36a to {{{git format-patch}}}. (Remember, the {{{git format-patch}}} range starting commit must be the commit ''before'' the first commit you want to send, so we use the '^' to specify the patch before commit 3b12c21.) The command will look something like this:

git format-patch -o /tmp/ --cover-letter -n --thread=shallow --cc="linux-usb@vger.kernel.org" 3b12c21^..b7ca36a}}}

Again, the -o flag specifies where to put the email files. The -n flag says to add numbering to each patch (e.g. [PATCH 2/5]). The --thread=shallow flag specifies that all patches will be In-Reply-To your cover letter.

That will output files into /tmp, and you can edit them in mutt in multiple terminal tabs:

Patch subject prefixes

You can pass `git format-patch` a --subject-prefix="string" parameter. It sets the Subject line prefix (the text in the square brackets) to the string you specify. By default, it is set to "PATCH", and this will generate email with the Subject line "[PATCH] <git short description>". The git tools will ignore anything in square brackets, so you can put whatever you want in the subject prefix.

For example, if you're sending the second revision of a patch, you should use [PATCH v2]. And yes, some patchsets even get up to [PATCH v8].

Another common Subject prefix is "RFC". This stands for "Request for Comment", which tells maintainers should review your patch thoroughly, and provide feedback. RFC is typically used when sending feature patches for the first time, or anytime the patch is more than just a simple bug fix. Developers will often use [RFC v2] on the second revision of their feature patchset.

Tips for editing patch emails

In general, you should never edit the patch subject line (except the subject prefix in square brackets), and you should never edit the patch body or diff. If you need to do that, go back into git, and amend your commit. It is sloppy to edit patches in mutt, and will trip you up if you ever get to the stage of sending maintainers pull requests.

There are a couple places where it's okay to add extra text. You can edit an inline patch to add notes below the --- line. The git tools to apply the patch will ignore any text after the ---}, up to the start of the diff. This is useful for adding information to the maintainer that you don't necessarily need to include in the patch description. For example, if you're sending a second revision of a patch, you may want to type:

Signed-off-by: Your Name <my.email@gmail.com>

Changes since v2:
 * Made commit message more clear
 * Corrected grammer in code comment
 * Used new API instead of depreciated API


You can also add comments before the patch description by adding scissor lines. This is useful if you want to give comments to the maintainer, but your patch body is longer than one page (yes, this happens in good patch descriptions). Scissor lines look like this:

Subject: [PATCH] csr: Misc cleanups

Changes since v2:
 * Made commit message more clear
 * Corrected grammer in code comment
 * Used new API instead of depreciated API


Play around with these options if you want. Bonus points if you send your first patch to the opw-kernel mailing list using one of these options.

Dealing with tags

When submitting a patch or patchset, Linux kernel community members will often reply with a "Reviewed-by" tag. That tag means the developer has reviewed the code, and thinks it looks fine. When the maintainer picks that patch for the their tree, they will edit it to include that line, so that the reviewer gets credit (and blame, if the patch later has issues). Here's an example

If the maintainer applies the revision of the patch that the mentor added their Reviewed-by tag to, you don't have to do anything more with the tag.

However, sometimes a reviewer says the patch itself looks fine and adds their Reviewed-by tag, but also says you need to do a small fix, like change the subject line. If you need to send another revision of your patch, please make sure to include that Reviewed-by tag in your next patch version. That will ensure that the tags don't get lost and reviewers get proper credit.

Other tags you might see in community patches include "Suggested-by" (for saying someone suggested you make this change), "Reported-by" (to acknowledge people who report bugs), "Tested-by" (to indicate code was tested by a developer), and more.

Tell others about this page:

last edited 2014-02-27 23:33:42 by SarahSharp