summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-07-20 02:48:48 +0300
committerSimon Glass <sjg@chromium.org>2023-07-24 18:34:11 +0300
commitaeb2381b2743b545e39f580a5a620e6f8e2e1edb (patch)
tree0244b578ae5b8648cf087e7d20aa13091511cc8f /tools
parent168d792ffa58bc1a8df1b980c0eacea7b840f62a (diff)
downloadu-boot-aeb2381b2743b545e39f580a5a620e6f8e2e1edb.tar.xz
buildman: Move counting of commits into a function
Move this code into a separate function to avoid a pylint warning in determine_series(). Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/buildman/control.py63
1 files changed, 41 insertions, 22 deletions
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 85c0c7b3a4..3e6933cc05 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,