Allow to skip patches that are already backported

This is controlled by the new -B option. The option will skip all
patches that have counterparts with the same Change-Id in all stable/*
branches present in the origin remote.

Change-Id: Iaf5d911d57bac5208a5fd53d28eaafd0c238010b
This commit is contained in:
Ihar Hrachyshka 2017-01-31 13:52:34 -08:00
parent 748d6b0d80
commit dfa2b9185c
2 changed files with 41 additions and 0 deletions

View File

@ -948,6 +948,13 @@ Example::
./bugs-fixed-since.py -r ../neutron --start=8.0.0
Use ``-B`` option to ignore patches that were already backported into all
stable branches.
Example::
./bugs-fixed-since.py -B -r ../neutron --start=8.0.0
lp-filter-bugs-by-importance.py
-------------------------------

View File

@ -23,6 +23,7 @@ from git import Repo
BUG_PATTERN = r'Bug:\s+#?(?P<bugnum>\d+)'
CHANGEID_PATTERN = r'Change-Id:\s+(?P<id>[0-9a-zA-Z]+)'
def _parse_args():
@ -36,9 +37,31 @@ def _parse_args():
parser.add_argument(
'--start', '-s', required=True,
help='git hash to start search from')
parser.add_argument(
'--skip-backported', '-B',
action='store_true',
help='whether to skip patches backported to all stable branches',
)
return parser.parse_args()
def _backported_to_all_stable_branches(repo, id_):
for ref in repo.refs:
if ref.name.startswith('origin/stable/'):
for commit in repo.iter_commits('..%s' % ref.name):
if id_ == _extract_changeid(commit):
break
else:
return False
return True
def _extract_changeid(commit):
for match in re.finditer(CHANGEID_PATTERN, commit.message):
id_ = match.group('id')
return id_
def main():
args = _parse_args()
@ -54,6 +77,17 @@ def main():
bugs = set()
for commit in repo.iter_commits(rev):
id_ = _extract_changeid(commit)
if id_ is None:
# probably a merge commit, skip
continue
# skip patches backported into all branches
if (args.skip_backported and
_backported_to_all_stable_branches(repo, id_)):
continue
# collect every bug number mentioned in the message
for match in re.finditer(BUG_PATTERN, commit.message):
bugs.add(match.group('bugnum'))