Skip to contentSkip to conversation

Add a tool to simplify patch checking and posting (patman)

PATCH In review Simon Glass 3 participants 10 messages May 3, 2015

lore
Share & tools
lore
#0 lore raw

cover Add a tool to simplify patch checking and posting (patman)

Preparing, checking and sending patches to a mailing list is a tedious and error-prone process. Dealing with multiple series, each which its own revision history, CC list, cover letter requires concentation. Mistakes are easy to make.

This tool aims to help with this. A single command generates the patch series, runs it through checkpatch, generates the cover letter, adds a change list to each patch and the cover letter, determines who should receive the patch and Ccs people on the patch either using maintainer information or tags in the commit subject. A dry-run mode allows output to be checked.

This tool makes patch series repeatable, since everything needed to create and send patches in stored in the git branch containing that series. When making a change to one commit you can update the change log in that commit and know that everything will turn out OK.

Specifically this tool is a Python script which (from the README):
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

It is intended to automate patch creation and make it a less error-prone process. It is useful for U-Boot and Linux work so far, since it uses the checkpatch.pl script.

It is configured almost entirely by tags it finds in your commits. This means that you can work on a number of different branches at once, and keep the settings with each branch rather than having to git format-patch, git send-email, etc. with the correct parameters each time. So for example if you put:

Series-to: [email protected]

in one of your commits, the series will be sent there.

In Linux and U-Boot this will also call get_maintainer.pl on each of your patches automatically (unless you use -m to disable this).

I am submitting this to LKML to raise awareness, since those who are not involved in U-Boot probably don't know about it. I could not find a specific linux-tools list but may have missed something.

Simon Glass (3):
Add patman patch automation script
Add tests for patman
Add documentation for patman

 MAINTAINERS                     |   5 +
 tools/patman/.gitignore         |   1 +
 tools/patman/README             | 475 ++++++++++++++++++++++++++++++++
 tools/patman/checkpatch.py      | 173 ++++++++++++
 tools/patman/command.py         | 123 +++++++++
 tools/patman/commit.py          |  88 ++++++
 tools/patman/cros_subprocess.py | 397 +++++++++++++++++++++++++++
 tools/patman/get_maintainer.py  |  47 ++++
 tools/patman/gitutil.py         | 582 ++++++++++++++++++++++++++++++++++++++++
 tools/patman/patchstream.py     | 488 +++++++++++++++++++++++++++++++++
 tools/patman/patman             |   1 +
 tools/patman/patman.py          | 167 ++++++++++++
 tools/patman/project.py         |  27 ++
 tools/patman/series.py          | 271 +++++++++++++++++++
 tools/patman/settings.py        | 295 ++++++++++++++++++++
 tools/patman/terminal.py        | 158 +++++++++++
 tools/patman/test.py            | 243 +++++++++++++++++
 17 files changed, 3541 insertions(+)
 create mode 100644 tools/patman/.gitignore
 create mode 100644 tools/patman/README
 create mode 100644 tools/patman/checkpatch.py
 create mode 100644 tools/patman/command.py
 create mode 100644 tools/patman/commit.py
 create mode 100644 tools/patman/cros_subprocess.py
 create mode 100644 tools/patman/get_maintainer.py
 create mode 100644 tools/patman/gitutil.py
 create mode 100644 tools/patman/patchstream.py
 create mode 120000 tools/patman/patman
 create mode 100755 tools/patman/patman.py
 create mode 100644 tools/patman/project.py
 create mode 100644 tools/patman/series.py
 create mode 100644 tools/patman/settings.py
 create mode 100644 tools/patman/terminal.py
 create mode 100644 tools/patman/test.py
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH 1/3 Add patman patch automation script

This tool is a Python script which:
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

Add the main part of the code, excluding tests and documentation.

