1.. SPDX-License-Identifier: GPL-2.0+ 2.. Copyright (c) 2011 The Chromium OS Authors 3.. Simon Glass <sjg@chromium.org> 4.. Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com> 5.. v1, v2, 19-Oct-11 6.. revised v3 24-Nov-11 7.. revised v4 Independence Day 2020, with Patchwork integration 8 9Patman patch manager 10==================== 11 12This tool is a Python script which: 13 14- Creates patch directly from your branch 15- Cleans them up by removing unwanted tags 16- Inserts a cover letter with change lists 17- Runs the patches through checkpatch.pl and its own checks 18- Optionally emails them out to selected people 19 20It also has some Patchwork features: 21 22- shows review tags from Patchwork so you can update your local patches 23- pulls these down into a new branch on request 24- lists comments received on a series 25 26It is intended to automate patch creation and make it a less 27error-prone process. It is useful for U-Boot and Linux work so far, 28since they use the checkpatch.pl script. 29 30It is configured almost entirely by tags it finds in your commits. 31This means that you can work on a number of different branches at 32once, and keep the settings with each branch rather than having to 33git format-patch, git send-email, etc. with the correct parameters 34each time. So for example if you put:: 35 36 Series-to: fred.blogs@napier.co.nz 37 38in one of your commits, the series will be sent there. 39 40In Linux and U-Boot this will also call get_maintainer.pl on each of your 41patches automatically (unless you use -m to disable this). 42 43 44Installation 45------------ 46 47You can install patman using:: 48 49 pip install patch-manager 50 51The name is chosen since patman conflicts with an existing package. 52 53If you are using patman within the U-Boot tree, it may be easiest to add a 54symlink from your local `~/.bin` directory to `/path/to/tools/patman/patman`. 55 56How to use this tool 57-------------------- 58 59This tool requires a certain way of working: 60 61- Maintain a number of branches, one for each patch series you are 62 working on 63- Add tags into the commits within each branch to indicate where the 64 series should be sent, cover letter, version, etc. Most of these are 65 normally in the top commit so it is easy to change them with 'git 66 commit --amend' 67- Each branch tracks the upstream branch, so that this script can 68 automatically determine the number of commits in it (optional) 69- Check out a branch, and run this script to create and send out your 70 patches. Weeks later, change the patches and repeat, knowing that you 71 will get a consistent result each time. 72 73 74How to configure it 75------------------- 76 77For most cases of using patman for U-Boot development, patman can use the 78file 'doc/git-mailrc' in your U-Boot directory to supply the email aliases 79you need. To make this work, tell git where to find the file by typing 80this once:: 81 82 git config sendemail.aliasesfile doc/git-mailrc 83 84For both Linux and U-Boot the 'scripts/get_maintainer.pl' handles 85figuring out where to send patches pretty well. For other projects, 86you may want to specify a different script to be run, for example via 87a project-specific `.patman` file:: 88 89 # .patman configuration file at the root of some project 90 91 [settings] 92 get_maintainer_script: etc/teams.scm get-maintainer 93 94The `get_maintainer_script` option corresponds to the 95`--get-maintainer-script` argument of the `send` command. It is 96looked relatively to the root of the current git repository, as well 97as on PATH. It can also be provided arguments, as shown above. The 98contract is that the script should accept a patch file name and return 99a list of email addresses, one per line, like `get_maintainer.pl` 100does. 101 102During the first run patman creates a config file for you by taking the default 103user name and email address from the global .gitconfig file. 104 105To add your own, create a file `~/.patman` like this:: 106 107 # patman alias file 108 109 [alias] 110 me: Simon Glass <sjg@chromium.org> 111 112 u-boot: U-Boot Mailing List <u-boot@lists.denx.de> 113 wolfgang: Wolfgang Denk <wd@denx.de> 114 others: Mike Frysinger <vapier@gentoo.org>, Fred Bloggs <f.bloggs@napier.net> 115 116As hinted above, Patman will also look for a `.patman` configuration 117file at the root of the current project git repository, which makes it 118possible to override the `project` settings variable or anything else 119in a project-specific way. The values of this "local" configuration 120file take precedence over those of the "global" one. 121 122Aliases are recursive. 123 124The checkpatch.pl in the U-Boot tools/ subdirectory will be located and 125used. Failing that you can put it into your path or ~/bin/checkpatch.pl 126 127If you want to avoid sending patches to email addresses that are picked up 128by patman but are known to bounce you can add a [bounces] section to your 129.patman file. Unlike the [alias] section these are simple key: value pairs 130that are not recursive:: 131 132 [bounces] 133 gonefishing: Fred Bloggs <f.bloggs@napier.net> 134 135 136If you want to change the defaults for patman's command-line arguments, 137you can add a [settings] section to your .patman file. This can be used 138for any command line option by referring to the "dest" for the option in 139patman.py. For reference, the useful ones (at the moment) shown below 140(all with the non-default setting):: 141 142 [settings] 143 ignore_errors: True 144 process_tags: False 145 verbose: True 146 smtp_server: /path/to/sendmail 147 patchwork_server: https://patchwork.ozlabs.org 148 149If you want to adjust settings (or aliases) that affect just a single 150project you can add a section that looks like [project_settings] or 151[project_alias]. If you want to use tags for your linux work, you could do:: 152 153 [linux_settings] 154 process_tags: True 155 156 157How to run it 158------------- 159 160First do a dry run: 161 162.. code-block:: bash 163 164 ./tools/patman/patman send -n 165 166If it can't detect the upstream branch, try telling it how many patches 167there are in your series 168 169.. code-block:: bash 170 171 ./tools/patman/patman -c5 send -n 172 173This will create patch files in your current directory and tell you who 174it is thinking of sending them to. Take a look at the patch files: 175 176.. code-block:: bash 177 178 ./tools/patman/patman -c5 -s1 send -n 179 180Similar to the above, but skip the first commit and take the next 5. This 181is useful if your top commit is for setting up testing. 182 183 184How to install it 185----------------- 186 187The most up to date version of patman can be found in the U-Boot sources. 188However to use it on other projects it may be more convenient to install it as 189a standalone application. A distutils installer is included, this can be used 190to install patman: 191 192.. code-block:: bash 193 194 cd tools/patman && python setup.py install 195 196 197How to add tags 198--------------- 199 200To make this script useful you must add tags like the following into any 201commit. Most can only appear once in the whole series. 202 203Series-to: email / alias 204 Email address / alias to send patch series to (you can add this 205 multiple times) 206 207Series-cc: email / alias, ... 208 Email address / alias to Cc patch series to (you can add this 209 multiple times) 210 211Series-version: n 212 Sets the version number of this patch series 213 214Series-prefix: prefix 215 Sets the subject prefix. Normally empty but it can be RFC for 216 RFC patches, or RESEND if you are being ignored. The patch subject 217 is like [RFC PATCH] or [RESEND PATCH]. 218 In the meantime, git format.subjectprefix option will be added as 219 well. If your format.subjectprefix is set to InternalProject, then 220 the patch shows like: [InternalProject][RFC/RESEND PATCH] 221 222Series-postfix: postfix 223 Sets the subject "postfix". Normally empty, but can be the name of a 224 tree such as net or net-next if that needs to be specified. The patch 225 subject is like [PATCH net] or [PATCH net-next]. 226 227Series-name: name 228 Sets the name of the series. You don't need to have a name, and 229 patman does not yet use it, but it is convenient to put the branch 230 name here to help you keep track of multiple upstreaming efforts. 231 232Series-links: [id | version:id]... 233 Set the ID of the series in patchwork. You can set this after you send 234 out the series and look in patchwork for the resulting series. The 235 URL you want is the one for the series itself, not any particular patch. 236 E.g. for http://patchwork.ozlabs.org/project/uboot/list/?series=187331 237 the series ID is 187331. This property can have a list of series IDs, 238 one for each version of the series, e.g. 239 240 :: 241 242 Series-links: 1:187331 2:188434 189372 243 244 Patman always uses the one without a version, since it assumes this is 245 the latest one. When this tag is provided, patman can compare your local 246 branch against patchwork to see what new reviews your series has 247 collected ('patman status'). 248 249Series-patchwork-url: url 250 This allows specifying the Patchwork URL for a branch. This overrides 251 both the setting files and the command-line argument. The URL should 252 include the protocol and web site, with no trailing slash, for example 253 'https://patchwork.ozlabs.org/project' 254 255Cover-letter: 256 Sets the cover letter contents for the series. The first line 257 will become the subject of the cover letter:: 258 259 Cover-letter: 260 This is the patch set title 261 blah blah 262 more blah blah 263 END 264 265Cover-letter-cc: email / alias 266 Additional email addresses / aliases to send cover letter to (you 267 can add this multiple times) 268 269Series-notes: 270 Sets some notes for the patch series, which you don't want in 271 the commit messages, but do want to send, The notes are joined 272 together and put after the cover letter. Can appear multiple 273 times:: 274 275 Series-notes: 276 blah blah 277 blah blah 278 more blah blah 279 END 280 281Commit-notes: 282 Similar, but for a single commit (patch). These notes will appear 283 immediately below the --- cut in the patch file:: 284 285 Commit-notes: 286 blah blah 287 blah blah 288 more blah blah 289 290Signed-off-by: Their Name <email> 291 A sign-off is added automatically to your patches (this is 292 probably a bug). If you put this tag in your patches, it will 293 override the default signoff that patman automatically adds. 294 Multiple duplicate signoffs will be removed. 295 296Tested-by / Reviewed-by / Acked-by 297 These indicate that someone has tested/reviewed/acked your patch. 298 When you get this reply on the mailing list, you can add this 299 tag to the relevant commit and the script will include it when 300 you send out the next version. If 'Tested-by:' is set to 301 yourself, it will be removed. No one will believe you. 302 303 Example:: 304 305 Tested-by: Their Name <fred@bloggs.com> 306 Reviewed-by: Their Name <email> 307 Acked-by: Their Name <email> 308 309Series-changes: n 310 This can appear in any commit. It lists the changes for a 311 particular version n of that commit. The change list is 312 created based on this information. Each commit gets its own 313 change list and also the whole thing is repeated in the cover 314 letter (where duplicate change lines are merged). 315 316 By adding your change lists into your commits it is easier to 317 keep track of what happened. When you amend a commit, remember 318 to update the log there and then, knowing that the script will 319 do the rest. 320 321 Example:: 322 323 Series-changes: n 324 - Guinea pig moved into its cage 325 - Other changes ending with a blank line 326 <blank line> 327 328Commit-changes: n 329 This tag is like Series-changes, except changes in this changelog will 330 only appear in the changelog of the commit this tag is in. This is 331 useful when you want to add notes which may not make sense in the cover 332 letter. For example, you can have short changes such as "New" or 333 "Lint". 334 335 Example:: 336 337 Commit-changes: n 338 - This line will not appear in the cover-letter changelog 339 <blank line> 340 341Cover-changes: n 342 This tag is like Series-changes, except changes in this changelog will 343 only appear in the cover-letter changelog. This is useful to summarize 344 changes made with Commit-changes, or to add additional context to 345 changes. 346 347 Example:: 348 349 Cover-changes: n 350 - This line will only appear in the cover letter 351 <blank line> 352 353Patch-cc: Their Name <email> 354 This copies a single patch to another email address. Note that the 355 Cc: used by git send-email is ignored by patman, but will be 356 interpreted by git send-email if you use it. 357 358Series-process-log: sort, uniq 359 This tells patman to sort and/or uniq the change logs. Changes may be 360 multiple lines long, as long as each subsequent line of a change begins 361 with a whitespace character. For example, 362 363 Example:: 364 365 - This change 366 continues onto the next line 367 - But this change is separate 368 369 Use 'sort' to sort the entries, and 'uniq' to include only 370 unique entries. If omitted, no change log processing is done. 371 Separate each tag with a comma. 372 373Change-Id: 374 This tag is stripped out but is used to generate the Message-Id 375 of the emails that will be sent. When you keep the Change-Id the 376 same you are asserting that this is a slightly different version 377 (but logically the same patch) as other patches that have been 378 sent out with the same Change-Id. 379 380Various other tags are silently removed, like these Chrome OS and 381Gerrit tags:: 382 383 BUG=... 384 TEST=... 385 Review URL: 386 Reviewed-on: 387 Commit-xxxx: (except Commit-notes) 388 389Exercise for the reader: Try adding some tags to one of your current 390patch series and see how the patches turn out. 391 392 393Where Patches Are Sent 394---------------------- 395 396Once the patches are created, patman sends them using git send-email. The 397whole series is sent to the recipients in Series-to: and Series-cc. 398You can Cc individual patches to other people with the Patch-cc: tag. Tags 399in the subject are also picked up to Cc patches. For example, a commit like 400this:: 401 402 commit 10212537b85ff9b6e09c82045127522c0f0db981 403 Author: Mike Frysinger <vapier@gentoo.org> 404 Date: Mon Nov 7 23:18:44 2011 -0500 405 406 x86: arm: add a git mailrc file for maintainers 407 408 This should make sending out e-mails to the right people easier. 409 410 Patch-cc: sandbox, mikef, ag 411 Patch-cc: afleming 412 413will create a patch which is copied to x86, arm, sandbox, mikef, ag and 414afleming. 415 416If you have a cover letter it will get sent to the union of the Patch-cc 417lists of all of the other patches. If you want to sent it to additional 418people you can add a tag:: 419 420 Cover-letter-cc: <list of addresses> 421 422These people will get the cover letter even if they are not on the To/Cc 423list for any of the patches. 424 425 426Patchwork Integration 427--------------------- 428 429Patman has a very basic integration with Patchwork. If you point patman to 430your series on patchwork it can show you what new reviews have appeared since 431you sent your series. 432 433To set this up, add a Series-link tag to one of the commits in your series 434(see above). 435 436Then you can type: 437 438.. code-block:: bash 439 440 patman status 441 442and patman will show you each patch and what review tags have been collected, 443for example:: 444 445 ... 446 21 x86: mtrr: Update the command to use the new mtrr 447 Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> 448 + Reviewed-by: Bin Meng <bmeng.cn@gmail.com> 449 22 x86: mtrr: Restructure so command execution is in 450 Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> 451 + Reviewed-by: Bin Meng <bmeng.cn@gmail.com> 452 ... 453 454This shows that patch 21 and 22 were sent out with one review but have since 455attracted another review each. If the series needs changes, you can update 456these commits with the new review tag before sending the next version of the 457series. 458 459To automatically pull into these tags into a new branch, use the -d option: 460 461.. code-block:: bash 462 463 patman status -d mtrr4 464 465This will create a new 'mtrr4' branch which is the same as your current branch 466but has the new review tags in it. The tags are added in alphabetic order and 467are placed immediately after any existing ack/review/test/fixes tags, or at the 468end. You can check that this worked with: 469 470.. code-block:: bash 471 472 patman -b mtrr4 status 473 474which should show that there are no new responses compared to this new branch. 475 476There is also a -C option to list the comments received for each patch. 477 478 479Example Work Flow 480----------------- 481 482The basic workflow is to create your commits, add some tags to the top 483commit, and type 'patman' to check and send them. 484 485Here is an example workflow for a series of 4 patches. Let's say you have 486these rather contrived patches in the following order in branch us-cmd in 487your tree where 'us' means your upstreaming activity (newest to oldest as 488output by git log --oneline):: 489 490 7c7909c wip 491 89234f5 Don't include standard parser if hush is used 492 8d640a7 mmc: sparc: Stop using builtin_run_command() 493 0c859a9 Rename run_command2() to run_command() 494 a74443f sandbox: Rename run_command() to builtin_run_command() 495 496The first patch is some test things that enable your code to be compiled, 497but that you don't want to submit because there is an existing patch for it 498on the list. So you can tell patman to create and check some patches 499(skipping the first patch) with: 500 501.. code-block:: bash 502 503 patman -s1 send -n 504 505If you want to do all of them including the work-in-progress one, then 506(if you are tracking an upstream branch): 507 508.. code-block:: bash 509 510 patman send -n 511 512Let's say that patman reports an error in the second patch. Then: 513 514.. code-block:: bash 515 516 git rebase -i HEAD~6 517 # change 'pick' to 'edit' in 89234f5 518 # use editor to make code changes 519 git add -u 520 git rebase --continue 521 522Now you have an updated patch series. To check it: 523 524.. code-block:: bash 525 526 patman -s1 send -n 527 528Let's say it is now clean and you want to send it. Now you need to set up 529the destination. So amend the top commit with: 530 531.. code-block:: bash 532 533 git commit --amend 534 535Use your editor to add some tags, so that the whole commit message is:: 536 537 The current run_command() is really only one of the options, with 538 hush providing the other. It really shouldn't be called directly 539 in case the hush parser is bring used, so rename this function to 540 better explain its purpose:: 541 542 Series-to: u-boot 543 Series-cc: bfin, marex 544 Series-prefix: RFC 545 Cover-letter: 546 Unified command execution in one place 547 548 At present two parsers have similar code to execute commands. Also 549 cmd_usage() is called all over the place. This series adds a single 550 function which processes commands called cmd_process(). 551 END 552 553 Change-Id: Ica71a14c1f0ecb5650f771a32fecb8d2eb9d8a17 554 555 556You want this to be an RFC and Cc the whole series to the bfin alias and 557to Marek. Two of the patches have tags (those are the bits at the front of 558the subject that say mmc: sparc: and sandbox:), so 8d640a7 will be Cc'd to 559mmc and sparc, and the last one to sandbox. 560 561Now to send the patches, take off the -n flag: 562 563.. code-block:: bash 564 565 patman -s1 send 566 567The patches will be created, shown in your editor, and then sent along with 568the cover letter. Note that patman's tags are automatically removed so that 569people on the list don't see your secret info. 570 571Of course patches often attract comments and you need to make some updates. 572Let's say one person sent comments and you get an Acked-by: on one patch. 573Also, the patch on the list that you were waiting for has been merged, 574so you can drop your wip commit. 575 576Take a look on patchwork and find out the URL of the series. This will be 577something like `http://patchwork.ozlabs.org/project/uboot/list/?series=187331` 578Add this to a tag in your top commit:: 579 580 Series-links: 187331 581 582You can use then patman to collect the Acked-by tag to the correct commit, 583creating a new 'version 2' branch for us-cmd: 584 585.. code-block:: bash 586 587 patman status -d us-cmd2 588 git checkout us-cmd2 589 590You can look at the comments in Patchwork or with: 591 592.. code-block:: bash 593 594 patman status -C 595 596Then you can resync with upstream: 597 598.. code-block:: bash 599 600 git fetch origin # or whatever upstream is called 601 git rebase origin/master 602 603and use git rebase -i to edit the commits, dropping the wip one. 604 605Then update the `Series-cc:` in the top commit to add the person who reviewed 606the v1 series:: 607 608 Series-cc: bfin, marex, Heiko Schocher <hs@denx.de> 609 610and remove the Series-prefix: tag since it it isn't an RFC any more. The 611series is now version two, so the series info in the top commit looks like 612this:: 613 614 Series-to: u-boot 615 Series-cc: bfin, marex, Heiko Schocher <hs@denx.de> 616 Series-version: 2 617 Cover-letter: 618 ... 619 620Finally, you need to add a change log to the two commits you changed. You 621add change logs to each individual commit where the changes happened, like 622this:: 623 624 Series-changes: 2 625 - Updated the command decoder to reduce code size 626 - Wound the torque propounder up a little more 627 628(note the blank line at the end of the list) 629 630When you run patman it will collect all the change logs from the different 631commits and combine them into the cover letter, if you have one. So finally 632you have a new series of commits:: 633 634 faeb973 Don't include standard parser if hush is used 635 1b2f2fe mmc: sparc: Stop using builtin_run_command() 636 cfbe330 Rename run_command2() to run_command() 637 0682677 sandbox: Rename run_command() to builtin_run_command() 638 639so to send them: 640 641.. code-block:: bash 642 643 patman 644 645and it will create and send the version 2 series. 646 647 648General points 649-------------- 650 651#. When you change back to the us-cmd branch days or weeks later all your 652 information is still there, safely stored in the commits. You don't need 653 to remember what version you are up to, who you sent the last lot of patches 654 to, or anything about the change logs. 655#. If you put tags in the subject, patman will Cc the maintainers 656 automatically in many cases. 657#. If you want to keep the commits from each series you sent so that you can 658 compare change and see what you did, you can either create a new branch for 659 each version, or just tag the branch before you start changing it: 660 661 .. code-block:: bash 662 663 git tag sent/us-cmd-rfc 664 # ...later... 665 git tag sent/us-cmd-v2 666 667#. If you want to modify the patches a little before sending, you can do 668 this in your editor, but be careful! 669#. If you want to run git send-email yourself, use the -n flag which will 670 print out the command line patman would have used. 671#. It is a good idea to add the change log info as you change the commit, 672 not later when you can't remember which patch you changed. You can always 673 go back and change or remove logs from commits. 674#. Some mailing lists have size limits and when we add binary contents to 675 our patches it's easy to exceed the size limits. Use "--no-binary" to 676 generate patches without any binary contents. You are supposed to include 677 a link to a git repository in your "Commit-notes", "Series-notes" or 678 "Cover-letter" for maintainers to fetch the original commit. 679#. Patches will have no changelog entries for revisions where they did not 680 change. For clarity, if there are no changes for this patch in the most 681 recent revision of the series, a note will be added. For example, a patch 682 with the following tags in the commit:: 683 684 Series-version: 5 685 Series-changes: 2 686 - Some change 687 688 Series-changes: 4 689 - Another change 690 691 would have a changelog of::: 692 693 (no changes since v4) 694 695 Changes in v4: 696 - Another change 697 698 Changes in v2: 699 - Some change 700 701 702Other thoughts 703-------------- 704 705This script has been split into sensible files but still needs work. 706Most of these are indicated by a TODO in the code. 707 708It would be nice if this could handle the In-reply-to side of things. 709 710The tests are incomplete, as is customary. Use the 'test' subcommand to run 711them: 712 713.. code-block:: bash 714 715 $ tools/patman/patman test 716 717Note that since the test suite depends on data files only available in 718the git checkout, the `test` command is hidden unless `patman` is 719invoked from the U-Boot git repository. 720 721Alternatively, you can run the test suite via Pytest: 722 723.. code-block:: bash 724 725 $ cd tools/patman && pytest 726 727Error handling doesn't always produce friendly error messages - e.g. 728putting an incorrect tag in a commit may provide a confusing message. 729 730There might be a few other features not mentioned in this README. They 731might be bugs. In particular, tags are case sensitive which is probably 732a bad thing. 733