[PATCH v3 38/81] buildman: Move counting of commits into a function

Simon Glass sjg at chromium.org
Sun Jul 16 02:36:06 CEST 2023


Move this code into a separate function to avoid a pylint warning in
determine_series().

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 tools/buildman/control.py | 63 +++++++++++++++++++++++++--------------
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 85c0c7b3a40d..3e6933cc05e7 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -159,6 +159,46 @@ def get_allow_missing(opt_allow, opt_no_allow, num_selected, has_branch):
     return allow_missing
 
 
+def count_commits(branch, count, col, git_dir):
+    """Could the number of commits in the branch/ranch being built
+
+    Args:
+        branch (str): Name of branch to build, or None if none
+        count (int): Number of commits to build, or -1 for all
+        col (Terminal.Color): Color object to use
+        git_dir (str): Git directory to use, e.g. './.git'
+
+    Returns:
+        tuple:
+            Number of commits being built
+            True if the 'branch' string contains a range rather than a simple
+                name
+    """
+    has_range = branch and '..' in branch
+    if count == -1:
+        if not branch:
+            count = 1
+        else:
+            if has_range:
+                count, msg = gitutil.count_commits_in_range(git_dir, branch)
+            else:
+                count, msg = gitutil.count_commits_in_branch(git_dir, branch)
+            if count is None:
+                sys.exit(col.build(col.RED, msg))
+            elif count == 0:
+                sys.exit(col.build(col.RED,
+                                   f"Range '{branch}' has no commits"))
+            if msg:
+                print(col.build(col.YELLOW, msg))
+            count += 1   # Build upstream commit also
+
+    if not count:
+        msg = (f"No commits found to process in branch '{branch}': "
+               "set branch's upstream or use -c flag")
+        sys.exit(col.build(col.RED, msg))
+    return count, has_range
+
+
 def determine_series(selected, col, git_dir, count, branch, work_in_output):
     """Determine the series which is to be built, if any
 
@@ -189,28 +229,7 @@ def determine_series(selected, col, git_dir, count, branch, work_in_output):
     # Work out how many commits to build. We want to build everything on the
     # branch. We also build the upstream commit as a control so we can see
     # problems introduced by the first commit on the branch.
-    has_range = branch and '..' in branch
-    if count == -1:
-        if not branch:
-            count = 1
-        else:
-            if has_range:
-                count, msg = gitutil.count_commits_in_range(git_dir, branch)
-            else:
-                count, msg = gitutil.count_commits_in_branch(git_dir, branch)
-            if count is None:
-                sys.exit(col.build(col.RED, msg))
-            elif count == 0:
-                sys.exit(col.build(col.RED,
-                                   f"Range '{branch}' has no commits"))
-            if msg:
-                print(col.build(col.YELLOW, msg))
-            count += 1   # Build upstream commit also
-
-    if not count:
-        msg = (f"No commits found to process in branch '{branch}': "
-               "set branch's upstream or use -c flag")
-        sys.exit(col.build(col.RED, msg))
+    count, has_range = count_commits(branch, count, col, git_dir)
     if work_in_output:
         if len(selected) != 1:
             sys.exit(col.build(col.RED,
-- 
2.41.0.455.g037347b96a-goog



More information about the U-Boot mailing list