diff mbox series

[Unstable/Lunar,2/5] UBUNTU: [Packaging] annotations: Clean up policy writes

Message ID 20230207073607.913994-3-juerg.haefliger@canonical.com
State New
Headers show
Series annotations: Cleanups and splitting | expand

Commit Message

Juerg Haefliger Feb. 7, 2023, 7:36 a.m. UTC
The logic to determine if policy lines need to be written to the output
file is a little convoluted. Basically, if there is no 'policy' key in
a config, there is nothing to do, so put that check at the beginning of
the loop.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
 debian/scripts/misc/kconfig/annotations.py | 34 ++++++++++++----------
 1 file changed, 19 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py
index 2af5f7c5b17b..ee679903d9da 100644
--- a/debian/scripts/misc/kconfig/annotations.py
+++ b/debian/scripts/misc/kconfig/annotations.py
@@ -276,25 +276,29 @@  class Annotation(Config):
 
             # Only save local differences (preserve includes)
             for conf in sorted(self.config):
-                old_val = tmp_a.config[conf] if conf in tmp_a.config else None
                 new_val = self.config[conf]
+                if 'policy' not in new_val:
+                    continue
+
                 # If new_val is a subset of old_val, skip it
-                if old_val and 'policy' in old_val and 'policy' in new_val:
+                old_val = tmp_a.config.get(conf)
+                if old_val and 'policy' in old_val:
                     if old_val['policy'] == old_val['policy'] | new_val['policy']:
                         continue
-                if 'policy' in new_val:
-                    val = dict(sorted(new_val['policy'].items()))
-                    line = f"{conf : <47} policy<{val}>"
-                    if 'note' in new_val:
-                        val = new_val['note']
-                        if new_val.get('oneline', False):
-                            # Single line
-                            line += f' note<{val}>'
-                        else:
-                            # Separate policy and note lines,
-                            # followed by an empty line
-                            line += f'\n{conf : <47} note<{val}>\n'
-                    tmp.write(line + "\n")
+
+                # Write out the policy (and note) line(s)
+                val = dict(sorted(new_val['policy'].items()))
+                line = f"{conf : <47} policy<{val}>"
+                if 'note' in new_val:
+                    val = new_val['note']
+                    if new_val.get('oneline', False):
+                        # Single line
+                        line += f' note<{val}>'
+                    else:
+                        # Separate policy and note lines,
+                        # followed by an empty line
+                        line += f'\n{conf : <47} note<{val}>\n'
+                tmp.write(line + "\n")
 
             # Replace annotations with the updated version
             tmp.flush()