diff mbox series

[cip-kernel-sec] report_affected: report cip branches

Message ID 20190620061309.1252-1-daniel.sangorrin@toshiba.co.jp (mailing list archive)
State Accepted
Headers show
Series [cip-kernel-sec] report_affected: report cip branches | expand

Commit Message

Daniel Sangorrin June 20, 2019, 6:13 a.m. UTC
Allow reporting on cip branches, instead of returning an
error like this one:

$ ./scripts/report_affected.py linux-4.4.y-cip
Traceback (most recent call last):
  File "./scripts/report_affected.py", line 105, in <module>
    args.only_fixed_upstream, args.include_ignored, *args.branches)
  File "./scripts/report_affected.py", line 33, in main
    branches.sort(key=kernel_sec.branch.get_sort_key)
  File "./scripts/kernel_sec/branch.py", line 146, in get_sort_key
    base_ver = branch['base_ver']
TypeError: 'NoneType' object is not subscriptable

Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
---
 scripts/kernel_sec/branch.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Ben Hutchings June 20, 2019, 7:51 p.m. UTC | #1
On Thu, 2019-06-20 at 15:13 +0900, Daniel Sangorrin wrote:
> Allow reporting on cip branches, instead of returning an
> error like this one:
[...]
>  def get_stable_branch(branch_name):
> -    match = _STABLE_BRANCH_RE.match(branch_name)
> -    return match and get_base_ver_stable_branch(match.group(1))
> +    if 'cip' in branch_name:
> +        match = _CIP_BRANCH_RE.match(branch_name)
> +        return match and get_base_ver_cip_branch(match.group(1))
> +    else:
> +        match = _STABLE_BRANCH_RE.match(branch_name)
> +        return match and get_base_ver_stable_branch(match.group(1))
[...]

Does this function actually need to know anything about specific branch
names?  It seems like we should be able to implement it as something
like:

    for branch in get_live_branches():
        if branch['short_name'] == branch_name:
            return branch
    return None

Ben.
Ben Hutchings June 20, 2019, 8:03 p.m. UTC | #2
On Thu, 2019-06-20 at 20:51 +0100, Ben Hutchings wrote:
> On Thu, 2019-06-20 at 15:13 +0900, Daniel Sangorrin wrote:
> > Allow reporting on cip branches, instead of returning an
> > error like this one:
> 
> [...]
> >  def get_stable_branch(branch_name):
> > -    match = _STABLE_BRANCH_RE.match(branch_name)
> > -    return match and get_base_ver_stable_branch(match.group(1))
> > +    if 'cip' in branch_name:
> > +        match = _CIP_BRANCH_RE.match(branch_name)
> > +        return match and get_base_ver_cip_branch(match.group(1))
> > +    else:
> > +        match = _STABLE_BRANCH_RE.match(branch_name)
> > +        return match and get_base_ver_stable_branch(match.group(1))
> 
> [...]
> 
> Does this function actually need to know anything about specific branch
> names?  It seems like we should be able to implement it as something
> like:
> 
>     for branch in get_live_branches():
>         if branch['short_name'] == branch_name:
>             return branch
>     return None

In fact it would probably make more sense to get rid of this function
altogether and put that code in reported_affected.py, which can avoid
calling get_live_branches() multiple times.

Ben.
diff mbox series

Patch

diff --git a/scripts/kernel_sec/branch.py b/scripts/kernel_sec/branch.py
index fb8785c..828de13 100644
--- a/scripts/kernel_sec/branch.py
+++ b/scripts/kernel_sec/branch.py
@@ -22,6 +22,7 @@  from . import version
 
 
 _STABLE_BRANCH_RE = re.compile(r'^linux-([\d.]+)\.y$')
+_CIP_BRANCH_RE = re.compile(r'^linux-([\d.]+)\.y-cip$')
 
 
 def get_base_ver_stable_branch(base_ver):
@@ -34,9 +35,23 @@  def get_base_ver_stable_branch(base_ver):
         }
 
 
+def get_base_ver_cip_branch(base_ver):
+    branch_name = 'linux-%s.y-cip' % base_ver
+    return {
+        'short_name': branch_name,
+        'git_remote': 'cip',
+        'git_name': branch_name,
+        'base_ver': base_ver
+        }
+
+
 def get_stable_branch(branch_name):
-    match = _STABLE_BRANCH_RE.match(branch_name)
-    return match and get_base_ver_stable_branch(match.group(1))
+    if 'cip' in branch_name:
+        match = _CIP_BRANCH_RE.match(branch_name)
+        return match and get_base_ver_cip_branch(match.group(1))
+    else:
+        match = _STABLE_BRANCH_RE.match(branch_name)
+        return match and get_base_ver_stable_branch(match.group(1))
 
 
 def _extract_live_stable_branches(doc):