From 5abab20dfb20406137e8b7d659aee3cf43dff351 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Dec 2014 17:33:57 -0700 Subject: buildman: Allow specifying a range of commits to build Adjust the -b flag to permit a range expression as well as a branch. Signed-off-by: Simon Glass Suggested-by: Daniel Schwierzeck Tested-by: Daniel Schwierzeck --- tools/patman/gitutil.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'tools/patman') diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 34c6b04..cc5a55a 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -154,6 +154,24 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False): rstr = '%s%s..%s' % (upstream, '~' if include_upstream else '', branch) return rstr, msg +def CountCommitsInRange(git_dir, range_expr): + """Returns the number of commits in the given range. + + Args: + git_dir: Directory containing git repo + range_expr: Range to check + Return: + Number of patches that exist in the supplied rangem or None if none + were found + """ + pipe = [LogCmd(range_expr, git_dir=git_dir, oneline=True)] + result = command.RunPipe(pipe, capture=True, capture_stderr=True, + raise_on_error=False) + if result.return_code: + return None, "Range '%s' not found or is invalid" % range_expr + patch_count = len(result.stdout.splitlines()) + return patch_count, None + def CountCommitsInBranch(git_dir, branch, include_upstream=False): """Returns the number of commits in the given branch. @@ -167,11 +185,7 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False): range_expr, msg = GetRangeInBranch(git_dir, branch, include_upstream) if not range_expr: return None, msg - pipe = [LogCmd(range_expr, git_dir=git_dir, oneline=True), - ['wc', '-l']] - result = command.RunPipe(pipe, capture=True, oneline=True) - patch_count = int(result.stdout) - return patch_count, msg + return CountCommitsInRange(git_dir, range_expr) def CountCommits(commit_range): """Returns the number of commits in the given range. -- cgit v1.1