]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
patman: Allow skipping patches at the end
authorSimon Glass <sjg@chromium.org>
Mon, 6 Jul 2020 03:41:52 +0000 (21:41 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 20 Jul 2020 17:37:46 +0000 (11:37 -0600)
The -s option allows skipping patches at the top of the branch. Sometimes
there are commits at the bottom that need to be skipped. At present it is
necessary to count the number of commits and then use -c to tell patman
how many to process.

Add a -e option to easily skip a number of commits at the bottom of the
branch.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/patman/control.py
tools/patman/func_test.py
tools/patman/main.py

index b48eac41fd7dae5e56222403fbed6cf615ba5d2f..b481ff6b2709ea0e08e4c897f42bc141d593afde 100644 (file)
@@ -20,7 +20,7 @@ def setup():
     """Do required setup before doing anything"""
     gitutil.Setup()
 
-def prepare_patches(col, branch, count, start, ignore_binary):
+def prepare_patches(col, branch, count, start, end, ignore_binary):
     """Figure out what patches to generate, then generate them
 
     The patch files are written to the current directory, e.g. 0001_xxx.patch
@@ -32,6 +32,8 @@ def prepare_patches(col, branch, count, start, ignore_binary):
         count (int): Number of patches to produce, or -1 to produce patches for
             the current branch back to the upstream commit
         start (int): Start partch to use (0=first / top of branch)
+        end (int): End patch to use (0=last one in series, 1=one before that,
+            etc.)
         ignore_binary (bool): Don't generate patches for binary files
 
     Returns:
@@ -50,7 +52,7 @@ def prepare_patches(col, branch, count, start, ignore_binary):
                            'No commits found to process - please use -c flag'))
 
     # Read the metadata from the commits
-    to_do = count
+    to_do = count - end
     series = patchstream.GetMetaData(branch, start, to_do)
     cover_fname, patch_files = gitutil.CreatePatches(
         branch, start, to_do, ignore_binary, series)
@@ -159,7 +161,7 @@ def send(options):
     setup()
     col = terminal.Color()
     series, cover_fname, patch_files = prepare_patches(
-        col, options.branch, options.count, options.start,
+        col, options.branch, options.count, options.start, options.end,
         options.ignore_binary)
     ok = check_patches(series, patch_files, options.check_patch,
                        options.verbose)
index 588be73ef48ce7a7a75385e32aa1ae3bf36b8dce..810af9c6042ab09954d3861ab52f6bc5ae5ff7c4 100644 (file)
@@ -430,7 +430,8 @@ complicated as possible''')
             col = terminal.Color()
             with capture_sys_output() as _:
                 _, cover_fname, patch_files = control.prepare_patches(
-                    col, branch=None, count=-1, start=0, ignore_binary=False)
+                    col, branch=None, count=-1, start=0, end=0,
+                    ignore_binary=False)
             self.assertIsNone(cover_fname)
             self.assertEqual(2, len(patch_files))
 
@@ -438,9 +439,17 @@ complicated as possible''')
             self.assertEqual(3, gitutil.CountCommitsToBranch('second'))
             with capture_sys_output() as _:
                 _, cover_fname, patch_files = control.prepare_patches(
-                    col, branch='second', count=-1, start=0,
+                    col, branch='second', count=-1, start=0, end=0,
                     ignore_binary=False)
             self.assertIsNotNone(cover_fname)
             self.assertEqual(3, len(patch_files))
+
+            # Check that it can skip patches at the end
+            with capture_sys_output() as _:
+                _, cover_fname, patch_files = control.prepare_patches(
+                    col, branch='second', count=-1, start=0, end=1,
+                    ignore_binary=False)
+            self.assertIsNotNone(cover_fname)
+            self.assertEqual(2, len(patch_files))
         finally:
             os.chdir(orig_dir)
index 066754196e55baa72b9466cb2f17b99745177041..4d7a3044eae8b8d94631aa82f66ea33fa7e7b296 100755 (executable)
@@ -35,6 +35,8 @@ parser.add_option('-b', '--branch', type='str',
                   help="Branch to process (by default, the current branch)")
 parser.add_option('-c', '--count', dest='count', type='int',
        default=-1, help='Automatically create patches from top n commits')
+parser.add_option('-e', '--end', type='int', default=0,
+                  help='Commits to skip at end of patch list')
 parser.add_option('-i', '--ignore-errors', action='store_true',
        dest='ignore_errors', default=False,
        help='Send patches email even if patch errors are found')