---

 tools/patman/.gitignore         |   1 +
 tools/patman/checkpatch.py      | 173 ++++++++++++
 tools/patman/command.py         | 123 +++++++++
 tools/patman/commit.py          |  88 ++++++
 tools/patman/cros_subprocess.py | 397 +++++++++++++++++++++++++++
 tools/patman/get_maintainer.py  |  47 ++++
 tools/patman/gitutil.py         | 582 ++++++++++++++++++++++++++++++++++++++++
 tools/patman/patchstream.py     | 488 +++++++++++++++++++++++++++++++++
 tools/patman/patman             |   1 +
 tools/patman/patman.py          | 167 ++++++++++++
 tools/patman/project.py         |  27 ++
 tools/patman/series.py          | 271 +++++++++++++++++++
 tools/patman/settings.py        | 295 ++++++++++++++++++++
 tools/patman/terminal.py        | 158 +++++++++++
 14 files changed, 2818 insertions(+)
 create mode 100644 tools/patman/.gitignore
 create mode 100644 tools/patman/checkpatch.py
 create mode 100644 tools/patman/command.py
 create mode 100644 tools/patman/commit.py
 create mode 100644 tools/patman/cros_subprocess.py
 create mode 100644 tools/patman/get_maintainer.py
 create mode 100644 tools/patman/gitutil.py
 create mode 100644 tools/patman/patchstream.py
 create mode 120000 tools/patman/patman
 create mode 100755 tools/patman/patman.py
 create mode 100644 tools/patman/project.py
 create mode 100644 tools/patman/series.py
 create mode 100644 tools/patman/settings.py
 create mode 100644 tools/patman/terminal.py
tools/patman/.gitignore new file +1 -0
new file mode 100644
index 0000000..0d20b64
@@ -0,0 +1 @@
+*.pyc
tools/patman/checkpatch.py new file +173 -0

173 lines not on this page · raw message

tools/patman/command.py new file +123 -0

123 lines not on this page · raw message

tools/patman/commit.py new file +88 -0

88 lines not on this page · raw message

tools/patman/cros_subprocess.py new file +397 -0

397 lines not on this page · raw message

tools/patman/get_maintainer.py new file +47 -0

47 lines not on this page · raw message

tools/patman/gitutil.py new file +582 -0

582 lines not on this page · raw message

tools/patman/patchstream.py new file +488 -0

488 lines not on this page · raw message

tools/patman/patman new file +1 -0
new file mode 120000
index 0000000..6cc3d7a
@@ -0,0 +1 @@
+patman.py
\ No newline at end of file
tools/patman/patman.py new file +167 -0

167 lines not on this page · raw message

tools/patman/project.py new file +27 -0
new file mode 100644
index 0000000..e05ff11
@@ -0,0 +1,27 @@
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+import os.path
+
+import gitutil
+
+def DetectProject():
+    """Autodetect the name of the current project.
+
+    This looks for signature files/directories that are unlikely to exist except
+    in the given project.
+
+    Returns:
+        The name of the project, like "linux" or "u-boot".  Returns "unknown"
+        if we can't detect the project.
+    """
+    top_level = gitutil.GetTopLevel()
+
+    if os.path.exists(os.path.join(top_level, "include", "u-boot")):
+        return "u-boot"
+    elif os.path.exists(os.path.join(top_level, "kernel")):
+        return "linux"
+
+    return "unknown"
tools/patman/series.py new file +271 -0

271 lines not on this page · raw message

tools/patman/settings.py new file +295 -0

295 lines not on this page · raw message

tools/patman/terminal.py new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Quoted 6 lines · Simon Glass

This tool is a Python script which:
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

Don't get me wrong but is this really worth 3000+ lines of python? The tasks you describe can be done using a few lines bash.

Signature · 2 lines
Thanks,
//richard
#3 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Hi Richard,

Quoted 10 lines · Richard Weinberger
Quoted 6 lines · Simon Glass

This tool is a Python script which:
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

Don't get me wrong but is this really worth 3000+ lines of python? The tasks you describe can be done using a few lines bash.

#!/bin/bash
patman $@

I obviously failed in my attempt to briefly explain what it does. Please check out the cover letter [1], README [2], or perhaps use it on a series. With respect to the length, it could be slimmed down a bit if that is important.

Regards,
Simon

[1] https://lkml.org/lkml/2015/5/3/105
[2] https://lkml.org/lkml/2015/5/3/95

#4 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Simon,

Am 03.05.2015 um 21:54 schrieb Simon Glass:

Quoted 14 lines

Hi Richard,

Quoted 10 lines · Richard Weinberger
Quoted 6 lines · Simon Glass

This tool is a Python script which:
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

Don't get me wrong but is this really worth 3000+ lines of python? The tasks you describe can be done using a few lines bash.

Quoted 7 lines

#!/bin/bash
patman $@

I obviously failed in my attempt to briefly explain what it does. Please check out the cover letter [1], README [2], or perhaps use it on a series. With respect to the length, it could be slimmed down a bit if that is important.

the README file did the trick. ;)
Sounds like a useful tool to manage patch series.

But I don't think it makes much sense to carry it with the Linux kernel tree. Other projects can also use it and it does not seem to be very Linux kernel specific.
git, quilt and other great tools also have their own repositories.

Thanks,
//richard

#5 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Hi Richard,

Quoted 25 lines · Richard Weinberger

