patman: Refactor MakeCcFile() into two functions
This function is quite long. Moving the handling of a commit into a separate function. This will make it easier to do the work in parallel. Update function comments while we are here. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org>
This commit is contained in:
@@ -234,6 +234,49 @@ class Series(dict):
|
|||||||
str = 'Change log exists, but no version is set'
|
str = 'Change log exists, but no version is set'
|
||||||
print(col.build(col.RED, str))
|
print(col.build(col.RED, str))
|
||||||
|
|
||||||
|
def GetCcForCommit(self, commit, process_tags, warn_on_error,
|
||||||
|
add_maintainers, limit, get_maintainer_script,
|
||||||
|
all_skips):
|
||||||
|
"""Get the email CCs to use with a particular commit
|
||||||
|
|
||||||
|
Uses subject tags and get_maintainers.pl script to find people to cc
|
||||||
|
on a patch
|
||||||
|
|
||||||
|
Args:
|
||||||
|
commit (Commit): Commit to process
|
||||||
|
process_tags (bool): Process tags as if they were aliases
|
||||||
|
warn_on_error (bool): True to print a warning when an alias fails to
|
||||||
|
match, False to ignore it.
|
||||||
|
add_maintainers (bool or list of str): Either:
|
||||||
|
True/False to call the get_maintainers to CC maintainers
|
||||||
|
List of maintainers to include (for testing)
|
||||||
|
limit (int): Limit the length of the Cc list (None if no limit)
|
||||||
|
get_maintainer_script (str): The file name of the get_maintainer.pl
|
||||||
|
script (or compatible).
|
||||||
|
all_skips (set of str): Updated to include the set of bouncing email
|
||||||
|
addresses that were dropped from the output. This is essentially
|
||||||
|
a return value from this function.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list of str: List of email addresses to cc
|
||||||
|
"""
|
||||||
|
cc = []
|
||||||
|
if process_tags:
|
||||||
|
cc += gitutil.build_email_list(commit.tags,
|
||||||
|
warn_on_error=warn_on_error)
|
||||||
|
cc += gitutil.build_email_list(commit.cc_list,
|
||||||
|
warn_on_error=warn_on_error)
|
||||||
|
if type(add_maintainers) == type(cc):
|
||||||
|
cc += add_maintainers
|
||||||
|
elif add_maintainers:
|
||||||
|
cc += get_maintainer.get_maintainer(get_maintainer_script,
|
||||||
|
commit.patch)
|
||||||
|
all_skips |= set(cc) & set(settings.bounces)
|
||||||
|
cc = list(set(cc) - set(settings.bounces))
|
||||||
|
if limit is not None:
|
||||||
|
cc = cc[:limit]
|
||||||
|
return cc
|
||||||
|
|
||||||
def MakeCcFile(self, process_tags, cover_fname, warn_on_error,
|
def MakeCcFile(self, process_tags, cover_fname, warn_on_error,
|
||||||
add_maintainers, limit, get_maintainer_script):
|
add_maintainers, limit, get_maintainer_script):
|
||||||
"""Make a cc file for us to use for per-commit Cc automation
|
"""Make a cc file for us to use for per-commit Cc automation
|
||||||
@@ -241,15 +284,15 @@ class Series(dict):
|
|||||||
Also stores in self._generated_cc to make ShowActions() faster.
|
Also stores in self._generated_cc to make ShowActions() faster.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
process_tags: Process tags as if they were aliases
|
process_tags (bool): Process tags as if they were aliases
|
||||||
cover_fname: If non-None the name of the cover letter.
|
cover_fname (str): If non-None the name of the cover letter.
|
||||||
warn_on_error: True to print a warning when an alias fails to match,
|
warn_on_error (bool): True to print a warning when an alias fails to
|
||||||
False to ignore it.
|
match, False to ignore it.
|
||||||
add_maintainers: Either:
|
add_maintainers (bool or list of str): Either:
|
||||||
True/False to call the get_maintainers to CC maintainers
|
True/False to call the get_maintainers to CC maintainers
|
||||||
List of maintainers to include (for testing)
|
List of maintainers to include (for testing)
|
||||||
limit: Limit the length of the Cc list (None if no limit)
|
limit (int): Limit the length of the Cc list (None if no limit)
|
||||||
get_maintainer_script: The file name of the get_maintainer.pl
|
get_maintainer_script (str): The file name of the get_maintainer.pl
|
||||||
script (or compatible).
|
script (or compatible).
|
||||||
Return:
|
Return:
|
||||||
Filename of temp file created
|
Filename of temp file created
|
||||||
@@ -259,28 +302,18 @@ class Series(dict):
|
|||||||
fname = '/tmp/patman.%d' % os.getpid()
|
fname = '/tmp/patman.%d' % os.getpid()
|
||||||
fd = open(fname, 'w', encoding='utf-8')
|
fd = open(fname, 'w', encoding='utf-8')
|
||||||
all_ccs = []
|
all_ccs = []
|
||||||
|
all_skips = set()
|
||||||
for commit in self.commits:
|
for commit in self.commits:
|
||||||
cc = []
|
cc = self.GetCcForCommit(commit, process_tags, warn_on_error,
|
||||||
if process_tags:
|
add_maintainers, limit,
|
||||||
cc += gitutil.build_email_list(commit.tags,
|
get_maintainer_script, all_skips)
|
||||||
warn_on_error=warn_on_error)
|
|
||||||
cc += gitutil.build_email_list(commit.cc_list,
|
|
||||||
warn_on_error=warn_on_error)
|
|
||||||
if type(add_maintainers) == type(cc):
|
|
||||||
cc += add_maintainers
|
|
||||||
elif add_maintainers:
|
|
||||||
|
|
||||||
cc += get_maintainer.get_maintainer(get_maintainer_script,
|
|
||||||
commit.patch)
|
|
||||||
for x in set(cc) & set(settings.bounces):
|
|
||||||
print(col.build(col.YELLOW, 'Skipping "%s"' % x))
|
|
||||||
cc = list(set(cc) - set(settings.bounces))
|
|
||||||
if limit is not None:
|
|
||||||
cc = cc[:limit]
|
|
||||||
all_ccs += cc
|
all_ccs += cc
|
||||||
print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
|
print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
|
||||||
self._generated_cc[commit.patch] = cc
|
self._generated_cc[commit.patch] = cc
|
||||||
|
|
||||||
|
for x in sorted(all_skips):
|
||||||
|
print(col.build(col.YELLOW, f'Skipping "{x}"'))
|
||||||
|
|
||||||
if cover_fname:
|
if cover_fname:
|
||||||
cover_cc = gitutil.build_email_list(self.get('cover_cc', ''))
|
cover_cc = gitutil.build_email_list(self.get('cover_cc', ''))
|
||||||
cover_cc = list(set(cover_cc + all_ccs))
|
cover_cc = list(set(cover_cc + all_ccs))
|
||||||
|
Reference in New Issue
Block a user