Simon,

Am 03.05.2015 um 21:54 schrieb Simon Glass:

Quoted 14 lines

Hi Richard,

Quoted 10 lines · Richard Weinberger
Quoted 6 lines · Simon Glass

This tool is a Python script which:
- Creates patch directly from your branch
- Cleans them up by removing unwanted tags
- Inserts a cover letter with change lists
- Runs the patches through checkpatch.pl and its own checks
- Optionally emails them out to selected people

Don't get me wrong but is this really worth 3000+ lines of python? The tasks you describe can be done using a few lines bash.

Quoted 7 lines

#!/bin/bash
patman $@

I obviously failed in my attempt to briefly explain what it does. Please check out the cover letter [1], README [2], or perhaps use it on a series. With respect to the length, it could be slimmed down a bit if that is important.

Quoted 7 lines

the README file did the trick. ;)
Sounds like a useful tool to manage patch series.

But I don't think it makes much sense to carry it with the Linux kernel tree. Other projects can also use it and it does not seem to be very Linux kernel specific.
git, quilt and other great tools also have their own repositories.

My reasoning is that:

- more will find it / use it if it is in-tree
- it avoids installation and old-version problems (e.g. I suppose this is why the device tree compiler is built-in)
- it is somewhat Linux-specific (e.g. uses get_maintainers, checkpatch.pl) and can break if checkpatch.pl if the wrong version (e.g. you check out and send patches from an older tree)
- it could be built into the Linux workflow [1] and might thereby reduce the amount of confusion and errors (did you run checkpatch?, your change log is in the wrong place, you forgot to add your sign-off, etc.)

That said, I could see this having a repo of its own, with the Linux version a downstream copy, a bit like dtc (and maybe Kbuild/Kconfig - I don't know). The feature set is probably mature enough to support that now.

Regards,
Simon

[1] https://www.kernel.org/doc/Documentation/SubmittingPatches section 14

#6 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Am 03.05.2015 um 22:40 schrieb Simon Glass:

Quoted 7 lines
Quoted 4 lines

But I don't think it makes much sense to carry it with the Linux kernel tree. Other projects can also use it and it does not seem to be very Linux kernel specific.
git, quilt and other great tools also have their own repositories.

My reasoning is that:

Quoted 10 lines

- more will find it / use it if it is in-tree
- it avoids installation and old-version problems (e.g. I suppose this is why the device tree compiler is built-in)
- it is somewhat Linux-specific (e.g. uses get_maintainers, checkpatch.pl) and can break if checkpatch.pl if the wrong version (e.g. you check out and send patches from an older tree)
- it could be built into the Linux workflow [1] and might thereby reduce the amount of confusion and errors (did you run checkpatch?, your change log is in the wrong place, you forgot to add your sign-off, etc.)

If we'd follow these arguments we'd have to move the whole GNU into the kernel tree. ;-)
checkpatch.pl and get_maintainers.pl are not really a show-stopper. Other projects are using them too. You can make them also configurable. i.e. check_script and get_maintaner_script.

Thanks,
//richard

#7 lore raw

Re: [PATCH 1/3] Add patman patch automation script

Hi Richard,

Quoted 19 lines · Richard Weinberger

Am 03.05.2015 um 22:40 schrieb Simon Glass:

Quoted 7 lines
Quoted 4 lines

But I don't think it makes much sense to carry it with the Linux kernel tree. Other projects can also use it and it does not seem to be very Linux kernel specific.
git, quilt and other great tools also have their own repositories.

My reasoning is that:

Quoted 10 lines

- more will find it / use it if it is in-tree
- it avoids installation and old-version problems (e.g. I suppose this is why the device tree compiler is built-in)
- it is somewhat Linux-specific (e.g. uses get_maintainers, checkpatch.pl) and can break if checkpatch.pl if the wrong version (e.g. you check out and send patches from an older tree)
- it could be built into the Linux workflow [1] and might thereby reduce the amount of confusion and errors (did you run checkpatch?, your change log is in the wrong place, you forgot to add your sign-off, etc.)

Quoted 2 lines

If we'd follow these arguments we'd have to move the whole GNU into the kernel tree. ;-)

Well maybe the first two.

Quoted 3 lines

checkpatch.pl and get_maintainers.pl are not really a show-stopper. Other projects are using them too. You can make them also configurable. i.e. check_script and get_maintaner_script.

Understood, I'm just explaining my reasoning for sending this patch. With U-Boot it has been very convenient to be able to rely on this being available in the tree. 3000 lines is a drop in the ocean with Linux's 22m lines.

But I fully understand your point of view. If nothing else, at least this series provides an easy way for people to try it out.

Regards,
Simon

#8 lore raw

PATCH 2/3 Add tests for patman

In reply to Simon Glass

Add some simple tests which can be run with the '--test' option.

---

 tools/patman/test.py | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 243 insertions(+)
 create mode 100644 tools/patman/test.py
tools/patman/test.py new file +243 -0
new file mode 100644
index 0000000..e8f7472
@@ -0,0 +1,243 @@
+#
+# Copyright (c) 2011 The Chromium OS Authors.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+import os
+import tempfile
+import unittest
+
+import checkpatch
+import gitutil
+import patchstream
+import series
+
+
+class TestPatch(unittest.TestCase):
+    """Test this program
+
+    TODO: Write tests for the rest of the functionality
+    """
+
+    def testBasic(self):
+        """Test basic filter operation"""
+        data='''
+
+From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
+From: Simon Glass <[email protected]>
+Date: Thu, 28 Apr 2011 09:58:51 -0700
+Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
+
+This adds functions to enable/disable clocks and reset to on-chip peripherals.
+
+BUG=chromium-os:13875
+TEST=build U-Boot for Seaboard, boot
+
+Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
+
+Review URL: http://codereview.chromium.org/6900006
+
+Signed-off-by: Simon Glass <[email protected]>
+---
+ arch/arm/cpu/armv7/tegra2/Makefile         |    2 +-
+ arch/arm/cpu/armv7/tegra2/ap20.c           |   57 ++----
+ arch/arm/cpu/armv7/tegra2/clock.c          |  163 +++++++++++++++++
+'''
+        expected='''
+
+From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
+From: Simon Glass <[email protected]>
+Date: Thu, 28 Apr 2011 09:58:51 -0700
+Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
+
+This adds functions to enable/disable clocks and reset to on-chip peripherals.
+
+Signed-off-by: Simon Glass <[email protected]>
+---
+
+ arch/arm/cpu/armv7/tegra2/Makefile         |    2 +-
+ arch/arm/cpu/armv7/tegra2/ap20.c           |   57 ++----
+ arch/arm/cpu/armv7/tegra2/clock.c          |  163 +++++++++++++++++
+'''
+        out = ''
+        inhandle, inname = tempfile.mkstemp()
+        infd = os.fdopen(inhandle, 'w')
+        infd.write(data)
+        infd.close()
+
+        exphandle, expname = tempfile.mkstemp()
+        expfd = os.fdopen(exphandle, 'w')
+        expfd.write(expected)
+        expfd.close()
+
+        patchstream.FixPatch(None, inname, series.Series(), None)
+        rc = os.system('diff -u %s %s' % (inname, expname))
+        self.assertEqual(rc, 0)
+
+        os.remove(inname)
+        os.remove(expname)
+
+    def GetData(self, data_type):
+        data='''
+From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
+From: Simon Glass <[email protected]>
+Date: Thu, 7 Apr 2011 10:14:41 -0700
+Subject: [PATCH 1/4] Add microsecond boot time measurement
+
+This defines the basics of a new boot time measurement feature. This allows
+logging of very accurate time measurements as the boot proceeds, by using
+an available microsecond counter.
+
+%s
+---
+ README              |   11 ++++++++
+ common/bootstage.c  |   50 ++++++++++++++++++++++++++++++++++++
+ include/bootstage.h |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ include/common.h    |    8 ++++++
+ 5 files changed, 141 insertions(+), 0 deletions(-)
+ create mode 100644 common/bootstage.c
+ create mode 100644 include/bootstage.h
+
+diff --git a/README b/README
+index 6f3748d..f9e4e65 100644
+--- a/README
++++ b/README
+@@ -2026,6 +2026,17 @@ The following options need to be configured:
+ 		example, some LED's) on your board. At the moment,
+ 		the following checkpoints are implemented:
+
++- Time boot progress
++		CONFIG_BOOTSTAGE
++
++		Define this option to enable microsecond boot stage timing
++		on supported platforms. For this to work your platform
++		needs to define a function timer_get_us() which returns the
++		number of microseconds since reset. This would normally
++		be done in your SOC or board timer.c file.
++
++		You can add calls to bootstage_mark() to set time markers.
++
+ - Standalone program support:
+ 		CONFIG_STANDALONE_LOAD_ADDR
+
+diff --git a/common/bootstage.c b/common/bootstage.c
+new file mode 100644
+index 0000000..2234c87
+--- /dev/null
++++ b/common/bootstage.c
+@@ -0,0 +1,39 @@
++/*
++ * Copyright (c) 2011, Google Inc. All rights reserved.
++ *
++ * SPDX-License-Identifier:	GPL-2.0+
++ */
++
++
++/*
++ * This module records the progress of boot and arbitrary commands, and
++ * permits accurate timestamping of each. The records can optionally be
++ * passed to kernel in the ATAGs
++ */
++
++#include <common.h>
++
++
++struct bootstage_record {
++	uint32_t time_us;
++	const char *name;
++};
++
++static struct bootstage_record record[BOOTSTAGE_COUNT];
++
++uint32_t bootstage_mark(enum bootstage_id id, const char *name)
++{
++	struct bootstage_record *rec = &record[id];
++
++	/* Only record the first event for each */
++%sif (!rec->name) {
++		rec->time_us = (uint32_t)timer_get_us();
++		rec->name = name;
++	}
++	if (!rec->name &&
++	%ssomething_else) {
++		rec->time_us = (uint32_t)timer_get_us();
++		rec->name = name;
++	}
++%sreturn rec->time_us;
++}
+--
+1.7.3.1
+'''
+        signoff = 'Signed-off-by: Simon Glass <[email protected]>\n'
+        tab = '	'
+        indent = '    '
+        if data_type == 'good':
+            pass
+        elif data_type == 'no-signoff':
+            signoff = ''
+        elif data_type == 'spaces':
+            tab = '   '
+        elif data_type == 'indent':
+            indent = tab
+        else:
+            print 'not implemented'
+        return data % (signoff, tab, indent, tab)
+
+    def SetupData(self, data_type):
+        inhandle, inname = tempfile.mkstemp()
+        infd = os.fdopen(inhandle, 'w')
+        data = self.GetData(data_type)
+        infd.write(data)
+        infd.close()
+        return inname
+
+    def testGood(self):
+        """Test checkpatch operation"""
+        inf = self.SetupData('good')
+        result = checkpatch.CheckPatch(inf)
+        self.assertEqual(result.ok, True)
+        self.assertEqual(result.problems, [])
+        self.assertEqual(result.errors, 0)
+        self.assertEqual(result.warnings, 0)
+        self.assertEqual(result.checks, 0)
+        self.assertEqual(result.lines, 56)
+        os.remove(inf)
+
+    def testNoSignoff(self):
+        inf = self.SetupData('no-signoff')
+        result = checkpatch.CheckPatch(inf)
+        self.assertEqual(result.ok, False)
+        self.assertEqual(len(result.problems), 1)
+        self.assertEqual(result.errors, 1)
+        self.assertEqual(result.warnings, 0)
+        self.assertEqual(result.checks, 0)
+        self.assertEqual(result.lines, 56)
+        os.remove(inf)
+
+    def testSpaces(self):
+        inf = self.SetupData('spaces')
+        result = checkpatch.CheckPatch(inf)
+        self.assertEqual(result.ok, False)
+        self.assertEqual(len(result.problems), 2)
+        self.assertEqual(result.errors, 0)
+        self.assertEqual(result.warnings, 2)
+        self.assertEqual(result.checks, 0)
+        self.assertEqual(result.lines, 56)
+        os.remove(inf)
+
+    def testIndent(self):
+        inf = self.SetupData('indent')
+        result = checkpatch.CheckPatch(inf)
+        self.assertEqual(result.ok, False)
+        self.assertEqual(len(result.problems), 1)
+        self.assertEqual(result.errors, 0)
+        self.assertEqual(result.warnings, 0)
+        self.assertEqual(result.checks, 1)
+        self.assertEqual(result.lines, 56)
+        os.remove(inf)
+
+
+if __name__ == "__main__":
+    unittest.main()
+    gitutil.RunTests()
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#9 lore raw

PATCH 3/3 Add documentation for patman

In reply to Simon Glass

Add an entry to the MAINTAINERS file, plus a README which explains how to use patman.

---

 MAINTAINERS         |   5 +
 tools/patman/README | 475 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 480 insertions(+)
 create mode 100644 tools/patman/README
MAINTAINERS +5 -0
index 1622775..cd415d0 100644
@@ -7404,6 +7404,11 @@ F:	drivers/video/fbdev/sti*
 F:	drivers/video/console/sti*
 F:	drivers/video/logo/logo_parisc*
 
+PATMAN PATCH AUTOMATION TOOL
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	tools/patman/
+
 PC87360 HARDWARE MONITORING DRIVER
 M:	Jim Cromie <[email protected]>
 L:	[email protected]
tools/patman/README new file +475 -0

475 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c